From e2891667dda38857ce0b269c0fb097408cca2eea Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Tue, 16 Mar 2021 17:59:50 +0100 Subject: [PATCH 001/188] Bump version to 3.8.0-SNAPSHOT --- apache-maven/pom.xml | 2 +- maven-artifact/pom.xml | 2 +- maven-builder-support/pom.xml | 2 +- maven-compat/pom.xml | 2 +- maven-core/pom.xml | 2 +- maven-embedder/pom.xml | 2 +- maven-model-builder/pom.xml | 2 +- maven-model/pom.xml | 2 +- maven-plugin-api/pom.xml | 2 +- maven-repository-metadata/pom.xml | 2 +- maven-resolver-provider/pom.xml | 2 +- maven-settings-builder/pom.xml | 2 +- maven-settings/pom.xml | 2 +- maven-slf4j-provider/pom.xml | 2 +- pom.xml | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index 7d85e7525202..6cf6a2c06a56 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT apache-maven diff --git a/maven-artifact/pom.xml b/maven-artifact/pom.xml index ef112321174a..7984bf7337e8 100644 --- a/maven-artifact/pom.xml +++ b/maven-artifact/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-artifact diff --git a/maven-builder-support/pom.xml b/maven-builder-support/pom.xml index ca20b8c5868d..dbc54fb2ee4f 100644 --- a/maven-builder-support/pom.xml +++ b/maven-builder-support/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-builder-support diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index 0fb684acd172..8492627a88b5 100644 --- a/maven-compat/pom.xml +++ b/maven-compat/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-compat diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 1f52e1b63bad..74543e2e4071 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-core diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 7af181714fa0..085373bcd4da 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-embedder diff --git a/maven-model-builder/pom.xml b/maven-model-builder/pom.xml index f03c59c3b6ae..b0eb11a91c4e 100644 --- a/maven-model-builder/pom.xml +++ b/maven-model-builder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-model-builder diff --git a/maven-model/pom.xml b/maven-model/pom.xml index f9f015349e2c..5a48eacf7b69 100644 --- a/maven-model/pom.xml +++ b/maven-model/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-model diff --git a/maven-plugin-api/pom.xml b/maven-plugin-api/pom.xml index 8abe7430d673..d88c4f0f3ff3 100644 --- a/maven-plugin-api/pom.xml +++ b/maven-plugin-api/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-plugin-api diff --git a/maven-repository-metadata/pom.xml b/maven-repository-metadata/pom.xml index 07a0a177c5a8..dd1146fa25a5 100644 --- a/maven-repository-metadata/pom.xml +++ b/maven-repository-metadata/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-repository-metadata diff --git a/maven-resolver-provider/pom.xml b/maven-resolver-provider/pom.xml index aad87452c748..33a605b9357e 100644 --- a/maven-resolver-provider/pom.xml +++ b/maven-resolver-provider/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-resolver-provider diff --git a/maven-settings-builder/pom.xml b/maven-settings-builder/pom.xml index 868d3447d4a9..e6018234ff30 100644 --- a/maven-settings-builder/pom.xml +++ b/maven-settings-builder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-settings-builder diff --git a/maven-settings/pom.xml b/maven-settings/pom.xml index 4a33dbe3eea4..3730e6c2baba 100644 --- a/maven-settings/pom.xml +++ b/maven-settings/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-settings diff --git a/maven-slf4j-provider/pom.xml b/maven-slf4j-provider/pom.xml index 604f8bbf7866..00ba5c9e4548 100644 --- a/maven-slf4j-provider/pom.xml +++ b/maven-slf4j-provider/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.6.3 + 3.8.0-SNAPSHOT maven-slf4j-provider diff --git a/pom.xml b/pom.xml index c770f0d33c5c..c890214b1bb3 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ under the License. maven - 3.6.3 + 3.8.0-SNAPSHOT pom Apache Maven From 02bc2a69fc8d1a14ff35645d9478b686a07cf29f Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sun, 28 Feb 2021 22:18:23 +0100 Subject: [PATCH 002/188] Add versionlessMavenDist profile --- apache-maven/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index 6cf6a2c06a56..485923df8314 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -319,6 +319,12 @@ under the License. + + + versionlessMavenDist + + ${project.artifactId} + From a96fd11b1fb9724d563cfde60288d17ddd22bf7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sat, 13 Mar 2021 21:46:48 +0100 Subject: [PATCH 003/188] [MNG-3220] fix doc: dependencyManagement import require scope import --- maven-model-builder/src/site/apt/index.apt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-model-builder/src/site/apt/index.apt b/maven-model-builder/src/site/apt/index.apt index e18ad9deb331..f7dd1d2e038c 100644 --- a/maven-model-builder/src/site/apt/index.apt +++ b/maven-model-builder/src/site/apt/index.apt @@ -81,7 +81,7 @@ Maven Model Builder with its <<>> implementation in maven-core ({{{./maven-core/xref/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.html}source}}) - ** dependency management import (for dependencies of type <<>> in the <<<\>>> section) + ** dependency management import (for dependencies of type <<>> and scope <<>> in the <<<\>>> section) ** dependency management injection: <<>> ({{{./apidocs/org/apache/maven/model/management/DependencyManagementInjector.html}javadoc}}), with its <<>> implementation From 09f77da9b0c39848fe763bdd4a392151eec0d8c3 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Tue, 16 Mar 2021 18:22:04 +0100 Subject: [PATCH 004/188] [MNG-7119] Upgrade Maven Wagon to 3.4.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c890214b1bb3..f94b73ab29ba 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,7 @@ under the License. 3.2.1 4.2.1 0.3.4 - 3.3.4 + 3.4.3 1.12.1 1.4 1.7 From e5f6634e17362387282b3867c9b23d4b54fea871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sun, 14 Mar 2021 20:52:42 +0100 Subject: [PATCH 005/188] use Maven Resolver 1.6.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f94b73ab29ba..4168c58bafbf 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ under the License. 1.7 1.11 1.3 - 1.4.1 + 1.6.2 1.7.29 2.2.1 1.7.4 From fa79cb22e456cc65522b5bab8c4240fe08c5775f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sat, 13 Mar 2021 18:40:48 +0100 Subject: [PATCH 006/188] [MNG-7116] add support for mirrorOf external:http:* --- .../repository/DefaultMirrorSelector.java | 51 ++++++++++++++++--- .../maven/bridge/MavenRepositorySystem.java | 48 +++++++++++++++-- 2 files changed, 89 insertions(+), 10 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java b/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java index 6fa2c554a7a6..adb562a6d091 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java @@ -41,6 +41,8 @@ public class DefaultMirrorSelector private static final String EXTERNAL_WILDCARD = "external:*"; + private static final String EXTERNAL_HTTP_WILDCARD = "external:http:*"; + public Mirror getMirror( ArtifactRepository repository, List mirrors ) { String repoId = repository.getId(); @@ -68,9 +70,14 @@ public Mirror getMirror( ArtifactRepository repository, List mirrors ) } /** - * This method checks if the pattern matches the originalRepository. Valid patterns: * = - * everything external:* = everything not on the localhost and not file based. repo,repo1 = repo - * or repo1 *,!repo1 = everything except repo1 + * This method checks if the pattern matches the originalRepository. Valid patterns: + *
    + *
  • {@code *} = everything,
  • + *
  • {@code external:*} = everything not on the localhost and not file based,
  • + *
  • {@code external:http:*} = any repository not on the localhost using HTTP,
  • + *
  • {@code repo,repo1} = {@code repo} or {@code repo1},
  • + *
  • {@code *,!repo1} = everything except {@code repo1}.
  • + *
* * @param originalRepository to compare for a match. * @param pattern used for match. Currently only '*' is supported. @@ -115,6 +122,12 @@ else if ( EXTERNAL_WILDCARD.equals( repo ) && isExternalRepo( originalRepository result = true; // don't stop processing in case a future segment explicitly excludes this repo } + // check for external:http:* + else if ( EXTERNAL_HTTP_WILDCARD.equals( repo ) && isExternalHttpRepo( originalRepository ) ) + { + result = true; + // don't stop processing in case a future segment explicitly excludes this repo + } else if ( WILDCARD.equals( repo ) ) { result = true; @@ -136,8 +149,34 @@ static boolean isExternalRepo( ArtifactRepository originalRepository ) try { URL url = new URL( originalRepository.getUrl() ); - return !( url.getHost().equals( "localhost" ) || url.getHost().equals( "127.0.0.1" ) - || url.getProtocol().equals( "file" ) ); + return !( isLocal( url.getHost() ) || url.getProtocol().equals( "file" ) ); + } + catch ( MalformedURLException e ) + { + // bad url just skip it here. It should have been validated already, but the wagon lookup will deal with it + return false; + } + } + + private static boolean isLocal( String host ) + { + return "localhost".equals( host ) || "127.0.0.1".equals( host ); + } + + /** + * Checks the URL to see if this repository refers to a non-localhost repository using HTTP. + * + * @param originalRepository + * @return true if external. + */ + static boolean isExternalHttpRepo( ArtifactRepository originalRepository ) + { + try + { + URL url = new URL( originalRepository.getUrl() ); + return ( "http".equalsIgnoreCase( url.getProtocol() ) || "dav".equalsIgnoreCase( url.getProtocol() ) + || "dav:http".equalsIgnoreCase( url.getProtocol() ) + || "dav+http".equalsIgnoreCase( url.getProtocol() ) ) && !isLocal( url.getHost() ); } catch ( MalformedURLException e ) { @@ -146,7 +185,7 @@ static boolean isExternalRepo( ArtifactRepository originalRepository ) } } - static boolean matchesLayout( ArtifactRepository repository, Mirror mirror ) + static boolean matchesLayout( ArtifactRepository repository, Mirror mirror ) { return matchesLayout( RepositoryUtils.getLayout( repository ), mirror.getMirrorOfLayouts() ); } diff --git a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java index 730b428221d0..90bfdcdce288 100644 --- a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java +++ b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java @@ -710,6 +710,8 @@ public ArtifactRepository createLocalRepository( MavenExecutionRequest request, private static final String EXTERNAL_WILDCARD = "external:*"; + private static final String EXTERNAL_HTTP_WILDCARD = "external:http:*"; + public static Mirror getMirror( ArtifactRepository repository, List mirrors ) { String repoId = repository.getId(); @@ -737,8 +739,14 @@ public static Mirror getMirror( ArtifactRepository repository, List mirr } /** - * This method checks if the pattern matches the originalRepository. Valid patterns: * = everything external:* = - * everything not on the localhost and not file based. repo,repo1 = repo or repo1 *,!repo1 = everything except repo1 + * This method checks if the pattern matches the originalRepository. Valid patterns: + *
    + *
  • {@code *} = everything,
  • + *
  • {@code external:*} = everything not on the localhost and not file based,
  • + *
  • {@code external:http:*} = any repository not on the localhost using HTTP,
  • + *
  • {@code repo,repo1} = {@code repo} or {@code repo1},
  • + *
  • {@code *,!repo1} = everything except {@code repo1}.
  • + *
* * @param originalRepository to compare for a match. * @param pattern used for match. Currently only '*' is supported. @@ -782,6 +790,12 @@ else if ( EXTERNAL_WILDCARD.equals( repo ) && isExternalRepo( originalRepository result = true; // don't stop processing in case a future segment explicitly excludes this repo } + // check for external:http:* + else if ( EXTERNAL_HTTP_WILDCARD.equals( repo ) && isExternalHttpRepo( originalRepository ) ) + { + result = true; + // don't stop processing in case a future segment explicitly excludes this repo + } else if ( WILDCARD.equals( repo ) ) { result = true; @@ -803,8 +817,34 @@ static boolean isExternalRepo( ArtifactRepository originalRepository ) try { URL url = new URL( originalRepository.getUrl() ); - return !( url.getHost().equals( "localhost" ) || url.getHost().equals( "127.0.0.1" ) - || url.getProtocol().equals( "file" ) ); + return !( isLocal( url.getHost() ) || url.getProtocol().equals( "file" ) ); + } + catch ( MalformedURLException e ) + { + // bad url just skip it here. It should have been validated already, but the wagon lookup will deal with it + return false; + } + } + + private static boolean isLocal( String host ) + { + return "localhost".equals( host ) || "127.0.0.1".equals( host ); + } + + /** + * Checks the URL to see if this repository refers to a non-localhost repository using HTTP. + * + * @param originalRepository + * @return true if external. + */ + static boolean isExternalHttpRepo( ArtifactRepository originalRepository ) + { + try + { + URL url = new URL( originalRepository.getUrl() ); + return ( "http".equalsIgnoreCase( url.getProtocol() ) || "dav".equalsIgnoreCase( url.getProtocol() ) + || "dav:http".equalsIgnoreCase( url.getProtocol() ) + || "dav+http".equalsIgnoreCase( url.getProtocol() ) ) && !isLocal( url.getHost() ); } catch ( MalformedURLException e ) { From 899465aeec03753ea91e15a79579eab76369c016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sat, 13 Mar 2021 18:00:59 +0100 Subject: [PATCH 007/188] [MNG-7117] add support for blocked mirror --- .../DefaultRepositorySystemSessionFactory.java | 4 ++-- maven-settings/pom.xml | 2 +- maven-settings/src/main/mdo/settings.mdo | 13 +++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index 248a3b6dd120..bda467c45e06 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -177,8 +177,8 @@ else if ( request.isUpdateSnapshots() ) DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector(); for ( Mirror mirror : request.getMirrors() ) { - mirrorSelector.add( mirror.getId(), mirror.getUrl(), mirror.getLayout(), false, mirror.getMirrorOf(), - mirror.getMirrorOfLayouts() ); + mirrorSelector.add( mirror.getId(), mirror.getUrl(), mirror.getLayout(), false, mirror.isBlocked(), + mirror.getMirrorOf(), mirror.getMirrorOfLayouts() ); } session.setMirrorSelector( mirrorSelector ); diff --git a/maven-settings/pom.xml b/maven-settings/pom.xml index 3730e6c2baba..70866e54ca79 100644 --- a/maven-settings/pom.xml +++ b/maven-settings/pom.xml @@ -46,7 +46,7 @@ under the License. org.codehaus.modello modello-maven-plugin - 1.1.0 + 1.2.0 src/main/mdo/settings.mdo diff --git a/maven-settings/src/main/mdo/settings.mdo b/maven-settings/src/main/mdo/settings.mdo index 333d8bd7ac86..b0498df43a42 100644 --- a/maven-settings/src/main/mdo/settings.mdo +++ b/maven-settings/src/main/mdo/settings.mdo @@ -633,6 +633,15 @@ of the mirror to repositories with a matching layout (apart from a matching id). Since Maven 3. + + blocked + 1.2.0+ + boolean + false + + Whether this mirror should be blocked from any download request but fail the download process, explaining why. + + @@ -648,6 +657,10 @@ sb.append( ",mirrorOf=" ).append( mirrorOf ); sb.append( ",url=" ).append( this.url ); sb.append( ",name=" ).append( this.name ); + if ( isBlocked() ) + { + sb.append( ",blocked" ); + } sb.append( "]" ); return sb.toString(); } From 907d53ad3264718f66ff15e1363d76b07dd0c05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sat, 13 Mar 2021 19:03:43 +0100 Subject: [PATCH 008/188] [MNG-7118] block HTTP repositories by default --- apache-maven/src/conf/settings.xml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apache-maven/src/conf/settings.xml b/apache-maven/src/conf/settings.xml index e27c579cf6db..99d8b1a4b01d 100644 --- a/apache-maven/src/conf/settings.xml +++ b/apache-maven/src/conf/settings.xml @@ -43,9 +43,9 @@ under the License. | values (values used when the setting is not specified) are provided. | |--> - + xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd"> + + maven-default-http-blocker + external:http:* + Pseudo repository to mirror external repositories initially using HTTP. + http://0.0.0.0/ + true + - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.codehaus.mojo - buildnumber-maven-plugin - [1.2,) - - create-timestamp - - - - - - - - - - @@ -234,16 +209,6 @@ under the License. org.codehaus.mojo buildnumber-maven-plugin - - create-noncanonicalrev - - create-timestamp - - - 'NON-CANONICAL_'yyyy-MM-dd'T'HH:mm:ssXXX_'${user.name}' - nonCanonicalRevision - - create-buildnumber @@ -252,7 +217,7 @@ under the License. false false - ${nonCanonicalRevision} + NON_CANONICAL From 8f58b85eaf724a98d1332cfbb3e0a3de58c9587b Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Mon, 4 Jan 2021 20:07:46 +0100 Subject: [PATCH 045/188] [MNG-7064] Use HTTPS for schema location in global settings.xml --- apache-maven/src/conf/settings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apache-maven/src/conf/settings.xml b/apache-maven/src/conf/settings.xml index 99d8b1a4b01d..9a80350ff042 100644 --- a/apache-maven/src/conf/settings.xml +++ b/apache-maven/src/conf/settings.xml @@ -45,7 +45,7 @@ under the License. |--> + xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd"> - - org.apache.maven.plugins - maven-source-plugin - 3.2.1 - - - org.apache.maven.plugins - maven-jar-plugin - 3.2.0 - - - org.apache.maven.plugins - maven-assembly-plugin - 3.2.0 - org.codehaus.plexus plexus-component-metadata From 2a2392f15e3cbdc7a7c8a453a4cbed314947a036 Mon Sep 17 00:00:00 2001 From: huangkaifeng Date: Mon, 2 Mar 2020 22:10:50 +0800 Subject: [PATCH 049/188] [MNG-6873] Align JUnit version to 4.13 Closes #331 --- .../test/java/org/apache/maven/project/PomConstructionTest.java | 2 +- .../lifecycle-executor/project-with-inheritance/pom.xml | 2 +- .../projects/plugin-manager/project-with-inheritance/pom.xml | 2 +- .../resources-project-builder/dependency-inheritance/pom.xml | 2 +- .../dependency-inheritance/sub/pom.xml | 2 +- .../src/test/resources-project-builder/micromailer/pom.xml | 2 +- .../src/test/resources/org/apache/maven/lifecycle/pom.xml | 2 +- maven-embedder/src/examples/simple-project/pom.xml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index 9e16ebc59487..e44e60f023b7 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -975,7 +975,7 @@ public void testDependencyInheritance() { PomTestWrapper pom = buildPom( "dependency-inheritance/sub" ); assertEquals( 1, ( (List) pom.getValue( "dependencies" ) ).size() ); - assertEquals( "4.4", pom.getValue( "dependencies[1]/version" ) ); + assertEquals( "4.13", pom.getValue( "dependencies[1]/version" ) ); } /** MNG-4034 */ diff --git a/maven-core/src/test/projects/lifecycle-executor/project-with-inheritance/pom.xml b/maven-core/src/test/projects/lifecycle-executor/project-with-inheritance/pom.xml index c19061ad9661..c9a894d9059b 100644 --- a/maven-core/src/test/projects/lifecycle-executor/project-with-inheritance/pom.xml +++ b/maven-core/src/test/projects/lifecycle-executor/project-with-inheritance/pom.xml @@ -53,7 +53,7 @@ under the License. --> 1.0-alpha-9 1.2_Java1.3 - 3.8.1 + 4.13 1.0-beta-3.0.7 1.0-alpha-6 1.1 diff --git a/maven-core/src/test/projects/plugin-manager/project-with-inheritance/pom.xml b/maven-core/src/test/projects/plugin-manager/project-with-inheritance/pom.xml index c19061ad9661..c9a894d9059b 100644 --- a/maven-core/src/test/projects/plugin-manager/project-with-inheritance/pom.xml +++ b/maven-core/src/test/projects/plugin-manager/project-with-inheritance/pom.xml @@ -53,7 +53,7 @@ under the License. --> 1.0-alpha-9 1.2_Java1.3 - 3.8.1 + 4.13 1.0-beta-3.0.7 1.0-alpha-6 1.1 diff --git a/maven-core/src/test/resources-project-builder/dependency-inheritance/pom.xml b/maven-core/src/test/resources-project-builder/dependency-inheritance/pom.xml index 736b793c8e87..8f9c028e3823 100644 --- a/maven-core/src/test/resources-project-builder/dependency-inheritance/pom.xml +++ b/maven-core/src/test/resources-project-builder/dependency-inheritance/pom.xml @@ -33,7 +33,7 @@ under the License. pom - 3.8.1 + 4.13 diff --git a/maven-core/src/test/resources-project-builder/dependency-inheritance/sub/pom.xml b/maven-core/src/test/resources-project-builder/dependency-inheritance/sub/pom.xml index aaf8e8e5ab58..832f49e321ff 100644 --- a/maven-core/src/test/resources-project-builder/dependency-inheritance/sub/pom.xml +++ b/maven-core/src/test/resources-project-builder/dependency-inheritance/sub/pom.xml @@ -25,7 +25,7 @@ junit junit - 4.4 + 4.13 test diff --git a/maven-core/src/test/resources-project-builder/micromailer/pom.xml b/maven-core/src/test/resources-project-builder/micromailer/pom.xml index 44f1cd9f22d0..0e875a7a1d4c 100644 --- a/maven-core/src/test/resources-project-builder/micromailer/pom.xml +++ b/maven-core/src/test/resources-project-builder/micromailer/pom.xml @@ -97,7 +97,7 @@ junit junit - 3.8.2 + 4.13 jar test diff --git a/maven-core/src/test/resources/org/apache/maven/lifecycle/pom.xml b/maven-core/src/test/resources/org/apache/maven/lifecycle/pom.xml index cd0a3d81712e..531e5510c5a7 100644 --- a/maven-core/src/test/resources/org/apache/maven/lifecycle/pom.xml +++ b/maven-core/src/test/resources/org/apache/maven/lifecycle/pom.xml @@ -53,7 +53,7 @@ under the License. --> 1.0-alpha-9 1.2_Java1.3 - 3.8.1 + 4.13 1.0-beta-3.0.7-SNAPSHOT 1.0-alpha-6 1.1 diff --git a/maven-embedder/src/examples/simple-project/pom.xml b/maven-embedder/src/examples/simple-project/pom.xml index 62de37aac1be..843b38e32b52 100644 --- a/maven-embedder/src/examples/simple-project/pom.xml +++ b/maven-embedder/src/examples/simple-project/pom.xml @@ -29,7 +29,7 @@ under the License. junit junit - 3.8.1 + 4.13 test From 9ae1d95a581bbf07bab72aff7aa26b096a267615 Mon Sep 17 00:00:00 2001 From: Artem Krosheninnikov Date: Thu, 9 Jan 2020 11:12:22 +0300 Subject: [PATCH 050/188] [MNG-6844] Use StandardCharsets and remove outdated @SuppressWarnings This closes #312 --- .../org/apache/maven/settings/GlobalSettingsTest.java | 3 ++- .../java/org/apache/maven/building/StringSource.java | 3 ++- .../inheritance/DefaultModelInheritanceAssembler.java | 3 --- .../artifact/AbstractArtifactComponentTestCase.java | 3 ++- .../apache/maven/repository/legacy/StringWagon.java | 10 ++-------- .../maven/artifact/handler/ArtifactHandlerTest.java | 1 - .../internal/stub/DefaultLifecyclesStub.java | 1 - .../maven/project/ExtensionDescriptorBuilderTest.java | 11 ++--------- .../main/java/org/apache/maven/cli/CLIManager.java | 2 +- .../interpolation/ProblemDetectingValueSource.java | 1 - 10 files changed, 11 insertions(+), 27 deletions(-) diff --git a/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java b/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java index 0d0543e2899d..257350c90510 100644 --- a/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java +++ b/apache-maven/src/test/java/org/apache/maven/settings/GlobalSettingsTest.java @@ -26,6 +26,7 @@ import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.StandardCharsets; /** * Tests that the global settings.xml shipped with the distribution is in good state. @@ -44,7 +45,7 @@ public void testValidGlobalSettings() File globalSettingsFile = new File( basedir, "src/conf/settings.xml" ); assertTrue( globalSettingsFile.getAbsolutePath(), globalSettingsFile.isFile() ); - try ( Reader reader = new InputStreamReader( new FileInputStream( globalSettingsFile ), "UTF-8" ) ) + try ( Reader reader = new InputStreamReader( new FileInputStream( globalSettingsFile ), StandardCharsets.UTF_8) ) { new SettingsXpp3Reader().read( reader ); } diff --git a/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java b/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java index f9d87c0ba649..7705804aa4b2 100644 --- a/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java +++ b/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java @@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; /** * Wraps an ordinary {@link CharSequence} as a source. @@ -62,7 +63,7 @@ public StringSource( CharSequence content, String location ) public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream( content.getBytes( "UTF-8" ) ); + return new ByteArrayInputStream( content.getBytes( StandardCharsets.UTF_8 ) ); } @Override diff --git a/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java b/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java index 7c3ca79ae309..2071cecc740e 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java +++ b/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java @@ -55,7 +55,6 @@ public class DefaultModelInheritanceAssembler implements ModelInheritanceAssembler { // TODO Remove this! - @SuppressWarnings( "unchecked" ) public void assembleBuildInheritance( Build childBuild, Build parentBuild, boolean handleAsInheritance ) { // The build has been set but we want to step in here and fill in @@ -307,7 +306,6 @@ private void assembleModelInheritance( Model child, Model parent, String childPa } // TODO Remove this! - @SuppressWarnings( "unchecked" ) private void assembleDependencyManagementInheritance( Model child, Model parent ) { DependencyManagement parentDepMgmt = parent.getDependencyManagement(); @@ -527,7 +525,6 @@ else if ( handleAsInheritance && ( parentInherited == null ) ) } // TODO Remove this! - @SuppressWarnings( "unchecked" ) private void assembleDependencyInheritance( Model child, Model parent ) { Map depsMap = new LinkedHashMap<>(); diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java index 2ce37940791a..dbd6e8ffd758 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java @@ -59,6 +59,7 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -293,7 +294,7 @@ protected void createArtifact( Artifact artifact, ArtifactRepository repository { artifactFile.getParentFile().mkdirs(); } - try ( Writer writer = new OutputStreamWriter( new FileOutputStream( artifactFile ), "ISO-8859-1" ) ) + try ( Writer writer = new OutputStreamWriter( new FileOutputStream( artifactFile ), StandardCharsets.ISO_8859_1) ) { writer.write( artifact.getId() ); } diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/StringWagon.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/StringWagon.java index 944cce62d71f..3a72b98e9a0c 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/StringWagon.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/StringWagon.java @@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -72,14 +73,7 @@ public void fillInputData( InputData inputData ) resource.setContentLength( content.length() ); resource.setLastModified( System.currentTimeMillis() ); - try - { - inputData.setInputStream( new ByteArrayInputStream( content.getBytes( "UTF-8" ) ) ); - } - catch ( UnsupportedEncodingException e ) - { - throw new Error( "broken JVM", e ); - } + inputData.setInputStream( new ByteArrayInputStream( content.getBytes( StandardCharsets.UTF_8 ) ) ); } else { diff --git a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java index 69f59fdb364e..2803d8d80a29 100644 --- a/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java +++ b/maven-core/src/test/java/org/apache/maven/artifact/handler/ArtifactHandlerTest.java @@ -33,7 +33,6 @@ public void testAptConsistency() { File apt = getTestFile( "src/site/apt/artifact-handlers.apt" ); - @SuppressWarnings( "unchecked" ) List lines = FileUtils.loadFile( apt ); for ( String line : lines ) diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java index 1dc2b6b0a633..a1a95322941b 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java @@ -47,7 +47,6 @@ public static DefaultLifecycles createDefaultLifecycles() List stubSiteCycle = Arrays.asList( PRE_SITE.getPhase(), SITE.getPhase(), POST_SITE.getPhase(), SITE_DEPLOY.getPhase() ); - @SuppressWarnings( "unchecked" ) Iterator> lcs = Arrays.asList( stubDefaultCycle, stubCleanCycle, stubSiteCycle ).iterator(); Map lifeCycles = new HashMap<>(); diff --git a/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java index 7a5e55d1eb1b..5ac8f611cf92 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ExtensionDescriptorBuilderTest.java @@ -25,7 +25,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import junit.framework.TestCase; @@ -61,14 +61,7 @@ protected void tearDown() private InputStream toStream( String xml ) { - try - { - return new ByteArrayInputStream( xml.getBytes( "UTF-8" ) ); - } - catch ( UnsupportedEncodingException e ) - { - throw new IllegalStateException( e ); - } + return new ByteArrayInputStream( xml.getBytes( StandardCharsets.UTF_8 ) ); } public void testEmptyDescriptor() diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java index a0d54d3bf944..edd60c91c0bb 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java @@ -107,7 +107,7 @@ public class CLIManager protected Options options; - @SuppressWarnings( { "static-access", "checkstyle:linelength" } ) + @SuppressWarnings( "checkstyle:linelength" ) public CLIManager() { options = new Options(); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java index 4ed98d035dd3..0b29f20e71cc 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/ProblemDetectingValueSource.java @@ -72,7 +72,6 @@ public Object getValue( String expression ) } @Override - @SuppressWarnings( "unchecked" ) public List getFeedback() { return valueSource.getFeedback(); From 8b693cc992ff4a5947babecd222fbebf7516e677 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Fri, 2 Jul 2021 17:50:44 +0200 Subject: [PATCH 051/188] Document hacks as such --- .../org/apache/maven/project/artifact/MavenMetadataSource.java | 1 + .../repository/internal/DefaultArtifactDescriptorReader.java | 1 + 2 files changed, 2 insertions(+) diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 1c40af8b9869..ac55fb93eb4d 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -180,6 +180,7 @@ public ResolutionGroup retrieve( MetadataResolutionRequest request ) Artifact relocatedArtifact = null; + // TODO hack: don't rebuild model if it was already loaded during reactor resolution final WorkspaceReader workspace = legacySupport.getRepositorySession().getWorkspaceReader(); Model model = null; if ( workspace instanceof MavenWorkspaceReader ) diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java index 586c83e271e9..c2ba0a3d729a 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java @@ -257,6 +257,7 @@ private Model loadPom( RepositorySystemSession session, ArtifactDescriptorReques Model model; + // TODO hack: don't rebuild model if it was already loaded during reactor resolution final WorkspaceReader workspace = session.getWorkspaceReader(); if ( workspace instanceof MavenWorkspaceReader ) { From 7358b084b120e28f42b5ae37b1c298ba123e2a5e Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sat, 3 Jul 2021 11:12:47 +0200 Subject: [PATCH 052/188] Add new ignores --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f79c9285cd4c..f85dc5684299 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ out/ /bootstrap /dependencies.xml .java-version +.factorypath +.checkstyle From 7b355f72235c0bd26b872601b38a493ed1cc518b Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sat, 3 Jul 2021 18:28:31 +0200 Subject: [PATCH 053/188] [MNG-7180] Make --color option behave more like BSD/GNU grep's --color option --- .../src/main/java/org/apache/maven/cli/CLIManager.java | 2 +- .../src/main/java/org/apache/maven/cli/MavenCli.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java index edd60c91c0bb..2ad542457b31 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java @@ -152,7 +152,7 @@ public CLIManager() options.addOption( Option.builder( "up" ).longOpt( "update-plugins" ).desc( "Ineffective, only kept for backward compatibility" ).build() ); options.addOption( Option.builder( "npu" ).longOpt( "no-plugin-updates" ).desc( "Ineffective, only kept for backward compatibility" ).build() ); - options.addOption( Option.builder().longOpt( COLOR ).hasArg().desc( "Defines the color mode of the output. Available options are auto/always/never" ).build() ); + options.addOption( Option.builder().longOpt( COLOR ).hasArg().optionalArg( true ).desc( "Defines the color mode of the output. Supported are 'auto', 'always', 'never'." ).build() ); } public CommandLine parse( String[] args ) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index e8e2f7401b7c..feed90561d35 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -506,18 +506,18 @@ else if ( cliRequest.quiet ) // LOG COLOR String styleColor = cliRequest.getUserProperties().getProperty( STYLE_COLOR_PROPERTY, "auto" ); styleColor = cliRequest.commandLine.getOptionValue( COLOR, styleColor ); - if ( "always".equals( styleColor ) ) + if ( "always".equals( styleColor ) || "yes".equals( styleColor ) || "force".equals( styleColor ) ) { MessageUtils.setColorEnabled( true ); } - else if ( "never".equals( styleColor ) ) + else if ( "never".equals( styleColor ) || "no".equals( styleColor ) || "none".equals( styleColor ) ) { MessageUtils.setColorEnabled( false ); } - else if ( !"auto".equals( styleColor ) ) + else if ( !"auto".equals( styleColor ) && !"tty".equals( styleColor ) && !"if-tty".equals( styleColor ) ) { - throw new IllegalArgumentException( "Invalid color configuration option [" + styleColor - + "]. Supported values are (auto|always|never)." ); + throw new IllegalArgumentException( "Invalid color configuration value '" + styleColor + + "'. Supported are 'auto', 'always', 'never'." ); } else if ( cliRequest.commandLine.hasOption( CLIManager.BATCH_MODE ) || cliRequest.commandLine.hasOption( CLIManager.LOG_FILE ) ) From 7a8acdd8e66de81b4f7f918905976191837bf147 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sat, 3 Jul 2021 19:17:19 +0200 Subject: [PATCH 054/188] [MNG-7181] Make --version support -q --- .../java/org/apache/maven/cli/CLIReportingUtils.java | 7 +++++++ .../src/main/java/org/apache/maven/cli/MavenCli.java | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java index 97a2db65bde1..57be1963295f 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java @@ -75,6 +75,13 @@ public static String showVersion() return version.toString(); } + public static String showVersionMinimal() + { + Properties properties = getBuildProperties(); + String version = reduce( properties.getProperty( BUILD_VERSION_PROPERTY ) ); + return ( version != null ? version : "" ); + } + /** * Create a human readable string containing the Maven version, buildnumber, and time of build * diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index feed90561d35..fbcb05f91371 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -433,7 +433,14 @@ private void informativeCommands( CliRequest cliRequest ) throws ExitException if ( cliRequest.commandLine.hasOption( CLIManager.VERSION ) ) { - System.out.println( CLIReportingUtils.showVersion() ); + if ( cliRequest.commandLine.hasOption( CLIManager.QUIET ) ) + { + System.out.println( CLIReportingUtils.showVersionMinimal() ); + } + else + { + System.out.println( CLIReportingUtils.showVersion() ); + } throw new ExitException( 0 ); } } From 0635e92665cbd247a4144c328321b0e9f058398e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sun, 11 Jul 2021 19:00:24 +0200 Subject: [PATCH 055/188] [MNG-7184] document .mavenrc/mavenrc_pre.bat|cmd and MAVEN_SKIP_RC --- apache-maven/src/site/apt/index.apt.vm | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 apache-maven/src/site/apt/index.apt.vm diff --git a/apache-maven/src/site/apt/index.apt.vm b/apache-maven/src/site/apt/index.apt.vm new file mode 100644 index 000000000000..994aeab1d9eb --- /dev/null +++ b/apache-maven/src/site/apt/index.apt.vm @@ -0,0 +1,40 @@ +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you under the Apache License, Version 2.0 (the +~~ "License"); you may not use this file except in compliance +~~ with the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, +~~ software distributed under the License is distributed on an +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +~~ KIND, either express or implied. See the License for the +~~ specific language governing permissions and limitations +~~ under the License. + + ----- + ${project.name} + ----- + Hervé Boutemy + ----- + 2021-07-11 + ----- + +${project.name} + + ${project.description} + +* References + + * <<>> invocation can be customised through: + + * <<>> and <<<~/.mavenrc>>> scripts on Unix, + + * <<<~\mavenrc_pre.bat>>> and <<<~\mavenrc_pre.cmd>>> scripts on Windows, + + [] + + and these scripts calls can be disabled by setting <<>> environment variable. From 842e7c88da3b310031d58325874c4b6b9a182c04 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Mon, 12 Jul 2021 19:36:38 +0200 Subject: [PATCH 056/188] [MNG-7186] Upgrade Guice to 4.2.2 --- maven-embedder/pom.xml | 4 ++++ pom.xml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index cf065031a7c2..8e08be47322a 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -104,6 +104,10 @@ under the License. org.codehaus.mojo animal-sniffer-annotations + + org.checkerframework + checker-qual + diff --git a/pom.xml b/pom.xml index 84abe1ad615a..dbe5eb2de604 100644 --- a/pom.xml +++ b/pom.xml @@ -57,7 +57,7 @@ under the License. 2.1.0 1.25 3.2.1 - 4.2.1 + 4.2.2 0.3.4 3.4.3 1.12.1 From a27b4ee595ee48833fa659ee30ff463f26c4a50d Mon Sep 17 00:00:00 2001 From: Marc Bruggmann Date: Thu, 10 Sep 2020 15:21:55 +0200 Subject: [PATCH 057/188] [MNG-6987] Reorder groupId before artifactId when writing an exclusion using maven-model In most other places, we order the groupId before the artifactId. Exclusion was the odd one out, so I changed it to be in line with the others. This closes #375 --- maven-model/src/main/mdo/maven.mdo | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maven-model/src/main/mdo/maven.mdo b/maven-model/src/main/mdo/maven.mdo index 7f439faa9f7d..61d9ceb6d5fe 100644 --- a/maven-model/src/main/mdo/maven.mdo +++ b/maven-model/src/main/mdo/maven.mdo @@ -1191,16 +1191,16 @@ - artifactId + groupId 4.0.0+ - The artifact ID of the project to exclude. + The group ID of the project to exclude. String true - groupId + artifactId 4.0.0+ - The group ID of the project to exclude. + The artifact ID of the project to exclude. String true From 5d6bb35b048d9d430c38cdf16f53b850a9ca9e4e Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Sat, 7 Dec 2019 10:28:19 +0100 Subject: [PATCH 058/188] [MNG-6810] - Remove profiles in maven-model --- maven-model/pom.xml | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/maven-model/pom.xml b/maven-model/pom.xml index 122e0b9b8b95..cd9a63940231 100644 --- a/maven-model/pom.xml +++ b/maven-model/pom.xml @@ -82,46 +82,4 @@ under the License. - - - all-models - - - - org.codehaus.modello - modello-maven-plugin - - - v3 - - java - xpp3-writer - xpp3-reader - xsd - - - 3.0.0 - true - - - - - - maven-jar-plugin - - - package - - jar - - - all - - - - - - - - From 5060349e676f2133219950f0d670997dacfbad69 Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Sat, 7 Dec 2019 15:18:46 +0100 Subject: [PATCH 059/188] [MNG-6811] - Remove unnecessary filtering configuration --- maven-embedder/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 8e08be47322a..2edf4171d63b 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -174,12 +174,6 @@ under the License. - - - src/main/resources - true - - From f32c3dba9495e3b7d4a73de6d303ae2eedb769f5 Mon Sep 17 00:00:00 2001 From: Romain Manni-Bucau Date: Thu, 6 Sep 2018 11:08:14 +0200 Subject: [PATCH 060/188] [MNG-6471] Parallel builder should use the module name as thread name This closes #177 --- .../multithreaded/MultiThreadedBuilder.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java index 94d10af4b44c..2688a6b4357c 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java @@ -186,12 +186,23 @@ private Callable createBuildCallable( final MavenSession rootSes { public ProjectSegment call() { - // muxer.associateThreadWithProjectSegment( projectBuild ); - lifecycleModuleBuilder.buildProject( projectBuild.getSession(), rootSession, reactorContext, - projectBuild.getProject(), taskSegment ); - // muxer.setThisModuleComplete( projectBuild ); + final Thread currentThread = Thread.currentThread(); + final String originalThreadName = currentThread.getName(); + currentThread.setName( "mvn-builder-" + projectBuild.getProject().getId() ); - return projectBuild; + try + { + // muxer.associateThreadWithProjectSegment( projectBuild ); + lifecycleModuleBuilder.buildProject( projectBuild.getSession(), rootSession, reactorContext, + projectBuild.getProject(), taskSegment ); + // muxer.setThisModuleComplete( projectBuild ); + + return projectBuild; + } + finally + { + currentThread.setName( originalThreadName ); + } } }; } From a3907fcb2b541d80852611b68494965f10b828f2 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sun, 11 Oct 2020 20:27:49 +0200 Subject: [PATCH 061/188] [MNG-6754] Set the same timestamp in multi module builds Reuse MavenExecutionRequest#getStartTime() throughout for snapshot versions, last updated fields in metadata consistently for local and remote repositories for the entire reactor and its modules. This closes #381 --- .../installer/DefaultArtifactInstaller.java | 1 + .../transform/ReleaseArtifactTransformation.java | 1 + .../transform/SnapshotTransformation.java | 1 + .../metadata/AbstractRepositoryMetadata.java | 1 - .../DefaultRepositorySystemSessionFactory.java | 1 + .../internal/LocalSnapshotMetadata.java | 15 ++++++++------- .../internal/LocalSnapshotMetadataGenerator.java | 7 ++++++- .../maven/repository/internal/MavenMetadata.java | 8 ++++++-- .../internal/MavenSnapshotMetadata.java | 5 +++-- .../internal/RemoteSnapshotMetadata.java | 14 +++++++------- .../internal/RemoteSnapshotMetadataGenerator.java | 9 +++++++-- .../repository/internal/VersionsMetadata.java | 13 +++++++------ .../internal/VersionsMetadataGenerator.java | 7 ++++++- .../internal/RemoteSnapshotMetadataTest.java | 2 +- 14 files changed, 55 insertions(+), 30 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java b/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java index a2529757c1cc..5deee382f948 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java @@ -123,6 +123,7 @@ else if ( metadata instanceof SnapshotArtifactRepositoryMetadata } Versioning versioning = new Versioning(); + // TODO Should this be changed for MNG-6754 too? versioning.updateTimestamp(); versioning.addVersion( artifact.getBaseVersion() ); if ( artifact.isRelease() ) diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ReleaseArtifactTransformation.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ReleaseArtifactTransformation.java index 3714924c6670..b1d2c7107a5f 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ReleaseArtifactTransformation.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ReleaseArtifactTransformation.java @@ -82,6 +82,7 @@ public void transformForDeployment( Artifact artifact, ArtifactRepository remote private ArtifactMetadata createMetadata( Artifact artifact ) { Versioning versioning = new Versioning(); + // TODO Should this be changed for MNG-6754 too? versioning.updateTimestamp(); versioning.addVersion( artifact.getVersion() ); diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/SnapshotTransformation.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/SnapshotTransformation.java index 895b952669e6..1a79049b17e4 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/SnapshotTransformation.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/SnapshotTransformation.java @@ -91,6 +91,7 @@ public void transformForDeployment( Artifact artifact, ArtifactRepository remote { Snapshot snapshot = new Snapshot(); + // TODO Should this be changed for MNG-6754 too? snapshot.setTimestamp( getDeploymentTimestamp() ); // we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java b/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java index 46c41b94e75d..4ebe33f2c1f7 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java @@ -165,7 +165,6 @@ protected static Versioning createVersioning( Snapshot snapshot ) { Versioning versioning = new Versioning(); versioning.setSnapshot( snapshot ); - versioning.updateTimestamp(); return versioning; } diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index bda467c45e06..9c4cede1c2c3 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -102,6 +102,7 @@ public DefaultRepositorySystemSession newRepositorySession( MavenExecutionReques Map configProps = new LinkedHashMap<>(); configProps.put( ConfigurationProperties.USER_AGENT, getUserAgent() ); configProps.put( ConfigurationProperties.INTERACTIVE, request.isInteractiveMode() ); + configProps.put( "maven.startTime", request.getStartTime() ); configProps.putAll( request.getSystemProperties() ); configProps.putAll( request.getUserProperties() ); diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java index ce09efdf4f31..453e4d2bec9d 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java @@ -22,6 +22,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; @@ -42,15 +43,15 @@ final class LocalSnapshotMetadata private final boolean legacyFormat; - LocalSnapshotMetadata( Artifact artifact, boolean legacyFormat ) + LocalSnapshotMetadata( Artifact artifact, boolean legacyFormat, Date timestamp ) { - super( createMetadata( artifact, legacyFormat ), null ); + super( createMetadata( artifact, legacyFormat ), null, timestamp ); this.legacyFormat = legacyFormat; } - LocalSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat ) + LocalSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat, Date timestamp ) { - super( metadata, file ); + super( metadata, file, timestamp ); this.legacyFormat = legacyFormat; } @@ -82,7 +83,7 @@ public void bind( Artifact artifact ) public MavenMetadata setFile( File file ) { - return new LocalSnapshotMetadata( metadata, file, legacyFormat ); + return new LocalSnapshotMetadata( metadata, file, legacyFormat, timestamp ); } public Object getKey() @@ -98,7 +99,7 @@ public static Object getKey( Artifact artifact ) @Override protected void merge( Metadata recessive ) { - metadata.getVersioning().updateTimestamp(); + metadata.getVersioning().setLastUpdatedTimestamp( timestamp ); if ( !legacyFormat ) { @@ -160,4 +161,4 @@ public Nature getNature() return Nature.SNAPSHOT; } -} \ No newline at end of file +} diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java index 584e1666064e..75b4e6b93900 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; @@ -42,10 +43,14 @@ class LocalSnapshotMetadataGenerator private final boolean legacyFormat; + private final Date timestamp; + LocalSnapshotMetadataGenerator( RepositorySystemSession session, InstallRequest request ) { legacyFormat = ConfigUtils.getBoolean( session.getConfigProperties(), false, "maven.metadata.legacy" ); + timestamp = (Date) ConfigUtils.getObject( session, new Date(), "maven.startTime" ); + snapshots = new LinkedHashMap<>(); } @@ -59,7 +64,7 @@ public Collection prepare( Collection ar LocalSnapshotMetadata snapshotMetadata = snapshots.get( key ); if ( snapshotMetadata == null ) { - snapshotMetadata = new LocalSnapshotMetadata( artifact, legacyFormat ); + snapshotMetadata = new LocalSnapshotMetadata( artifact, legacyFormat, timestamp ); snapshots.put( key, snapshotMetadata ); } snapshotMetadata.bind( artifact ); diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java index aef44f6bbb5e..bdddc709f6ae 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java @@ -34,6 +34,7 @@ import java.io.Reader; import java.io.Writer; import java.util.Collections; +import java.util.Date; import java.util.Map; /** @@ -46,16 +47,19 @@ abstract class MavenMetadata static final String MAVEN_METADATA_XML = "maven-metadata.xml"; + protected Metadata metadata; + private final File file; - protected Metadata metadata; + protected final Date timestamp; private boolean merged; - protected MavenMetadata( Metadata metadata, File file ) + protected MavenMetadata( Metadata metadata, File file, Date timestamp ) { this.metadata = metadata; this.file = file; + this.timestamp = timestamp; } public String getType() diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenSnapshotMetadata.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenSnapshotMetadata.java index e4c9a7e9e0d7..35d4d42808a1 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenSnapshotMetadata.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenSnapshotMetadata.java @@ -22,6 +22,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.Date; import org.apache.maven.artifact.repository.metadata.Metadata; import org.eclipse.aether.artifact.Artifact; @@ -38,9 +39,9 @@ abstract class MavenSnapshotMetadata protected final boolean legacyFormat; - protected MavenSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat ) + protected MavenSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat, Date timestamp ) { - super( metadata, file ); + super( metadata, file, timestamp ); this.legacyFormat = legacyFormat; } diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java index efcfb4d5e8ca..d9b56166af79 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java @@ -47,19 +47,19 @@ final class RemoteSnapshotMetadata private final Map versions = new LinkedHashMap<>(); - RemoteSnapshotMetadata( Artifact artifact, boolean legacyFormat ) + RemoteSnapshotMetadata( Artifact artifact, boolean legacyFormat, Date timestamp ) { - super( createRepositoryMetadata( artifact, legacyFormat ), null, legacyFormat ); + super( createRepositoryMetadata( artifact, legacyFormat ), null, legacyFormat, timestamp ); } - private RemoteSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat ) + private RemoteSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat, Date timestamp ) { - super( metadata, file, legacyFormat ); + super( metadata, file, legacyFormat, timestamp ); } public MavenMetadata setFile( File file ) { - return new RemoteSnapshotMetadata( metadata, file, legacyFormat ); + return new RemoteSnapshotMetadata( metadata, file, legacyFormat, timestamp ); } public String getExpandedVersion( Artifact artifact ) @@ -82,11 +82,11 @@ protected void merge( Metadata recessive ) snapshot = new Snapshot(); snapshot.setBuildNumber( getBuildNumber( recessive ) + 1 ); - snapshot.setTimestamp( utcDateFormatter.format( new Date() ) ); + snapshot.setTimestamp( utcDateFormatter.format( timestamp ) ); Versioning versioning = new Versioning(); versioning.setSnapshot( snapshot ); - versioning.setLastUpdated( snapshot.getTimestamp().replace( ".", "" ) ); + versioning.setLastUpdatedTimestamp( timestamp ); lastUpdated = versioning.getLastUpdated(); metadata.setVersioning( versioning ); diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataGenerator.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataGenerator.java index 32188636b34a..2e42bee7d5c7 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataGenerator.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataGenerator.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; @@ -42,9 +43,13 @@ class RemoteSnapshotMetadataGenerator private final boolean legacyFormat; + private final Date timestamp; + RemoteSnapshotMetadataGenerator( RepositorySystemSession session, DeployRequest request ) { - legacyFormat = ConfigUtils.getBoolean( session.getConfigProperties(), false, "maven.metadata.legacy" ); + legacyFormat = ConfigUtils.getBoolean( session, false, "maven.metadata.legacy" ); + + timestamp = (Date) ConfigUtils.getObject( session, new Date(), "maven.startTime" ); snapshots = new LinkedHashMap<>(); @@ -74,7 +79,7 @@ public Collection prepare( Collection ar RemoteSnapshotMetadata snapshotMetadata = snapshots.get( key ); if ( snapshotMetadata == null ) { - snapshotMetadata = new RemoteSnapshotMetadata( artifact, legacyFormat ); + snapshotMetadata = new RemoteSnapshotMetadata( artifact, legacyFormat, timestamp ); snapshots.put( key, snapshotMetadata ); } snapshotMetadata.bind( artifact ); diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java index f7df64ef7fa9..5103e5caea82 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java @@ -22,6 +22,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.Date; import java.util.LinkedHashSet; import org.apache.maven.artifact.repository.metadata.Metadata; @@ -38,15 +39,15 @@ final class VersionsMetadata private final Artifact artifact; - VersionsMetadata( Artifact artifact ) + VersionsMetadata( Artifact artifact, Date timestamp ) { - super( createRepositoryMetadata( artifact ), null ); + super( createRepositoryMetadata( artifact ), null, timestamp ); this.artifact = artifact; } - VersionsMetadata( Artifact artifact, File file ) + VersionsMetadata( Artifact artifact, File file, Date timestamp ) { - super( createRepositoryMetadata( artifact ), file ); + super( createRepositoryMetadata( artifact ), file, timestamp ); this.artifact = artifact; } @@ -76,7 +77,7 @@ private static Metadata createRepositoryMetadata( Artifact artifact ) protected void merge( Metadata recessive ) { Versioning versioning = metadata.getVersioning(); - versioning.updateTimestamp(); + versioning.setLastUpdatedTimestamp( timestamp ); if ( recessive.getVersioning() != null ) { @@ -107,7 +108,7 @@ public static Object getKey( Artifact artifact ) public MavenMetadata setFile( File file ) { - return new VersionsMetadata( artifact, file ); + return new VersionsMetadata( artifact, file, timestamp ); } public String getGroupId() diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGenerator.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGenerator.java index d6b5c8a41c91..409eec4221d1 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGenerator.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGenerator.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; @@ -31,6 +32,7 @@ import org.eclipse.aether.impl.MetadataGenerator; import org.eclipse.aether.installation.InstallRequest; import org.eclipse.aether.metadata.Metadata; +import org.eclipse.aether.util.ConfigUtils; /** * @author Benjamin Bentmann @@ -43,6 +45,8 @@ class VersionsMetadataGenerator private Map processedVersions; + private final Date timestamp; + VersionsMetadataGenerator( RepositorySystemSession session, InstallRequest request ) { this( session, request.getMetadata() ); @@ -57,6 +61,7 @@ private VersionsMetadataGenerator( RepositorySystemSession session, Collection(); processedVersions = new LinkedHashMap<>(); + timestamp = (Date) ConfigUtils.getObject( session, new Date(), "maven.startTime" ); /* * NOTE: This should be considered a quirk to support interop with Maven's legacy ArtifactDeployer which @@ -96,7 +101,7 @@ public Collection finish( Collection art VersionsMetadata versionsMetadata = versions.get( key ); if ( versionsMetadata == null ) { - versionsMetadata = new VersionsMetadata( artifact ); + versionsMetadata = new VersionsMetadata( artifact, timestamp ); versions.put( key, versionsMetadata ); } } diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java index 278231f9f60e..c319348c8082 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataTest.java @@ -66,7 +66,7 @@ public void gregorianCalendarIsUsed() String dateBefore = gregorianDate(); RemoteSnapshotMetadata metadata = new RemoteSnapshotMetadata( - new DefaultArtifact( "a:b:1-SNAPSHOT" ), false); + new DefaultArtifact( "a:b:1-SNAPSHOT" ), false, new Date() ); metadata.merge( new Metadata() ); String dateAfter = gregorianDate(); From 176b272f30c4fbd62013b4702ab28518c21628ac Mon Sep 17 00:00:00 2001 From: Nils Breunese Date: Tue, 13 Jul 2021 20:36:38 +0200 Subject: [PATCH 062/188] [MNG-7185] Describe explicit and recommended version for VersionRange.createFromVersionSpec() This closes #487 --- .../org/apache/maven/artifact/versioning/VersionRange.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java index bbc6523607b7..3689b2e7abcb 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java @@ -91,7 +91,8 @@ public VersionRange cloneOf() *

* Some spec examples are: *
    - *
  • 1.0 Version 1.0
  • + *
  • 1.0 Version 1.0 as a recommended version
  • + *
  • [1.0] Version 1.0 explicitly only
  • *
  • [1.0,2.0) Versions 1.0 (included) to 2.0 (not included)
  • *
  • [1.0,2.0] Versions 1.0 to 2.0 (both included)
  • *
  • [1.5,) Versions 1.5 and higher
  • From 268f9565746175f5900670e372092e0c071d85bd Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Mon, 19 Jul 2021 23:45:50 +0200 Subject: [PATCH 063/188] Use proper term: directory --- apache-maven/src/bin/mvn.cmd | 2 +- .../projects/project-builder/it0063/jdk/jre/placeholder.txt | 2 +- .../it0063/jdk/jre/placeholder.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apache-maven/src/bin/mvn.cmd b/apache-maven/src/bin/mvn.cmd index b8367f61e3e3..d8f26265f8c8 100644 --- a/apache-maven/src/bin/mvn.cmd +++ b/apache-maven/src/bin/mvn.cmd @@ -74,7 +74,7 @@ goto error set MAVEN_CMD_LINE_ARGS=%* -@REM Find the project basedir, i.e., the directory that contains the folder ".mvn". +@REM Find the project basedir, i.e., the directory that contains the directory ".mvn". @REM Fallback to current working directory if not found. set "MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%" diff --git a/maven-core/src/test/projects/project-builder/it0063/jdk/jre/placeholder.txt b/maven-core/src/test/projects/project-builder/it0063/jdk/jre/placeholder.txt index e26e86087ce3..4a9eb145a1e3 100644 --- a/maven-core/src/test/projects/project-builder/it0063/jdk/jre/placeholder.txt +++ b/maven-core/src/test/projects/project-builder/it0063/jdk/jre/placeholder.txt @@ -1 +1 @@ -need it so that empty folder does not get deleted \ No newline at end of file +need it so that empty directory does not get deleted diff --git a/maven-core/src/test/projects/project-dependencies-resolver/it0063/jdk/jre/placeholder.txt b/maven-core/src/test/projects/project-dependencies-resolver/it0063/jdk/jre/placeholder.txt index e26e86087ce3..4a9eb145a1e3 100644 --- a/maven-core/src/test/projects/project-dependencies-resolver/it0063/jdk/jre/placeholder.txt +++ b/maven-core/src/test/projects/project-dependencies-resolver/it0063/jdk/jre/placeholder.txt @@ -1 +1 @@ -need it so that empty folder does not get deleted \ No newline at end of file +need it so that empty directory does not get deleted From 25df095829bff8a1744db7dbf1ddd14aa1f8d43f Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Mon, 19 Jul 2021 23:56:22 +0200 Subject: [PATCH 064/188] [MNG-7190] Load mavenrc from /usr/local/etc also in Bourne shell script --- apache-maven/src/bin/mvn | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn index 1d429303a6b1..cc2cdacba096 100755 --- a/apache-maven/src/bin/mvn +++ b/apache-maven/src/bin/mvn @@ -29,6 +29,10 @@ if [ -z "$MAVEN_SKIP_RC" ] ; then + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + if [ -f /etc/mavenrc ] ; then . /etc/mavenrc fi From c395ca976dc9eaed65dcdc0037508d1edbfb57f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Tue, 20 Jul 2021 22:41:03 +0200 Subject: [PATCH 065/188] [MNG-7190] add /usr/local/etc/mavenrc to reference documentation --- apache-maven/src/site/apt/index.apt.vm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apache-maven/src/site/apt/index.apt.vm b/apache-maven/src/site/apt/index.apt.vm index 994aeab1d9eb..1d802661d98f 100644 --- a/apache-maven/src/site/apt/index.apt.vm +++ b/apache-maven/src/site/apt/index.apt.vm @@ -31,9 +31,9 @@ ${project.name} * <<>> invocation can be customised through: - * <<>> and <<<~/.mavenrc>>> scripts on Unix, + * <<>> (since 3.8.2), <<>> and <<<$HOME/.mavenrc>>> scripts on Unix, - * <<<~\mavenrc_pre.bat>>> and <<<~\mavenrc_pre.cmd>>> scripts on Windows, + * <<<%USERPROFILE%\\mavenrc_pre.bat>>> and <<<%USERPROFILE%\\mavenrc_pre.cmd>>> scripts on Windows, [] From b74199ed446c83282ad806afaf962a7f74eac0ea Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 25 Nov 2020 20:12:04 +0100 Subject: [PATCH 066/188] [MNG-7034] StackOverflowError thrown if a cycle exists in BOM imports This closes #484 --- .../model/building/DefaultModelBuilder.java | 11 +- .../building/DefaultModelBuilderTest.java | 153 ++++++++++++++++++ 2 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index a8568efb2753..a089f9d991df 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -248,6 +248,13 @@ public DefaultModelBuilder setReportingConverter( ReportingConverter reportingCo @Override public ModelBuildingResult build( ModelBuildingRequest request ) throws ModelBuildingException + { + return build( request, new LinkedHashSet() ); + } + + @SuppressWarnings( "checkstyle:methodlength" ) + protected ModelBuildingResult build( ModelBuildingRequest request, Collection importIds ) + throws ModelBuildingException { // phase 1 DefaultModelBuildingResult result = new DefaultModelBuildingResult(); @@ -427,7 +434,7 @@ else if ( !parentIds.add( parentData.getId() ) ) if ( !request.isTwoPhaseBuilding() ) { - build( request, result ); + build( request, result, importIds ); } return result; @@ -1303,7 +1310,7 @@ private void importDependencyManagement( Model model, ModelBuildingRequest reque final ModelBuildingResult importResult; try { - importResult = build( importRequest ); + importResult = build( importRequest, importIds ); } catch ( ModelBuildingException e ) { diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java new file mode 100644 index 000000000000..4e7919a6c2ed --- /dev/null +++ b/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java @@ -0,0 +1,153 @@ +package org.apache.maven.model.building; + + /* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Parent; +import org.apache.maven.model.Repository; +import org.apache.maven.model.resolution.InvalidRepositoryException; +import org.apache.maven.model.resolution.ModelResolver; +import org.apache.maven.model.resolution.UnresolvableModelException; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Guillaume Nodet + */ +public class DefaultModelBuilderTest +{ + + private static final String BASE1_ID = "thegroup:base1:pom"; + private static final String BASE1_ID2 = "thegroup:base1:1"; + + private static final String BASE1 = "\n" + + " 4.0.0\n" + + " thegroup\n" + + " base1\n" + + " 1\n" + + " pom\n" + + " \n" + + " \n" + + " \n" + + " thegroup\n" + + " base2\n" + + " 1\n" + + " pom\n" + + " import\n" + + " \n" + + " \n" + + " \n" + + "\n"; + + private static final String BASE2_ID = "thegroup:base2:pom"; + private static final String BASE2_ID2 = "thegroup:base2:1"; + + private static final String BASE2 = "\n" + + " 4.0.0\n" + + " thegroup\n" + + " base2\n" + + " 1\n" + + " pom\n" + + " \n" + + " \n" + + " \n" + + " thegroup\n" + + " base1\n" + + " 1\n" + + " pom\n" + + " import\n" + + " \n" + + " \n" + + " \n" + + "\n"; + + @Test( expected = ModelBuildingException.class ) + public void testCycleInImports() + throws Exception + { + ModelBuilder builder = new DefaultModelBuilderFactory().newInstance(); + assertNotNull( builder ); + + DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); + request.setModelSource( new StringModelSource( BASE1 ) ); + request.setModelResolver( new CycleInImportsResolver() ); + + builder.build( request ); + } + + static class CycleInImportsResolver extends BaseModelResolver + { + @Override + public ModelSource resolveModel(Dependency dependency) throws UnresolvableModelException + { + switch ( dependency.getManagementKey() ) + { + case BASE1_ID: return new StringModelSource( BASE1 ); + case BASE2_ID: return new StringModelSource( BASE2 ); + } + return null; + } + } + + static class BaseModelResolver implements ModelResolver + { + @Override + public ModelSource resolveModel( String groupId, String artifactId, String version ) + throws UnresolvableModelException + { + switch ( groupId + ":" + artifactId + ":" + version ) + { + case BASE1_ID2: return new StringModelSource( BASE1 ); + case BASE2_ID2: return new StringModelSource( BASE2 ); + } + return null; + } + + @Override + public ModelSource resolveModel( Parent parent ) throws UnresolvableModelException + { + return null; + } + + @Override + public ModelSource resolveModel( Dependency dependency ) throws UnresolvableModelException + { + return null; + } + + @Override + public void addRepository( Repository repository ) throws InvalidRepositoryException + { + } + + @Override + public void addRepository(Repository repository, boolean replace) throws InvalidRepositoryException + { + } + + @Override + public ModelResolver newCopy() + { + return this; + } + } + +} From 22a8cfa05976b23284388675dcabd7e5e8037fb0 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Thu, 22 Jul 2021 21:07:03 +0200 Subject: [PATCH 067/188] [MNG-6648] 'mavenrc_pre' script does not receive arguments like mavenrc in Bourne shell does This closes #511 --- apache-maven/src/bin/mvn.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apache-maven/src/bin/mvn.cmd b/apache-maven/src/bin/mvn.cmd index d8f26265f8c8..0faa39f81de8 100644 --- a/apache-maven/src/bin/mvn.cmd +++ b/apache-maven/src/bin/mvn.cmd @@ -35,8 +35,8 @@ @REM Execute a user defined script before this one if not "%MAVEN_SKIP_RC%"=="" goto skipRcPre @REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* :skipRcPre @setlocal From f32eb09892686cba083f9f175b3c8eac0ac42ae7 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Fri, 23 Jul 2021 22:45:34 +0200 Subject: [PATCH 068/188] [MNG-7010] Omit "NB: JAVA_HOME should point to a JDK not a JRE" This closes #512 --- apache-maven/src/bin/mvn | 5 ++--- apache-maven/src/bin/mvn.cmd | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn index cc2cdacba096..29e0eabb837c 100755 --- a/apache-maven/src/bin/mvn +++ b/apache-maven/src/bin/mvn @@ -100,9 +100,8 @@ else fi if [ ! -x "$JAVACMD" ] ; then - echo "The JAVA_HOME environment variable is not defined correctly" >&2 - echo "This environment variable is needed to run this program" >&2 - echo "NB: JAVA_HOME should point to a JDK not a JRE" >&2 + echo "The JAVA_HOME environment variable is not defined correctly," >&2 + echo "this environment variable is needed to run this program." >&2 exit 1 fi diff --git a/apache-maven/src/bin/mvn.cmd b/apache-maven/src/bin/mvn.cmd index 0faa39f81de8..fcb0f455a804 100644 --- a/apache-maven/src/bin/mvn.cmd +++ b/apache-maven/src/bin/mvn.cmd @@ -54,9 +54,8 @@ set "JAVACMD=%JAVA_HOME%\bin\java.exe" :checkJCmd if exist "%JAVACMD%" goto chkMHome -echo The JAVA_HOME environment variable is not defined correctly >&2 -echo This environment variable is needed to run this program >&2 -echo NB: JAVA_HOME should point to a JDK not a JRE >&2 +echo The JAVA_HOME environment variable is not defined correctly, >&2 +echo this environment variable is needed to run this program. >&2 goto error :chkMHome From 51f6d8b8525d8bf218f70100ec99a7ae97097923 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sun, 25 Jul 2021 14:32:31 +0200 Subject: [PATCH 069/188] [MNG-7196] Upgrade Jansi to 2.3.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dbe5eb2de604..750e63b1eeb8 100644 --- a/pom.xml +++ b/pom.xml @@ -294,7 +294,7 @@ under the License. org.fusesource.jansi jansi - 2.3.3 + 2.3.4 org.slf4j From 7ecdb3c970d71de3e48fe4de691388868ac03630 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Tue, 27 Jul 2021 14:58:11 +0200 Subject: [PATCH 070/188] [MNG-7198] Upgrade SLF4J to 1.7.32 --- .../{MIT-slf4j-api-1.7.30.txt => MIT-slf4j-api-1.7.32.txt} | 0 pom.xml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename apache-maven/src/main/appended-resources/licenses/{MIT-slf4j-api-1.7.30.txt => MIT-slf4j-api-1.7.32.txt} (100%) diff --git a/apache-maven/src/main/appended-resources/licenses/MIT-slf4j-api-1.7.30.txt b/apache-maven/src/main/appended-resources/licenses/MIT-slf4j-api-1.7.32.txt similarity index 100% rename from apache-maven/src/main/appended-resources/licenses/MIT-slf4j-api-1.7.30.txt rename to apache-maven/src/main/appended-resources/licenses/MIT-slf4j-api-1.7.32.txt diff --git a/pom.xml b/pom.xml index 750e63b1eeb8..318141ea1899 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ under the License. 1.11 1.3 1.6.3 - 1.7.30 + 1.7.32 2.2.1 1.7.4 true From ea98e05a04480131370aa0c110b8c54cf726c06f Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Wed, 4 Aug 2021 21:03:30 +0200 Subject: [PATCH 071/188] [maven-release-plugin] prepare release maven-3.8.2 --- apache-maven/pom.xml | 2 +- maven-artifact/pom.xml | 2 +- maven-builder-support/pom.xml | 2 +- maven-compat/pom.xml | 2 +- maven-core/pom.xml | 2 +- maven-embedder/pom.xml | 2 +- maven-model-builder/pom.xml | 2 +- maven-model/pom.xml | 2 +- maven-plugin-api/pom.xml | 2 +- maven-repository-metadata/pom.xml | 2 +- maven-resolver-provider/pom.xml | 2 +- maven-settings-builder/pom.xml | 2 +- maven-settings/pom.xml | 2 +- maven-slf4j-provider/pom.xml | 2 +- pom.xml | 6 +++--- 15 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index 6e267ad5e25a..42491b3feb84 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 apache-maven diff --git a/maven-artifact/pom.xml b/maven-artifact/pom.xml index 6b2aabfeebe7..d085c96530d2 100644 --- a/maven-artifact/pom.xml +++ b/maven-artifact/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-artifact diff --git a/maven-builder-support/pom.xml b/maven-builder-support/pom.xml index ed0df18ec467..af3608dbb1a5 100644 --- a/maven-builder-support/pom.xml +++ b/maven-builder-support/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-builder-support diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index 55f4f2575342..161764395933 100644 --- a/maven-compat/pom.xml +++ b/maven-compat/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-compat diff --git a/maven-core/pom.xml b/maven-core/pom.xml index dc5a422e202a..7c7b722310ce 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-core diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 2edf4171d63b..637a408cf40b 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-embedder diff --git a/maven-model-builder/pom.xml b/maven-model-builder/pom.xml index a383fefe3e4f..1365b6b64026 100644 --- a/maven-model-builder/pom.xml +++ b/maven-model-builder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-model-builder diff --git a/maven-model/pom.xml b/maven-model/pom.xml index cd9a63940231..c99d8e337fe2 100644 --- a/maven-model/pom.xml +++ b/maven-model/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-model diff --git a/maven-plugin-api/pom.xml b/maven-plugin-api/pom.xml index 3d93184524ee..8ac3cfbb5037 100644 --- a/maven-plugin-api/pom.xml +++ b/maven-plugin-api/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-plugin-api diff --git a/maven-repository-metadata/pom.xml b/maven-repository-metadata/pom.xml index b1ec1e540fb1..486e26e04be5 100644 --- a/maven-repository-metadata/pom.xml +++ b/maven-repository-metadata/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-repository-metadata diff --git a/maven-resolver-provider/pom.xml b/maven-resolver-provider/pom.xml index 355a4ebab0c4..d4a1c61363e9 100644 --- a/maven-resolver-provider/pom.xml +++ b/maven-resolver-provider/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-resolver-provider diff --git a/maven-settings-builder/pom.xml b/maven-settings-builder/pom.xml index ee196b75d804..055eb0dbb485 100644 --- a/maven-settings-builder/pom.xml +++ b/maven-settings-builder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-settings-builder diff --git a/maven-settings/pom.xml b/maven-settings/pom.xml index bdc4c0f435bf..606550eea8fa 100644 --- a/maven-settings/pom.xml +++ b/maven-settings/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-settings diff --git a/maven-slf4j-provider/pom.xml b/maven-slf4j-provider/pom.xml index b896f9548acd..b4280ce7a460 100644 --- a/maven-slf4j-provider/pom.xml +++ b/maven-slf4j-provider/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2-SNAPSHOT + 3.8.2 maven-slf4j-provider diff --git a/pom.xml b/pom.xml index 318141ea1899..1875b9f65b72 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ under the License. maven - 3.8.2-SNAPSHOT + 3.8.2 pom Apache Maven @@ -77,7 +77,7 @@ under the License. ref/3-LATEST None **/package-info.java - 2019-11-07T12:32:18Z + 2021-08-04T18:57:55Z @@ -101,7 +101,7 @@ under the License. scm:git:https://gitbox.apache.org/repos/asf/maven.git scm:git:https://gitbox.apache.org/repos/asf/maven.git https://github.com/apache/maven/tree/${project.scm.tag} - maven-3.8.x + maven-3.8.2 jira From 865dcaa6fffc8fbc679f190280e1f0f7b1d783b5 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Wed, 4 Aug 2021 21:03:42 +0200 Subject: [PATCH 072/188] [maven-release-plugin] prepare for next development iteration --- apache-maven/pom.xml | 2 +- maven-artifact/pom.xml | 2 +- maven-builder-support/pom.xml | 2 +- maven-compat/pom.xml | 2 +- maven-core/pom.xml | 2 +- maven-embedder/pom.xml | 2 +- maven-model-builder/pom.xml | 2 +- maven-model/pom.xml | 2 +- maven-plugin-api/pom.xml | 2 +- maven-repository-metadata/pom.xml | 2 +- maven-resolver-provider/pom.xml | 2 +- maven-settings-builder/pom.xml | 2 +- maven-settings/pom.xml | 2 +- maven-slf4j-provider/pom.xml | 2 +- pom.xml | 4 ++-- 15 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index 42491b3feb84..2cc6ca31d533 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT apache-maven diff --git a/maven-artifact/pom.xml b/maven-artifact/pom.xml index d085c96530d2..5203f1b79592 100644 --- a/maven-artifact/pom.xml +++ b/maven-artifact/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-artifact diff --git a/maven-builder-support/pom.xml b/maven-builder-support/pom.xml index af3608dbb1a5..191bfc5967d0 100644 --- a/maven-builder-support/pom.xml +++ b/maven-builder-support/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-builder-support diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index 161764395933..06686b980a5d 100644 --- a/maven-compat/pom.xml +++ b/maven-compat/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-compat diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 7c7b722310ce..60b958f1f6fb 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-core diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 637a408cf40b..e0b647902053 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-embedder diff --git a/maven-model-builder/pom.xml b/maven-model-builder/pom.xml index 1365b6b64026..06d42d38e31b 100644 --- a/maven-model-builder/pom.xml +++ b/maven-model-builder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-model-builder diff --git a/maven-model/pom.xml b/maven-model/pom.xml index c99d8e337fe2..0e002c0c2f5e 100644 --- a/maven-model/pom.xml +++ b/maven-model/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-model diff --git a/maven-plugin-api/pom.xml b/maven-plugin-api/pom.xml index 8ac3cfbb5037..a0a708926b69 100644 --- a/maven-plugin-api/pom.xml +++ b/maven-plugin-api/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-plugin-api diff --git a/maven-repository-metadata/pom.xml b/maven-repository-metadata/pom.xml index 486e26e04be5..b4ac0f489b00 100644 --- a/maven-repository-metadata/pom.xml +++ b/maven-repository-metadata/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-repository-metadata diff --git a/maven-resolver-provider/pom.xml b/maven-resolver-provider/pom.xml index d4a1c61363e9..70e0f4e5bc35 100644 --- a/maven-resolver-provider/pom.xml +++ b/maven-resolver-provider/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-resolver-provider diff --git a/maven-settings-builder/pom.xml b/maven-settings-builder/pom.xml index 055eb0dbb485..a85c8a8c1191 100644 --- a/maven-settings-builder/pom.xml +++ b/maven-settings-builder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-settings-builder diff --git a/maven-settings/pom.xml b/maven-settings/pom.xml index 606550eea8fa..6fa967c38ca3 100644 --- a/maven-settings/pom.xml +++ b/maven-settings/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-settings diff --git a/maven-slf4j-provider/pom.xml b/maven-slf4j-provider/pom.xml index b4280ce7a460..802d226c9c0a 100644 --- a/maven-slf4j-provider/pom.xml +++ b/maven-slf4j-provider/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.2 + 3.8.3-SNAPSHOT maven-slf4j-provider diff --git a/pom.xml b/pom.xml index 1875b9f65b72..05b80b2db065 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ under the License. maven - 3.8.2 + 3.8.3-SNAPSHOT pom Apache Maven @@ -77,7 +77,7 @@ under the License. ref/3-LATEST None **/package-info.java - 2021-08-04T18:57:55Z + 2021-08-04T19:03:41Z From 9adb3aedf21ca9a49560957e0e1b9125266bb401 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Fri, 13 Aug 2021 21:59:19 +0200 Subject: [PATCH 073/188] Document Maven 3.8.1 and 3.8.2 releases --- doap_Maven.rdf | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doap_Maven.rdf b/doap_Maven.rdf index 45b4e4bef3e4..0417fff803ea 100644 --- a/doap_Maven.rdf +++ b/doap_Maven.rdf @@ -33,6 +33,24 @@ under the License. Latest stable release + 2021-08-04 + 3.8.2 + http://archive.apache.org/dist/maven/maven-3/3.8.2/binaries/apache-maven-3.8.2-bin.zip + http://archive.apache.org/dist/maven/maven-3/3.8.2/binaries/apache-maven-3.8.2-bin.tar.gz + http://archive.apache.org/dist/maven/maven-3/3.8.2/source/apache-maven-3.8.2-src.zip + http://archive.apache.org/dist/maven/maven-3/3.8.2/source/apache-maven-3.8.2-src.tar.gz + + + Latest stable release + 2021-04-04 + 3.8.1 + http://archive.apache.org/dist/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.zip + http://archive.apache.org/dist/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz + http://archive.apache.org/dist/maven/maven-3/3.8.1/source/apache-maven-3.8.1-src.zip + http://archive.apache.org/dist/maven/maven-3/3.8.1/source/apache-maven-3.8.1-src.tar.gz + + + Apache Maven 3.6.2 2019-08-27 3.6.2 http://archive.apache.org/dist/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.zip From 4dc115967a9ac1522fe01d33de1a3279d52a559a Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sat, 14 Aug 2021 10:27:09 +0200 Subject: [PATCH 074/188] Fix DOAP --- doap_Maven.rdf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doap_Maven.rdf b/doap_Maven.rdf index 0417fff803ea..531df1217a61 100644 --- a/doap_Maven.rdf +++ b/doap_Maven.rdf @@ -41,7 +41,7 @@ under the License. http://archive.apache.org/dist/maven/maven-3/3.8.2/source/apache-maven-3.8.2-src.tar.gz - Latest stable release + Apache Maven 3.8.1 2021-04-04 3.8.1 http://archive.apache.org/dist/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.zip From 547dfddb2ef02f44d9f2d0730348eaedfcd2e126 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Wed, 22 Jan 2020 09:25:24 +0100 Subject: [PATCH 075/188] Improve license handling * Stream line the output of the license listing * Exclude jsoup from final distribution since we only need its license information * Use proper SPDX ID for our license This closes #317 --- apache-maven/pom.xml | 6 +++--- .../appended-resources/META-INF/LICENSE.vm | 19 +++++++++++-------- .../licenses/{ASL-2.0.txt => Apache-2.0.txt} | 0 apache-maven/src/main/assembly/component.xml | 1 + 4 files changed, 15 insertions(+), 11 deletions(-) rename apache-maven/src/main/appended-resources/licenses/{ASL-2.0.txt => Apache-2.0.txt} (100%) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index 2cc6ca31d533..a4cf0396c61b 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -79,10 +79,10 @@ under the License. + - org.jsoup jsoup runtime diff --git a/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm b/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm index 25ac46f3770f..43357d142ef0 100644 --- a/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm +++ b/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm @@ -18,21 +18,21 @@ ## -Apache Maven includes a number of components and libraries with separate -copyright notices and license terms. Your use of those components are -subject to the terms and conditions of the following licenses: +Apache Maven includes a number of components and libraries with separate +copyright notices and license terms. Your use of those components are +subject to the terms and conditions of the following licenses: ## #set ( $apacheMavenGroupIds = [ "org.apache.maven", "org.apache.maven.wagon", "org.apache.maven.resolver", "org.apache.maven.shared" ] ) #set ( $MITLicenseNames = [ "MIT License", "MIT license", "The MIT License" ] ) #foreach ( $project in $projects ) -#**##foreach ( $license in $project.licenses) +#**##foreach ( $license in $project.licenses ) #* *##set ( $groupId = $project.artifact.groupId ) #* *##set ( $directory = 'lib' ) #* *##if ( !$apacheMavenGroupIds.contains( $groupId ) ) #* *### advertise about each non-Maven dependency #* *### -#* *### infer SPDX license code +#* *### infer SPDX license id #* *##if ( $license.name == "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" ) #* *##set ( $spdx = 'CDDL-1.0' ) #* *##elseif ( $MITLicenseNames.contains( $license.name ) ) @@ -40,7 +40,7 @@ subject to the terms and conditions of the following licenses: #* *##elseif ( $license.name == "Eclipse Public License, Version 1.0" ) #* *##set ( $spdx = 'EPL-1.0' ) #* *##elseif ( $license.url.contains( "www.apache.org/licenses/LICENSE-2.0" ) ) -#* *##set ( $spdx = 'ASL-2.0' ) +#* *##set ( $spdx = 'Apache-2.0' ) #* *##else #* *### unrecognized license will require analysis to know obligations #* *##set ( $spdx = 'unrecognized' ) @@ -68,13 +68,16 @@ subject to the terms and conditions of the following licenses: #* *##else #* *##set ( $downloaded = $locator.getResourceAsFile( "licenses/${spdx}.txt", "licenses/${licFile}" ) ) #* *##end + #* *### add dependency info to output - $directory/${project.artifact.artifactId}-${project.artifact.version}.jar: $project.artifact.toString().replace( ':eclipse-plugin:', ':jar:' ) - $project.name + Project: $project.name #if ( $project.url )Project URL: ${project.url}#end - License: $license.name#if ( $spdx ) ($spdx)#end $license.url ($licFile) + License: $license.name#if ( $spdx ) ($spdx)#end + + License URL: $license.url ($licFile) #* *##end #**##end diff --git a/apache-maven/src/main/appended-resources/licenses/ASL-2.0.txt b/apache-maven/src/main/appended-resources/licenses/Apache-2.0.txt similarity index 100% rename from apache-maven/src/main/appended-resources/licenses/ASL-2.0.txt rename to apache-maven/src/main/appended-resources/licenses/Apache-2.0.txt diff --git a/apache-maven/src/main/assembly/component.xml b/apache-maven/src/main/assembly/component.xml index 4f9ff1662854..657d06bf026b 100644 --- a/apache-maven/src/main/assembly/component.xml +++ b/apache-maven/src/main/assembly/component.xml @@ -31,6 +31,7 @@ under the License. lib org.codehaus.plexus:plexus-classworlds + org.jsoup:jsoup From 0c3fe074bbd3272a7b46c28683c6ed50d0daede7 Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Mon, 9 Dec 2019 19:43:44 +0100 Subject: [PATCH 076/188] [MNG-6818] - Upgrade plexus-utils 3.3.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 05b80b2db065..82128161c01c 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ under the License. 2.21.0 2.1.0 1.25 - 3.2.1 + 3.3.0 4.2.2 0.3.4 3.4.3 From ccafe8bf46ad874ca0cfba6ea5961b34f1630f82 Mon Sep 17 00:00:00 2001 From: "artem.krosheninnikov" Date: Sun, 5 Jan 2020 22:24:21 +0300 Subject: [PATCH 077/188] [MNG-6841] update plexus-interpolation to 1.26 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 82128161c01c..4a4f69ba3f0a 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ under the License. 4.12 2.21.0 2.1.0 - 1.25 + 1.26 3.3.0 4.2.2 0.3.4 From c76c9d9116b4626c20abe26c025623797249f997 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 10 Sep 2021 14:33:45 +0200 Subject: [PATCH 078/188] [MNG-7246] Upgrade Plexus Cipher and Sec Dispatcher to 2.0 Both plexus-cipher and plexus-sec-dispatcher have had a groupId change, but plexus-cipher change was implemented for 1.8 version. Latest versions of artifacts are 2.0. This PR ups plexus-cipher version and adds proper changes for plexus-sec-dispatcher groupId change. This closes #534 --- .../project-with-inheritance/pom.xml | 2 +- .../project-with-inheritance/pom.xml | 2 +- .../org/apache/maven/lifecycle/pom.xml | 2 +- maven-embedder/pom.xml | 2 +- maven-settings-builder/pom.xml | 2 +- pom.xml | 17 ++++++----------- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/maven-core/src/test/projects/lifecycle-executor/project-with-inheritance/pom.xml b/maven-core/src/test/projects/lifecycle-executor/project-with-inheritance/pom.xml index c9a894d9059b..7d0850e48382 100644 --- a/maven-core/src/test/projects/lifecycle-executor/project-with-inheritance/pom.xml +++ b/maven-core/src/test/projects/lifecycle-executor/project-with-inheritance/pom.xml @@ -473,7 +473,7 @@ under the License. ${mercuryMp3Version} - org.sonatype.plexus + org.codehaus.plexus plexus-sec-dispatcher ${securityDispatcherVersion} diff --git a/maven-core/src/test/projects/plugin-manager/project-with-inheritance/pom.xml b/maven-core/src/test/projects/plugin-manager/project-with-inheritance/pom.xml index c9a894d9059b..7d0850e48382 100644 --- a/maven-core/src/test/projects/plugin-manager/project-with-inheritance/pom.xml +++ b/maven-core/src/test/projects/plugin-manager/project-with-inheritance/pom.xml @@ -473,7 +473,7 @@ under the License. ${mercuryMp3Version} - org.sonatype.plexus + org.codehaus.plexus plexus-sec-dispatcher ${securityDispatcherVersion} diff --git a/maven-core/src/test/resources/org/apache/maven/lifecycle/pom.xml b/maven-core/src/test/resources/org/apache/maven/lifecycle/pom.xml index 531e5510c5a7..5caaac1ba285 100644 --- a/maven-core/src/test/resources/org/apache/maven/lifecycle/pom.xml +++ b/maven-core/src/test/resources/org/apache/maven/lifecycle/pom.xml @@ -473,7 +473,7 @@ under the License. ${mercuryMp3Version} - org.sonatype.plexus + org.codehaus.plexus plexus-sec-dispatcher ${securityDispatcherVersion} diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index e0b647902053..fc90bbc13493 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -131,7 +131,7 @@ under the License. org.eclipse.sisu.plexus - org.sonatype.plexus + org.codehaus.plexus plexus-sec-dispatcher diff --git a/maven-settings-builder/pom.xml b/maven-settings-builder/pom.xml index a85c8a8c1191..dd0c09bb9ce8 100644 --- a/maven-settings-builder/pom.xml +++ b/maven-settings-builder/pom.xml @@ -62,7 +62,7 @@ under the License. maven-settings - org.sonatype.plexus + org.codehaus.plexus plexus-sec-dispatcher diff --git a/pom.xml b/pom.xml index 4a4f69ba3f0a..40a7ee81ade0 100644 --- a/pom.xml +++ b/pom.xml @@ -61,8 +61,8 @@ under the License. 0.3.4 3.4.3 1.12.1 - 1.4 - 1.8 + 2.0 + 2.0 1.11 1.3 1.6.3 @@ -402,15 +402,9 @@ under the License. ${commonsLangVersion} - org.sonatype.plexus + org.codehaus.plexus plexus-sec-dispatcher ${securityDispatcherVersion} - - - org.sonatype.plexus - plexus-cipher - - org.codehaus.plexus @@ -641,15 +635,16 @@ under the License. enforce validate - ensure-no-org.sonatype:plexus-cipher + ensure-no-sonatype-cipher-and-sec-dispatcher + org.sonatype.plexus:plexus-sec-dispatcher org.sonatype.plexus:plexus-cipher - ensure no more org.sonatype.plexus:plexus-cipher as groupId changed. you have to add some exclusions. + ensure no more org.sonatype.plexus:plexus-cipher and org.sonatype.plexus:plexus-sec-dispatcher. From 383cabf9e4992eeff36c9b5731d95bafa72398d3 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Mon, 16 Aug 2021 18:08:39 +0200 Subject: [PATCH 079/188] [MNG-7216] [Regression] Revert MNG-7170 This reverts commit 5a8997312680a4b9c69a129801524691bc546c08. This closes #524 --- .../maven/project/ProjectBuilderTest.java | 26 ------------------- .../projects/modelsourcebasedir/pom.xml | 19 -------------- .../model/building/DefaultModelBuilder.java | 9 +------ 3 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 maven-core/src/test/resources/projects/modelsourcebasedir/pom.xml diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java index 37d51cd49d00..6adb10e8f4e2 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java @@ -39,8 +39,6 @@ import org.apache.maven.model.Plugin; import org.apache.maven.model.building.FileModelSource; import org.apache.maven.model.building.ModelBuildingRequest; -import org.apache.maven.model.building.ModelProblem; -import org.apache.maven.model.building.ModelProblem.Severity; import org.apache.maven.model.building.ModelSource; import org.apache.maven.shared.utils.io.FileUtils; @@ -85,30 +83,6 @@ public void testBuildFromModelSource() assertNotNull( result.getProject().getParentFile() ); } - public void testBuildFromModelSourceResolvesBasedir() - throws Exception - { - File pomFile = new File( "src/test/resources/projects/modelsourcebasedir/pom.xml" ); - MavenSession mavenSession = createMavenSession( null ); - ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest(); - configuration.setRepositorySession( mavenSession.getRepositorySession() ); - ModelSource modelSource = new FileModelSource( pomFile ); - ProjectBuildingResult result = - getContainer().lookup( org.apache.maven.project.ProjectBuilder.class ).build( modelSource, configuration ); - - assertEquals( pomFile.getAbsoluteFile(), result.getProject().getModel().getPomFile().getAbsoluteFile() ); - int errors = 0; - for ( ModelProblem p : result.getProblems() ) - { - if ( p.getSeverity() == Severity.ERROR ) - { - errors++; - } - } - assertEquals( 0, errors ); - } - - public void testVersionlessManagedDependency() throws Exception { diff --git a/maven-core/src/test/resources/projects/modelsourcebasedir/pom.xml b/maven-core/src/test/resources/projects/modelsourcebasedir/pom.xml deleted file mode 100644 index ec0f7d385a9b..000000000000 --- a/maven-core/src/test/resources/projects/modelsourcebasedir/pom.xml +++ /dev/null @@ -1,19 +0,0 @@ - - 4.0.0 - test.readparent - local-parent - pom - 1.0 - - - - blah - blah - 0.0.1-SNASPSHOT - system - ${basedir}/blah.jar - - - - diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index a089f9d991df..70c9ed529cd2 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -624,14 +624,7 @@ private Model readModel( ModelSource modelSource, File pomFile, ModelBuildingReq throw problems.newModelBuildingException(); } - if ( pomFile != null ) - { - model.setPomFile( pomFile ); - } - else if ( modelSource instanceof FileModelSource ) - { - model.setPomFile( ( (FileModelSource) modelSource ).getFile() ); - } + model.setPomFile( pomFile ); problems.setSource( model ); modelValidator.validateRawModel( model, request, problems ); From e08834b79e9387811ece442f6e7b445b19110fcf Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Mon, 13 Sep 2021 17:56:54 +0200 Subject: [PATCH 080/188] [MNG-7250] Upgrade Sisu Inject/Plexus to 0.3.5 Since we have replaced the old JSR 250 library with javax.annotation library we go straight to 1.2. This closes #539 --- .../appended-resources/META-INF/LICENSE.vm | 6 +- .../appended-resources/META-INF/NOTICE.vm | 2 +- .../appended-resources/licenses/CDDL-1.0.txt | 384 --------- .../unrecognized-javax.annotation-api-1.2.txt | 759 ++++++++++++++++++ .../resources/META-INF/maven/extension.xml | 2 +- maven-embedder/pom.xml | 2 +- pom.xml | 16 +- 7 files changed, 772 insertions(+), 399 deletions(-) delete mode 100644 apache-maven/src/main/appended-resources/licenses/CDDL-1.0.txt create mode 100644 apache-maven/src/main/appended-resources/licenses/unrecognized-javax.annotation-api-1.2.txt diff --git a/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm b/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm index 43357d142ef0..b589e36e0222 100644 --- a/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm +++ b/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm @@ -33,9 +33,7 @@ subject to the terms and conditions of the following licenses: #* *### advertise about each non-Maven dependency #* *### #* *### infer SPDX license id -#* *##if ( $license.name == "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" ) -#* *##set ( $spdx = 'CDDL-1.0' ) -#* *##elseif ( $MITLicenseNames.contains( $license.name ) ) +#* *##if ( $MITLicenseNames.contains( $license.name ) ) #* *##set ( $spdx = 'MIT' ) #* *##elseif ( $license.name == "Eclipse Public License, Version 1.0" ) #* *##set ( $spdx = 'EPL-1.0' ) @@ -62,7 +60,7 @@ subject to the terms and conditions of the following licenses: #* *### #* *### copy license file to lib/$artifactId.license #* *##set ( $licFile = $directory + '/' + $project.artifact.artifactId + '.license' ) -#* *##if ( $spdx == "MIT" ) +#* *##if ( $spdx == "MIT" || $spdx == "unrecognized" ) #* *### MIT license contains date and copyright that makes the file specific to each artifact #* *##set ( $downloaded = $locator.getResourceAsFile( "licenses/${spdx}-${project.artifact.artifactId}-${project.artifact.version}.txt", "licenses/${licFile}" ) ) #* *##else diff --git a/apache-maven/src/main/appended-resources/META-INF/NOTICE.vm b/apache-maven/src/main/appended-resources/META-INF/NOTICE.vm index acf7ba42e070..3cfd92583cd2 100644 --- a/apache-maven/src/main/appended-resources/META-INF/NOTICE.vm +++ b/apache-maven/src/main/appended-resources/META-INF/NOTICE.vm @@ -36,7 +36,7 @@ javolution (http://javolution.org/). This product includes software developed by Rome (https://rome.dev.java.net/). -about.html in archive lib/org.eclipse.sisu.inject-0.3.4.jar +about.html in archive lib/org.eclipse.sisu.inject-0.3.5.jar diff --git a/apache-maven/src/main/appended-resources/licenses/CDDL-1.0.txt b/apache-maven/src/main/appended-resources/licenses/CDDL-1.0.txt deleted file mode 100644 index 9bc6342e22c9..000000000000 --- a/apache-maven/src/main/appended-resources/licenses/CDDL-1.0.txt +++ /dev/null @@ -1,384 +0,0 @@ -COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 - - - 1. Definitions. - - 1.1. "Contributor" means each individual or entity that - creates or contributes to the creation of Modifications. - - 1.2. "Contributor Version" means the combination of the - Original Software, prior Modifications used by a - Contributor (if any), and the Modifications made by that - particular Contributor. - - 1.3. "Covered Software" means (a) the Original Software, or - (b) Modifications, or (c) the combination of files - containing Original Software with files containing - Modifications, in each case including portions thereof. - - 1.4. "Executable" means the Covered Software in any form - other than Source Code. - - 1.5. "Initial Developer" means the individual or entity - that first makes Original Software available under this - License. - - 1.6. "Larger Work" means a work which combines Covered - Software or portions thereof with code not governed by the - terms of this License. - - 1.7. "License" means this document. - - 1.8. "Licensable" means having the right to grant, to the - maximum extent possible, whether at the time of the initial - grant or subsequently acquired, any and all of the rights - conveyed herein. - - 1.9. "Modifications" means the Source Code and Executable - form of any of the following: - - A. Any file that results from an addition to, - deletion from or modification of the contents of a - file containing Original Software or previous - Modifications; - - B. Any new file that contains any part of the - Original Software or previous Modification; or - - C. Any new file that is contributed or otherwise made - available under the terms of this License. - - 1.10. "Original Software" means the Source Code and - Executable form of computer software code that is - originally released under this License. - - 1.11. "Patent Claims" means any patent claim(s), now owned - or hereafter acquired, including without limitation, - method, process, and apparatus claims, in any patent - Licensable by grantor. - - 1.12. "Source Code" means (a) the common form of computer - software code in which modifications are made and (b) - associated documentation included in or with such code. - - 1.13. "You" (or "Your") means an individual or a legal - entity exercising rights under, and complying with all of - the terms of, this License. For legal entities, "You" - includes any entity which controls, is controlled by, or is - under common control with You. For purposes of this - definition, "control" means (a) the power, direct or - indirect, to cause the direction or management of such - entity, whether by contract or otherwise, or (b) ownership - of more than fifty percent (50%) of the outstanding shares - or beneficial ownership of such entity. - - 2. License Grants. - - 2.1. The Initial Developer Grant. - - Conditioned upon Your compliance with Section 3.1 below and - subject to third party intellectual property claims, the - Initial Developer hereby grants You a world-wide, - royalty-free, non-exclusive license: - - (a) under intellectual property rights (other than - patent or trademark) Licensable by Initial Developer, - to use, reproduce, modify, display, perform, - sublicense and distribute the Original Software (or - portions thereof), with or without Modifications, - and/or as part of a Larger Work; and - - (b) under Patent Claims infringed by the making, - using or selling of Original Software, to make, have - made, use, practice, sell, and offer for sale, and/or - otherwise dispose of the Original Software (or - portions thereof). - - (c) The licenses granted in Sections 2.1(a) and (b) - are effective on the date Initial Developer first - distributes or otherwise makes the Original Software - available to a third party under the terms of this - License. - - (d) Notwithstanding Section 2.1(b) above, no patent - license is granted: (1) for code that You delete from - the Original Software, or (2) for infringements - caused by: (i) the modification of the Original - Software, or (ii) the combination of the Original - Software with other software or devices. - - 2.2. Contributor Grant. - - Conditioned upon Your compliance with Section 3.1 below and - subject to third party intellectual property claims, each - Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - (a) under intellectual property rights (other than - patent or trademark) Licensable by Contributor to - use, reproduce, modify, display, perform, sublicense - and distribute the Modifications created by such - Contributor (or portions thereof), either on an - unmodified basis, with other Modifications, as - Covered Software and/or as part of a Larger Work; and - - - (b) under Patent Claims infringed by the making, - using, or selling of Modifications made by that - Contributor either alone and/or in combination with - its Contributor Version (or portions of such - combination), to make, use, sell, offer for sale, - have made, and/or otherwise dispose of: (1) - Modifications made by that Contributor (or portions - thereof); and (2) the combination of Modifications - made by that Contributor with its Contributor Version - (or portions of such combination). - - (c) The licenses granted in Sections 2.2(a) and - 2.2(b) are effective on the date Contributor first - distributes or otherwise makes the Modifications - available to a third party. - - (d) Notwithstanding Section 2.2(b) above, no patent - license is granted: (1) for any code that Contributor - has deleted from the Contributor Version; (2) for - infringements caused by: (i) third party - modifications of Contributor Version, or (ii) the - combination of Modifications made by that Contributor - with other software (except as part of the - Contributor Version) or other devices; or (3) under - Patent Claims infringed by Covered Software in the - absence of Modifications made by that Contributor. - - 3. Distribution Obligations. - - 3.1. Availability of Source Code. - - Any Covered Software that You distribute or otherwise make - available in Executable form must also be made available in - Source Code form and that Source Code form must be - distributed only under the terms of this License. You must - include a copy of this License with every copy of the - Source Code form of the Covered Software You distribute or - otherwise make available. You must inform recipients of any - such Covered Software in Executable form as to how they can - obtain such Covered Software in Source Code form in a - reasonable manner on or through a medium customarily used - for software exchange. - - 3.2. Modifications. - - The Modifications that You create or to which You - contribute are governed by the terms of this License. You - represent that You believe Your Modifications are Your - original creation(s) and/or You have sufficient rights to - grant the rights conveyed by this License. - - 3.3. Required Notices. - - You must include a notice in each of Your Modifications - that identifies You as the Contributor of the Modification. - You may not remove or alter any copyright, patent or - trademark notices contained within the Covered Software, or - any notices of licensing or any descriptive text giving - attribution to any Contributor or the Initial Developer. - - 3.4. Application of Additional Terms. - - You may not offer or impose any terms on any Covered - Software in Source Code form that alters or restricts the - applicable version of this License or the recipients" - rights hereunder. You may choose to offer, and to charge a - fee for, warranty, support, indemnity or liability - obligations to one or more recipients of Covered Software. - However, you may do so only on Your own behalf, and not on - behalf of the Initial Developer or any Contributor. You - must make it absolutely clear that any such warranty, - support, indemnity or liability obligation is offered by - You alone, and You hereby agree to indemnify the Initial - Developer and every Contributor for any liability incurred - by the Initial Developer or such Contributor as a result of - warranty, support, indemnity or liability terms You offer. - - - 3.5. Distribution of Executable Versions. - - You may distribute the Executable form of the Covered - Software under the terms of this License or under the terms - of a license of Your choice, which may contain terms - different from this License, provided that You are in - compliance with the terms of this License and that the - license for the Executable form does not attempt to limit - or alter the recipient"s rights in the Source Code form - from the rights set forth in this License. If You - distribute the Covered Software in Executable form under a - different license, You must make it absolutely clear that - any terms which differ from this License are offered by You - alone, not by the Initial Developer or Contributor. You - hereby agree to indemnify the Initial Developer and every - Contributor for any liability incurred by the Initial - Developer or such Contributor as a result of any such terms - You offer. - - 3.6. Larger Works. - - You may create a Larger Work by combining Covered Software - with other code not governed by the terms of this License - and distribute the Larger Work as a single product. In such - a case, You must make sure the requirements of this License - are fulfilled for the Covered Software. - - 4. Versions of the License. - - 4.1. New Versions. - - Sun Microsystems, Inc. is the initial license steward and - may publish revised and/or new versions of this License - from time to time. Each version will be given a - distinguishing version number. Except as provided in - Section 4.3, no one other than the license steward has the - right to modify this License. - - 4.2. Effect of New Versions. - - You may always continue to use, distribute or otherwise - make the Covered Software available under the terms of the - version of the License under which You originally received - the Covered Software. If the Initial Developer includes a - notice in the Original Software prohibiting it from being - distributed or otherwise made available under any - subsequent version of the License, You must distribute and - make the Covered Software available under the terms of the - version of the License under which You originally received - the Covered Software. Otherwise, You may also choose to - use, distribute or otherwise make the Covered Software - available under the terms of any subsequent version of the - License published by the license steward. - - 4.3. Modified Versions. - - When You are an Initial Developer and You want to create a - new license for Your Original Software, You may create and - use a modified version of this License if You: (a) rename - the license and remove any references to the name of the - license steward (except to note that the license differs - from this License); and (b) otherwise make it clear that - the license contains terms which differ from this License. - - - 5. DISCLAIMER OF WARRANTY. - - COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" - BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, - INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED - SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR - PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND - PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY - COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE - INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF - ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF - WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF - ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS - DISCLAIMER. - - 6. TERMINATION. - - 6.1. This License and the rights granted hereunder will - terminate automatically if You fail to comply with terms - herein and fail to cure such breach within 30 days of - becoming aware of the breach. Provisions which, by their - nature, must remain in effect beyond the termination of - this License shall survive. - - 6.2. If You assert a patent infringement claim (excluding - declaratory judgment actions) against Initial Developer or - a Contributor (the Initial Developer or Contributor against - whom You assert such claim is referred to as "Participant") - alleging that the Participant Software (meaning the - Contributor Version where the Participant is a Contributor - or the Original Software where the Participant is the - Initial Developer) directly or indirectly infringes any - patent, then any and all rights granted directly or - indirectly to You by such Participant, the Initial - Developer (if the Initial Developer is not the Participant) - and all Contributors under Sections 2.1 and/or 2.2 of this - License shall, upon 60 days notice from Participant - terminate prospectively and automatically at the expiration - of such 60 day notice period, unless if within such 60 day - period You withdraw Your claim with respect to the - Participant Software against such Participant either - unilaterally or pursuant to a written agreement with - Participant. - - 6.3. In the event of termination under Sections 6.1 or 6.2 - above, all end user licenses that have been validly granted - by You or any distributor hereunder prior to termination - (excluding licenses granted to You by any distributor) - shall survive termination. - - 7. LIMITATION OF LIABILITY. - - UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT - (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE - INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF - COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE - LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT - LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK - STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER - COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN - INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF - LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL - INJURY RESULTING FROM SUCH PARTY"S NEGLIGENCE TO THE EXTENT - APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO - NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR - CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT - APPLY TO YOU. - - 8. U.S. GOVERNMENT END USERS. - - The Covered Software is a "commercial item," as that term is - defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial - computer software" (as that term is defined at 48 C.F.R. " - 252.227-7014(a)(1)) and "commercial computer software - documentation" as such terms are used in 48 C.F.R. 12.212 (Sept. - 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 - through 227.7202-4 (June 1995), all U.S. Government End Users - acquire Covered Software with only those rights set forth herein. - This U.S. Government Rights clause is in lieu of, and supersedes, - any other FAR, DFAR, or other clause or provision that addresses - Government rights in computer software under this License. - - 9. MISCELLANEOUS. - - This License represents the complete agreement concerning subject - matter hereof. If any provision of this License is held to be - unenforceable, such provision shall be reformed only to the - extent necessary to make it enforceable. This License shall be - governed by the law of the jurisdiction specified in a notice - contained within the Original Software (except to the extent - applicable law, if any, provides otherwise), excluding such - jurisdiction"s conflict-of-law provisions. Any litigation - relating to this License shall be subject to the jurisdiction of - the courts located in the jurisdiction and venue specified in a - notice contained within the Original Software, with the losing - party responsible for costs, including, without limitation, court - costs and reasonable attorneys" fees and expenses. The - application of the United Nations Convention on Contracts for the - International Sale of Goods is expressly excluded. Any law or - regulation which provides that the language of a contract shall - be construed against the drafter shall not apply to this License. - You agree that You alone are responsible for compliance with the - United States export administration regulations (and the export - control laws and regulation of any other countries) when You use, - distribute or otherwise make available any Covered Software. - - 10. RESPONSIBILITY FOR CLAIMS. - - As between Initial Developer and the Contributors, each party is - responsible for claims and damages arising, directly or - indirectly, out of its utilization of rights under this License - and You agree to work with Initial Developer and Contributors to - distribute such responsibility on an equitable basis. Nothing - herein is intended or shall be deemed to constitute any admission - of liability. diff --git a/apache-maven/src/main/appended-resources/licenses/unrecognized-javax.annotation-api-1.2.txt b/apache-maven/src/main/appended-resources/licenses/unrecognized-javax.annotation-api-1.2.txt new file mode 100644 index 000000000000..b1c74f95ede8 --- /dev/null +++ b/apache-maven/src/main/appended-resources/licenses/unrecognized-javax.annotation-api-1.2.txt @@ -0,0 +1,759 @@ +COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.1 + +1. Definitions. + + 1.1. "Contributor" means each individual or entity that creates or + contributes to the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the Original + Software, prior Modifications used by a Contributor (if any), and + the Modifications made by that particular Contributor. + + 1.3. "Covered Software" means (a) the Original Software, or (b) + Modifications, or (c) the combination of files containing Original + Software with files containing Modifications, in each case including + portions thereof. + + 1.4. "Executable" means the Covered Software in any form other than + Source Code. + + 1.5. "Initial Developer" means the individual or entity that first + makes Original Software available under this License. + + 1.6. "Larger Work" means a work which combines Covered Software or + portions thereof with code not governed by the terms of this License. + + 1.7. "License" means this document. + + 1.8. "Licensable" means having the right to grant, to the maximum + extent possible, whether at the time of the initial grant or + subsequently acquired, any and all of the rights conveyed herein. + + 1.9. "Modifications" means the Source Code and Executable form of + any of the following: + + A. Any file that results from an addition to, deletion from or + modification of the contents of a file containing Original Software + or previous Modifications; + + B. Any new file that contains any part of the Original Software or + previous Modification; or + + C. Any new file that is contributed or otherwise made available + under the terms of this License. + + 1.10. "Original Software" means the Source Code and Executable form + of computer software code that is originally released under this + License. + + 1.11. "Patent Claims" means any patent claim(s), now owned or + hereafter acquired, including without limitation, method, process, + and apparatus claims, in any patent Licensable by grantor. + + 1.12. "Source Code" means (a) the common form of computer software + code in which modifications are made and (b) associated + documentation included in or with such code. + + 1.13. "You" (or "Your") means an individual or a legal entity + exercising rights under, and complying with all of the terms of, + this License. For legal entities, "You" includes any entity which + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants. + + 2.1. The Initial Developer Grant. + + Conditioned upon Your compliance with Section 3.1 below and subject + to third party intellectual property claims, the Initial Developer + hereby grants You a world-wide, royalty-free, non-exclusive license: + + (a) under intellectual property rights (other than patent or + trademark) Licensable by Initial Developer, to use, reproduce, + modify, display, perform, sublicense and distribute the Original + Software (or portions thereof), with or without Modifications, + and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using or selling of + Original Software, to make, have made, use, practice, sell, and + offer for sale, and/or otherwise dispose of the Original Software + (or portions thereof). + + (c) The licenses granted in Sections 2.1(a) and (b) are effective on + the date Initial Developer first distributes or otherwise makes the + Original Software available to a third party under the terms of this + License. + + (d) Notwithstanding Section 2.1(b) above, no patent license is + granted: (1) for code that You delete from the Original Software, or + (2) for infringements caused by: (i) the modification of the + Original Software, or (ii) the combination of the Original Software + with other software or devices. + + 2.2. Contributor Grant. + + Conditioned upon Your compliance with Section 3.1 below and subject + to third party intellectual property claims, each Contributor hereby + grants You a world-wide, royalty-free, non-exclusive license: + + (a) under intellectual property rights (other than patent or + trademark) Licensable by Contributor to use, reproduce, modify, + display, perform, sublicense and distribute the Modifications + created by such Contributor (or portions thereof), either on an + unmodified basis, with other Modifications, as Covered Software + and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using, or selling + of Modifications made by that Contributor either alone and/or in + combination with its Contributor Version (or portions of such + combination), to make, use, sell, offer for sale, have made, and/or + otherwise dispose of: (1) Modifications made by that Contributor (or + portions thereof); and (2) the combination of Modifications made by + that Contributor with its Contributor Version (or portions of such + combination). + + (c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective + on the date Contributor first distributes or otherwise makes the + Modifications available to a third party. + + (d) Notwithstanding Section 2.2(b) above, no patent license is + granted: (1) for any code that Contributor has deleted from the + Contributor Version; (2) for infringements caused by: (i) third + party modifications of Contributor Version, or (ii) the combination + of Modifications made by that Contributor with other software + (except as part of the Contributor Version) or other devices; or (3) + under Patent Claims infringed by Covered Software in the absence of + Modifications made by that Contributor. + +3. Distribution Obligations. + + 3.1. Availability of Source Code. + + Any Covered Software that You distribute or otherwise make available + in Executable form must also be made available in Source Code form + and that Source Code form must be distributed only under the terms + of this License. You must include a copy of this License with every + copy of the Source Code form of the Covered Software You distribute + or otherwise make available. You must inform recipients of any such + Covered Software in Executable form as to how they can obtain such + Covered Software in Source Code form in a reasonable manner on or + through a medium customarily used for software exchange. + + 3.2. Modifications. + + The Modifications that You create or to which You contribute are + governed by the terms of this License. You represent that You + believe Your Modifications are Your original creation(s) and/or You + have sufficient rights to grant the rights conveyed by this License. + + 3.3. Required Notices. + + You must include a notice in each of Your Modifications that + identifies You as the Contributor of the Modification. You may not + remove or alter any copyright, patent or trademark notices contained + within the Covered Software, or any notices of licensing or any + descriptive text giving attribution to any Contributor or the + Initial Developer. + + 3.4. Application of Additional Terms. + + You may not offer or impose any terms on any Covered Software in + Source Code form that alters or restricts the applicable version of + this License or the recipients' rights hereunder. You may choose to + offer, and to charge a fee for, warranty, support, indemnity or + liability obligations to one or more recipients of Covered Software. + However, you may do so only on Your own behalf, and not on behalf of + the Initial Developer or any Contributor. You must make it + absolutely clear that any such warranty, support, indemnity or + liability obligation is offered by You alone, and You hereby agree + to indemnify the Initial Developer and every Contributor for any + liability incurred by the Initial Developer or such Contributor as a + result of warranty, support, indemnity or liability terms You offer. + + 3.5. Distribution of Executable Versions. + + You may distribute the Executable form of the Covered Software under + the terms of this License or under the terms of a license of Your + choice, which may contain terms different from this License, + provided that You are in compliance with the terms of this License + and that the license for the Executable form does not attempt to + limit or alter the recipient's rights in the Source Code form from + the rights set forth in this License. If You distribute the Covered + Software in Executable form under a different license, You must make + it absolutely clear that any terms which differ from this License + are offered by You alone, not by the Initial Developer or + Contributor. You hereby agree to indemnify the Initial Developer and + every Contributor for any liability incurred by the Initial + Developer or such Contributor as a result of any such terms You offer. + + 3.6. Larger Works. + + You may create a Larger Work by combining Covered Software with + other code not governed by the terms of this License and distribute + the Larger Work as a single product. In such a case, You must make + sure the requirements of this License are fulfilled for the Covered + Software. + +4. Versions of the License. + + 4.1. New Versions. + + Oracle is the initial license steward and may publish revised and/or + new versions of this License from time to time. Each version will be + given a distinguishing version number. Except as provided in Section + 4.3, no one other than the license steward has the right to modify + this License. + + 4.2. Effect of New Versions. + + You may always continue to use, distribute or otherwise make the + Covered Software available under the terms of the version of the + License under which You originally received the Covered Software. If + the Initial Developer includes a notice in the Original Software + prohibiting it from being distributed or otherwise made available + under any subsequent version of the License, You must distribute and + make the Covered Software available under the terms of the version + of the License under which You originally received the Covered + Software. Otherwise, You may also choose to use, distribute or + otherwise make the Covered Software available under the terms of any + subsequent version of the License published by the license steward. + + 4.3. Modified Versions. + + When You are an Initial Developer and You want to create a new + license for Your Original Software, You may create and use a + modified version of this License if You: (a) rename the license and + remove any references to the name of the license steward (except to + note that the license differs from this License); and (b) otherwise + make it clear that the license contains terms which differ from this + License. + +5. DISCLAIMER OF WARRANTY. + + COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, + INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE + IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR + NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF + THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE + DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY + OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, + REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN + ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS + AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +6. TERMINATION. + + 6.1. This License and the rights granted hereunder will terminate + automatically if You fail to comply with terms herein and fail to + cure such breach within 30 days of becoming aware of the breach. + Provisions which, by their nature, must remain in effect beyond the + termination of this License shall survive. + + 6.2. If You assert a patent infringement claim (excluding + declaratory judgment actions) against Initial Developer or a + Contributor (the Initial Developer or Contributor against whom You + assert such claim is referred to as "Participant") alleging that the + Participant Software (meaning the Contributor Version where the + Participant is a Contributor or the Original Software where the + Participant is the Initial Developer) directly or indirectly + infringes any patent, then any and all rights granted directly or + indirectly to You by such Participant, the Initial Developer (if the + Initial Developer is not the Participant) and all Contributors under + Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice + from Participant terminate prospectively and automatically at the + expiration of such 60 day notice period, unless if within such 60 + day period You withdraw Your claim with respect to the Participant + Software against such Participant either unilaterally or pursuant to + a written agreement with Participant. + + 6.3. If You assert a patent infringement claim against Participant + alleging that the Participant Software directly or indirectly + infringes any patent where such claim is resolved (such as by + license or settlement) prior to the initiation of patent + infringement litigation, then the reasonable value of the licenses + granted by such Participant under Sections 2.1 or 2.2 shall be taken + into account in determining the amount or value of any payment or + license. + + 6.4. In the event of termination under Sections 6.1 or 6.2 above, + all end user licenses that have been validly granted by You or any + distributor hereunder prior to termination (excluding licenses + granted to You by any distributor) shall survive termination. + +7. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE + INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF + COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE + TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR + CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT + LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER + FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR + LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE + POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT + APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH + PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH + LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR + LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION + AND LIMITATION MAY NOT APPLY TO YOU. + +8. U.S. GOVERNMENT END USERS. + + The Covered Software is a "commercial item," as that term is defined + in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer + software" (as that term is defined at 48 C.F.R. § + 252.227-7014(a)(1)) and "commercial computer software documentation" + as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent + with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 + (June 1995), all U.S. Government End Users acquire Covered Software + with only those rights set forth herein. This U.S. Government Rights + clause is in lieu of, and supersedes, any other FAR, DFAR, or other + clause or provision that addresses Government rights in computer + software under this License. + +9. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. This License shall be governed by + the law of the jurisdiction specified in a notice contained within + the Original Software (except to the extent applicable law, if any, + provides otherwise), excluding such jurisdiction's conflict-of-law + provisions. Any litigation relating to this License shall be subject + to the jurisdiction of the courts located in the jurisdiction and + venue specified in a notice contained within the Original Software, + with the losing party responsible for costs, including, without + limitation, court costs and reasonable attorneys' fees and expenses. + The application of the United Nations Convention on Contracts for + the International Sale of Goods is expressly excluded. Any law or + regulation which provides that the language of a contract shall be + construed against the drafter shall not apply to this License. You + agree that You alone are responsible for compliance with the United + States export administration regulations (and the export control + laws and regulation of any other countries) when You use, distribute + or otherwise make available any Covered Software. + +10. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or indirectly, + out of its utilization of rights under this License and You agree to + work with Initial Developer and Contributors to distribute such + responsibility on an equitable basis. Nothing herein is intended or + shall be deemed to constitute any admission of liability. + +------------------------------------------------------------------------ + +NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION +LICENSE (CDDL) + +The code released under the CDDL shall be governed by the laws of the +State of California (excluding conflict-of-law provisions). Any +litigation relating to this License shall be subject to the jurisdiction +of the Federal Courts of the Northern District of California and the +state courts of the State of California, with venue lying in Santa Clara +County, California. + + + + The GNU General Public License (GPL) Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +51 Franklin Street, Fifth Floor +Boston, MA 02110-1335 +USA + +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +Preamble + +The licenses for most software are designed to take away your freedom to +share and change it. By contrast, the GNU General Public License is +intended to guarantee your freedom to share and change free software--to +make sure the software is free for all its users. This General Public +License applies to most of the Free Software Foundation's software and +to any other program whose authors commit to using it. (Some other Free +Software Foundation software is covered by the GNU Library General +Public License instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. +Our General Public Licenses are designed to make sure that you have the +freedom to distribute copies of free software (and charge for this +service if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone +to deny you these rights or to ask you to surrender the rights. These +restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis +or for a fee, you must give the recipients all the rights that you have. +You must make sure that they, too, receive or can get the source code. +And you must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software patents. +We wish to avoid the danger that redistributors of a free program will +individually obtain patent licenses, in effect making the program +proprietary. To prevent this, we have made it clear that any patent must +be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains a +notice placed by the copyright holder saying it may be distributed under +the terms of this General Public License. The "Program", below, refers +to any such program or work, and a "work based on the Program" means +either the Program or any derivative work under copyright law: that is +to say, a work containing the Program or a portion of it, either +verbatim or with modifications and/or translated into another language. +(Hereinafter, translation is included without limitation in the term +"modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of running +the Program is not restricted, and the output from the Program is +covered only if its contents constitute a work based on the Program +(independent of having been made by running the Program). Whether that +is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's source +code as you receive it, in any medium, provided that you conspicuously +and appropriately publish on each copy an appropriate copyright notice +and disclaimer of warranty; keep intact all the notices that refer to +this License and to the absence of any warranty; and give any other +recipients of the Program a copy of this License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of +it, thus forming a work based on the Program, and copy and distribute +such modifications or work under the terms of Section 1 above, provided +that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any part + thereof, to be licensed as a whole at no charge to all third parties + under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a notice + that there is no warranty (or else, saying that you provide a + warranty) and that users may redistribute the program under these + conditions, and telling the user how to view a copy of this License. + (Exception: if the Program itself is interactive but does not + normally print such an announcement, your work based on the Program + is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, and +can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based on +the Program, the distribution of the whole must be on the terms of this +License, whose permissions for other licensees extend to the entire +whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of a +storage or distribution medium does not bring the other work under the +scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections 1 + and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your cost + of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer to + distribute corresponding source code. (This alternative is allowed + only for noncommercial distribution and only if you received the + program in object code or executable form with such an offer, in + accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source code +means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to control +compilation and installation of the executable. However, as a special +exception, the source code distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies the +executable. + +If distribution of executable or object code is made by offering access +to copy from a designated place, then offering equivalent access to copy +the source code from the same place counts as distribution of the source +code, even though third parties are not compelled to copy the source +along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt otherwise +to copy, modify, sublicense or distribute the Program is void, and will +automatically terminate your rights under this License. However, parties +who have received copies, or rights, from you under this License will +not have their licenses terminated so long as such parties remain in +full compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and all +its terms and conditions for copying, distributing or modifying the +Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further restrictions +on the recipients' exercise of the rights granted herein. You are not +responsible for enforcing compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot distribute +so as to satisfy simultaneously your obligations under this License and +any other pertinent obligations, then as a consequence you may not +distribute the Program at all. For example, if a patent license would +not permit royalty-free redistribution of the Program by all those who +receive copies directly or indirectly through you, then the only way you +could satisfy both it and this License would be to refrain entirely from +distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is implemented +by public license practices. Many people have made generous +contributions to the wide range of software distributed through that +system in reliance on consistent application of that system; it is up to +the author/donor to decide if he or she is willing to distribute +software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be +a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License may +add an explicit geographical distribution limitation excluding those +countries, so that distribution is permitted only in or among countries +not thus excluded. In such case, this License incorporates the +limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new +versions of the General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Program does not specify a version +number of this License, you may choose any version ever published by the +Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the +author to ask for permission. For software which is copyrighted by the +Free Software Foundation, write to the Free Software Foundation; we +sometimes make exceptions for this. Our decision will be guided by the +two goals of preserving the free status of all derivatives of our free +software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, +EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE +ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH +YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL +NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR +DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL +DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM +(INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED +INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF +THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR +OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to +attach them to the start of each source file to most effectively convey +the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + One line to give the program's name and a brief idea of what it does. + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type + `show w'. This is free software, and you are welcome to redistribute + it under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the +appropriate parts of the General Public License. Of course, the commands +you use may be called something other than `show w' and `show c'; they +could even be mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + program `Gnomovision' (which makes passes at compilers) written by + James Hacker. + + signature of Ty Coon, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications +with the library. If this is what you want to do, use the GNU Library +General Public License instead of this License. + +# + +Certain source files distributed by Oracle America, Inc. and/or its +affiliates are subject to the following clarification and special +exception to the GPLv2, based on the GNU Project exception for its +Classpath libraries, known as the GNU Classpath Exception, but only +where Oracle has expressly included in the particular source file's +header the words "Oracle designates this particular file as subject to +the "Classpath" exception as provided by Oracle in the LICENSE file +that accompanied this code." + +You should also note that Oracle includes multiple, independent +programs in this software package. Some of those programs are provided +under licenses deemed incompatible with the GPLv2 by the Free Software +Foundation and others. For example, the package includes programs +licensed under the Apache License, Version 2.0. Such programs are +licensed to you under their original licenses. + +Oracle facilitates your further distribution of this package by adding +the Classpath Exception to the necessary parts of its GPLv2 code, which +permits you to use that code in combination with other independent +modules not licensed under the GPLv2. However, note that this would +not permit you to commingle code under an incompatible license with +Oracle's GPLv2 licensed code by, for example, cutting and pasting such +code into a file also containing Oracle's GPLv2 licensed code and then +distributing the result. Additionally, if you were to remove the +Classpath Exception from any of the files to which it applies and +distribute the result, you would likely be required to license some or +all of the other code in that distribution under the GPLv2 as well, and +since the GPLv2 is incompatible with the license terms of some items +included in the distribution by Oracle, removing the Classpath +Exception could therefore effectively compromise your ability to +further distribute the package. + +Proceed with caution and we recommend that you obtain the advice of a +lawyer skilled in open source matters before removing the Classpath +Exception or making modifications to this package which may +subsequently be redistributed and/or involve the use of third party +software. + +CLASSPATH EXCEPTION +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License version 2 cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from or +based on this library. If you modify this library, you may extend this +exception to your version of the library, but you are not obligated to +do so. If you do not wish to do so, delete this exception statement +from your version. diff --git a/maven-core/src/main/resources/META-INF/maven/extension.xml b/maven-core/src/main/resources/META-INF/maven/extension.xml index 6bd836927364..1fa9d41750b6 100644 --- a/maven-core/src/main/resources/META-INF/maven/extension.xml +++ b/maven-core/src/main/resources/META-INF/maven/extension.xml @@ -166,7 +166,7 @@ under the License. org.apache.maven.resolver:maven-resolver-impl javax.inject:javax.inject - javax.annotation:jsr250-api + javax.annotation:javax.annotation-api org.slf4j:slf4j-api org.fusesource.jansi:jansi diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index fc90bbc13493..232bb9031048 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -116,7 +116,7 @@ under the License. javax.annotation - jsr250-api + javax.annotation-api org.codehaus.plexus diff --git a/pom.xml b/pom.xml index 40a7ee81ade0..9e68774899cc 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ under the License. 1.26 3.3.0 4.2.2 - 0.3.4 + 0.3.5 3.4.3 1.12.1 2.0 @@ -248,12 +248,12 @@ under the License. org.eclipse.sisu org.eclipse.sisu.plexus - ${sisuInjectVersion} + ${sisuVersion} org.eclipse.sisu org.eclipse.sisu.inject - ${sisuInjectVersion} + ${sisuVersion} javax.inject @@ -262,8 +262,8 @@ under the License. javax.annotation - jsr250-api - 1.0 + javax.annotation-api + 1.2 org.codehaus.plexus @@ -480,7 +480,7 @@ under the License. org.eclipse.sisu sisu-maven-plugin - ${sisuInjectVersion} + ${sisuVersion} @@ -545,10 +545,10 @@ under the License. src/test/remote-repo/** **/*.odg - src/main/appended-resources/licenses/CDDL-1.0.txt src/main/appended-resources/licenses/EPL-1.0.txt + src/main/appended-resources/licenses/unrecognized-javax.annotation-api-1.2.txt From 4e5b3d55545e5f03f05ac7b0cd1b56689df36201 Mon Sep 17 00:00:00 2001 From: Falko Modler Date: Sun, 22 Aug 2021 22:52:30 +0200 Subject: [PATCH 081/188] [MNG-7251] Fix threadLocalArtifactsHolder leaking into cloned project This closes #527 --- .../apache/maven/project/MavenProject.java | 49 ++++++++++--------- .../maven/project/MavenProjectTest.java | 43 ++++++++++++++++ 2 files changed, 68 insertions(+), 24 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index 157b7a0f0a55..94d678814534 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -143,13 +143,7 @@ public class MavenProject private Artifact artifact; - private final ThreadLocal threadLocalArtifactsHolder = new ThreadLocal() - { - protected ArtifactsHolder initialValue() - { - return new ArtifactsHolder(); - } - }; + private ThreadLocal threadLocalArtifactsHolder = newThreadLocalArtifactsHolder(); private Model originalModel; @@ -188,6 +182,17 @@ public MavenProject() setModel( model ); } + private static ThreadLocal newThreadLocalArtifactsHolder() + { + return new ThreadLocal() + { + protected ArtifactsHolder initialValue() + { + return new ArtifactsHolder(); + } + }; + } + public MavenProject( Model model ) { setModel( model ); @@ -1181,7 +1186,8 @@ public MavenProject clone() { throw new UnsupportedOperationException( e ); } - + // clone must have it's own TL, otherwise the artifacts are intermingled! + clone.threadLocalArtifactsHolder = newThreadLocalArtifactsHolder(); clone.deepCopy( this ); return clone; @@ -1224,6 +1230,7 @@ private void deepCopy( MavenProject project ) // copy fields file = project.file; basedir = project.basedir; + threadLocalArtifactsHolder.set( project.threadLocalArtifactsHolder.get().copy() ); // don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be // sure! @@ -1232,11 +1239,6 @@ private void deepCopy( MavenProject project ) setDependencyArtifacts( Collections.unmodifiableSet( project.getDependencyArtifacts() ) ); } - if ( project.getArtifacts() != null ) - { - setArtifacts( Collections.unmodifiableSet( project.getArtifacts() ) ); - } - if ( project.getParentFile() != null ) { parentFile = new File( project.getParentFile().getAbsolutePath() ); @@ -1479,13 +1481,7 @@ public void addLifecyclePhase( String lifecyclePhase ) // ---------------------------------------------------------------------------------------------------------------- // - // - // D E P R E C A T E D - // - // - // ---------------------------------------------------------------------------------------------------------------- - // - // Everything below will be removed for Maven 4.0.0 + // D E P R E C A T E D - Everything below will be removed for Maven 4.0.0 // // ---------------------------------------------------------------------------------------------------------------- @@ -1506,7 +1502,6 @@ public String getModulePathAdjustment( MavenProject moduleProject ) if ( moduleFile != null ) { File moduleDir = moduleFile.getCanonicalFile().getParentFile(); - module = moduleDir.getName(); } @@ -1827,7 +1822,6 @@ public Reporting getReporting() public void setReportArtifacts( Set reportArtifacts ) { this.reportArtifacts = reportArtifacts; - reportArtifactMap = null; } @@ -1851,7 +1845,6 @@ public Map getReportArtifactMap() public void setExtensionArtifacts( Set extensionArtifacts ) { this.extensionArtifacts = extensionArtifacts; - extensionArtifactMap = null; } @@ -1885,7 +1878,6 @@ public List getReportPlugins() public Xpp3Dom getReportConfiguration( String pluginGroupId, String pluginArtifactId, String reportSetId ) { Xpp3Dom dom = null; - // ---------------------------------------------------------------------- // I would like to be able to lookup the Mojo object using a key but // we have a limitation in modello that will be remedied shortly. So @@ -1995,5 +1987,14 @@ private static class ArtifactsHolder private ArtifactFilter artifactFilter; private Set artifacts; private Map artifactMap; + + ArtifactsHolder copy() + { + ArtifactsHolder copy = new ArtifactsHolder(); + copy.artifactFilter = artifactFilter; + copy.artifacts = artifacts != null ? new LinkedHashSet<>( artifacts ) : null; + copy.artifactMap = artifactMap != null ? new LinkedHashMap<>( artifactMap ) : null; + return copy; + } } } diff --git a/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java b/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java index 6b4258b3fde9..2344d8f77345 100644 --- a/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java @@ -21,13 +21,18 @@ import java.io.File; import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; +import org.apache.maven.artifact.Artifact; import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.model.Profile; +import org.mockito.Mockito; public class MavenProjectTest extends AbstractMavenProjectTestCase @@ -188,6 +193,44 @@ public void testCloneWithBaseDir() assertEquals( "Base directory is preserved across clone", projectToClone.getBasedir(), clonedProject.getBasedir() ); } + public void testCloneWithArtifacts() + throws InterruptedException + { + Artifact initialArtifact = Mockito.mock( Artifact.class, "initialArtifact" ); + MavenProject originalProject = new MavenProject(); + originalProject.setArtifacts( Collections.singleton( initialArtifact ) ); + assertEquals( "Sanity check: originalProject returns artifact that has just been set", + Collections.singleton( initialArtifact ), originalProject.getArtifacts() ); + + final MavenProject clonedProject = originalProject.clone(); + + assertEquals( "Cloned project returns the artifact that was set for the original project", + Collections.singleton( initialArtifact ), clonedProject.getArtifacts() ); + + Artifact anotherArtifact = Mockito.mock( Artifact.class, "anotherArtifact" ); + clonedProject.setArtifacts( Collections.singleton( anotherArtifact ) ); + assertEquals( "Sanity check: clonedProject returns artifact that has just been set", + Collections.singleton( anotherArtifact ), clonedProject.getArtifacts() ); + + assertEquals( "Original project returns the artifact that was set initially (not the one for clonedProject)", + Collections.singleton( initialArtifact ), originalProject.getArtifacts() ); + + final AtomicReference> artifactsFromThread = new AtomicReference<>(); + Thread thread = new Thread( new Runnable() + { + @Override + public void run() + { + artifactsFromThread.set( clonedProject.getArtifacts() ); + } + } ); + thread.start(); + thread.join(); + + assertEquals( "Another thread does not see the same artifacts", + Collections.emptySet(), artifactsFromThread.get() ); + } + public void testUndefinedOutputDirectory() throws Exception { From 1ea42b0371f1bc99a4e0629c3734ad4ccfc0dcbd Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sat, 11 Sep 2021 13:43:19 +0200 Subject: [PATCH 082/188] [MNG-7219] [Regression] plexus-cipher missing from transitive dependencies --- apache-maven/pom.xml | 4 ---- maven-compat/pom.xml | 5 ----- maven-core/pom.xml | 5 ----- 3 files changed, 14 deletions(-) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index a4cf0396c61b..d98d4326f002 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -113,10 +113,6 @@ under the License. org.fusesource.jansi jansi - - org.codehaus.plexus - plexus-cipher - diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index 06686b980a5d..46259815a4fe 100644 --- a/maven-compat/pom.xml +++ b/maven-compat/pom.xml @@ -99,11 +99,6 @@ under the License. wagon-provider-api - - org.codehaus.plexus - plexus-cipher - test - org.apache.maven.wagon wagon-file diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 60b958f1f6fb..b3f048b3c07c 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -122,11 +122,6 @@ under the License. org.codehaus.plexus plexus-component-annotations - - org.codehaus.plexus - plexus-cipher - test - org.apache.commons commons-lang3 From 98a9d089bda8870fd658208d98bdc73a5f039b0f Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 9 Sep 2021 16:25:21 +0200 Subject: [PATCH 083/188] [MNG-7236] The DefaultPluginVersionResolver should cache results for the session --- .../DefaultPluginVersionResolver.java | 89 ++++++++++++++++++- 1 file changed, 85 insertions(+), 4 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java index 82e32fb310b3..2d2d1cba7b41 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java @@ -25,7 +25,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.TreeSet; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.Versioning; @@ -49,6 +52,7 @@ import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RequestTrace; +import org.eclipse.aether.SessionData; import org.eclipse.aether.metadata.DefaultMetadata; import org.eclipse.aether.repository.ArtifactRepository; import org.eclipse.aether.repository.RemoteRepository; @@ -72,6 +76,8 @@ public class DefaultPluginVersionResolver private static final String REPOSITORY_CONTEXT = "plugin"; + private static final Object CACHE_KEY = new Object(); + @Requirement private Logger logger; @@ -91,12 +97,26 @@ public PluginVersionResult resolve( PluginVersionRequest request ) if ( result == null ) { - result = resolveFromRepository( request ); + ConcurrentMap cache = getCache( request.getRepositorySession().getData() ); + Key key = getKey( request ); + result = cache.get( key ); - if ( logger.isDebugEnabled() ) + if ( result == null ) { - logger.debug( "Resolved plugin version for " + request.getGroupId() + ":" + request.getArtifactId() - + " to " + result.getVersion() + " from repository " + result.getRepository() ); + result = resolveFromRepository( request ); + + if ( logger.isDebugEnabled() ) + { + logger.debug( "Resolved plugin version for " + request.getGroupId() + ":" + request.getArtifactId() + + " to " + result.getVersion() + " from repository " + result.getRepository() ); + } + + cache.putIfAbsent( key, result ); + } + else if ( logger.isDebugEnabled() ) + { + logger.debug( "Reusing cached resolved plugin version for " + request.getGroupId() + ":" + + request.getArtifactId() + " to " + result.getVersion() + " from POM " + request.getPom() ); } } else if ( logger.isDebugEnabled() ) @@ -384,6 +404,67 @@ private PluginVersionResult resolveFromProject( PluginVersionRequest request, Li return null; } + @SuppressWarnings( "unchecked" ) + private ConcurrentMap getCache( SessionData data ) + { + ConcurrentMap cache = + ( ConcurrentMap ) data.get( CACHE_KEY ); + while ( cache == null ) + { + cache = new ConcurrentHashMap<>( 256 ); + if ( data.set( CACHE_KEY, null, cache ) ) + { + break; + } + cache = ( ConcurrentMap ) data.get( CACHE_KEY ); + } + return cache; + } + + private static Key getKey( PluginVersionRequest request ) + { + return new Key( request.getGroupId(), request.getArtifactId(), request.getRepositories() ); + } + + static class Key + { + final String groupId; + final String artifactId; + final List repositories; + final int hash; + + Key( String groupId, String artifactId, List repositories ) + { + this.groupId = groupId; + this.artifactId = artifactId; + this.repositories = repositories; + this.hash = Objects.hash( groupId, artifactId, repositories ); + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + Key key = ( Key ) o; + return groupId.equals( key.groupId ) + && artifactId.equals( key.artifactId ) + && repositories.equals( key.repositories ); + } + + @Override + public int hashCode() + { + return hash; + } + } + static class Versions { From 93f9e85955abb40bb090bad689f15fa9969ef9ba Mon Sep 17 00:00:00 2001 From: Romain Manni-Bucau Date: Thu, 3 Dec 2020 20:07:03 +0100 Subject: [PATCH 084/188] [MNG-7045] Drop CDI API from Maven This closes #540 --- maven-core/src/main/resources/META-INF/maven/extension.xml | 4 +++- pom.xml | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/maven-core/src/main/resources/META-INF/maven/extension.xml b/maven-core/src/main/resources/META-INF/maven/extension.xml index 1fa9d41750b6..73bee382de9c 100644 --- a/maven-core/src/main/resources/META-INF/maven/extension.xml +++ b/maven-core/src/main/resources/META-INF/maven/extension.xml @@ -94,9 +94,11 @@ under the License. javax.inject.* - + javax.annotation.* diff --git a/pom.xml b/pom.xml index 9e68774899cc..65f5d22411a2 100644 --- a/pom.xml +++ b/pom.xml @@ -249,6 +249,12 @@ under the License. org.eclipse.sisu org.eclipse.sisu.plexus ${sisuVersion} + + + javax.enterprise + cdi-api + + org.eclipse.sisu From d1aa1e1f0a891609256c60b2b7b5b8efaceea563 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Thu, 16 Sep 2021 10:08:23 +0200 Subject: [PATCH 085/188] [MNG-7252] Fix warnings issued by dependency:analyze This closes #541 --- maven-core/pom.xml | 8 ++++++++ maven-embedder/pom.xml | 1 + .../apache/maven/model/building/FileModelSourceTest.java | 4 ++-- maven-resolver-provider/pom.xml | 4 ---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/maven-core/pom.xml b/maven-core/pom.xml index b3f048b3c07c..748ce6cd3960 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -118,6 +118,10 @@ under the License. org.codehaus.plexus plexus-classworlds + + org.codehaus.plexus + plexus-interpolation + org.codehaus.plexus plexus-component-annotations @@ -126,6 +130,10 @@ under the License. org.apache.commons commons-lang3 + + org.slf4j + slf4j-api + commons-jxpath commons-jxpath diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 232bb9031048..7a3cc7e0d14a 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -114,6 +114,7 @@ under the License. javax.inject javax.inject + javax.annotation javax.annotation-api diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java index 9b0ecd9ddf57..6c8ebe0e4220 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/building/FileModelSourceTest.java @@ -22,7 +22,7 @@ import java.io.IOException; import static junit.framework.TestCase.assertFalse; import static junit.framework.TestCase.assertTrue; -import org.apache.commons.lang3.SystemUtils; +import org.codehaus.plexus.util.Os;; import static org.junit.Assume.assumeTrue; import org.junit.Test; @@ -53,7 +53,7 @@ public void testEquals() public void testWindowsPaths() throws Exception { - assumeTrue( SystemUtils.IS_OS_WINDOWS ); + assumeTrue( Os.isFamily( "Windows" ) ); File upperCaseFile = createTempFile( "TESTE" ); String absolutePath = upperCaseFile.getAbsolutePath(); diff --git a/maven-resolver-provider/pom.xml b/maven-resolver-provider/pom.xml index 70e0f4e5bc35..ca317a9edeca 100644 --- a/maven-resolver-provider/pom.xml +++ b/maven-resolver-provider/pom.xml @@ -108,10 +108,6 @@ under the License. mockito-core test - - org.slf4j - slf4j-api - org.slf4j slf4j-simple From 8c66edc0417f37540b3a6ef4b266ff88bdbd8327 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Thu, 16 Sep 2021 13:52:15 +0200 Subject: [PATCH 086/188] [MNG-7254] Expand Windows native libraries for Jansi due to JDK-8195129 (workaround) This closes #542 --- apache-maven/pom.xml | 16 ++++++++++++++++ apache-maven/src/bin/mvn | 1 + apache-maven/src/bin/mvn.cmd | 1 + apache-maven/src/lib/jansi-native/README.txt | 8 ++++++++ .../src/main/assembly/.component.xml.swp | Bin 0 -> 12288 bytes apache-maven/src/main/assembly/component.xml | 7 +++++++ 6 files changed, 33 insertions(+) create mode 100644 apache-maven/src/lib/jansi-native/README.txt create mode 100644 apache-maven/src/main/assembly/.component.xml.swp diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index d98d4326f002..b6068d0fc972 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -131,6 +131,22 @@ under the License. + + org.apache.maven.plugins + maven-dependency-plugin + + jansi + org/fusesource/jansi/internal/native/Windows/** + + + + unpack-jansi-native + + unpack-dependencies + + + + org.apache.maven.plugins maven-compiler-plugin diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn index 29e0eabb837c..90f9a758d9cf 100755 --- a/apache-maven/src/bin/mvn +++ b/apache-maven/src/bin/mvn @@ -197,5 +197,6 @@ exec "$JAVACMD" \ -classpath "${CLASSWORLDS_JAR}" \ "-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \ "-Dmaven.home=${MAVEN_HOME}" \ + "-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" \ "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ ${CLASSWORLDS_LAUNCHER} "$@" diff --git a/apache-maven/src/bin/mvn.cmd b/apache-maven/src/bin/mvn.cmd index fcb0f455a804..9fb4a98c7e24 100644 --- a/apache-maven/src/bin/mvn.cmd +++ b/apache-maven/src/bin/mvn.cmd @@ -174,6 +174,7 @@ set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher -classpath %CLASSWORLDS_JAR% ^ "-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" ^ "-Dmaven.home=%MAVEN_HOME%" ^ + "-Dlibrary.jansi.path=%MAVEN_HOME%\lib\jansi-native" ^ "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS% if ERRORLEVEL 1 goto error diff --git a/apache-maven/src/lib/jansi-native/README.txt b/apache-maven/src/lib/jansi-native/README.txt new file mode 100644 index 000000000000..26a957e1b564 --- /dev/null +++ b/apache-maven/src/lib/jansi-native/README.txt @@ -0,0 +1,8 @@ +This directory contains Jansi native libraries extracted from Jansi JAR. + +You can add your own build for platforms not natively supported by Jansi. +See here [1] on how to compile for your platform and and here [2] how libraries +follow Jansi's directory and filename conventions. + +[1] https://github.com/fusesource/jansi/tree/master/src/main/native +[2] https://github.com/fusesource/jansi/blob/321a8ff71c731e10f4ea05c607860180276b2215/src/main/java/org/fusesource/jansi/internal/OSInfo.java diff --git a/apache-maven/src/main/assembly/.component.xml.swp b/apache-maven/src/main/assembly/.component.xml.swp new file mode 100644 index 0000000000000000000000000000000000000000..52c487e4a78f44dad9a6220103ec18dab7e0e89c GIT binary patch literal 12288 zcmeI2Ux*t;9LJ|sYpb?O1w{mz#)@sd?B=c%+iN^X?{XNt>p#tp?;n+atIrV|a#CCfJl4>gbba*>_Y%xqgrOqiBu*)5js7nErf z)0S;d3MRDCZM%tQre9M9QUyj(AkdBM;hhTyC&qK3^@Eu`^zPjYBQ#7+QUy{4QUy{4 zQUy{4QUy{4QUy{4ZWINyw}m{1V7A5qHRI1MD?a05`jIM-Dv&CWDv&CWDv&CWDv&CW zDv&CWDv&CWD)2v4z;X!r34XsB{sI7h{~!GS|H_?&dC3Q@E!beJ0V|#3*cFB7VHQ2g00}k+X%S`UIEX5BVZT!V+SGM zf-k_Q;C*l&ya0S)g9Weye7T*F&%s;ZMG$}nI1L^Kzu!v8_uw;d5nKT0z#_S zWg8(sfUm&YKm!{T!9lPW+yj2Tg^*9cyWmyefv3PxFa{m~zugR7`z9zO{FPsEEuR3HB9!LM26tJNX%&_d<$e(r zGSFV2XSmO7E&bk<%jyQWQ|%?uTlDe+lYy?V z*ptoDT8k@+e@ar_vNWA8QPoqLwH383K|SVk>2TX}-5&J=0V75|UxrTmG@DI4Ez#c$ zs|U@sdQ8}?x;=1s7{jW}*SQ!q6OrjA6Oqu>k!sUAA29mqAH*2vCXoqPw4MK6+=G!Z z6h7(lfot#=ubsJQ3B|L*(tL@Hk~D4kO{PtUc}zG=*gZ3EZZdz@J&wARdK138+{RHk zrp$i3f7|;J=gC<3q4U==XRfDwWxiILF0L9yi7_^Z`<3cylZ__?1A}Dal^~8VI*^!E zEz4(4*7EHZMrPJ$N(R1-q?L=cLbgqn|_DL1W}2X=-CZYFU9YJePF?HQE2j+Ahv&oBgGFd%@2lqTbw^~NSaguo)&*blhGpxihUF?u9&6l*y3DVk!V19#(G7>+T60_| z%_#A%nAkTSp6kyaYlOAwfUlMy3a+d8q{0E*wlybhOute*mT772O`84lxkmqdu7Rk{ zLbX~fADcUqot`frpRW`vHFLtq89Dk-4Z6x1p5)CAPx5A?Mh0$XrbvERO>w|isLl7D z={KB2B*Vs?PRHmRjGUgpxn%Qnd9E4-ndL%hOV}(!!re%K#lw#_DRceV*dWSdHg9m7 zx|V1LR+G`DTw=b!hAQ0Nw7F6cNl{BU)a7liBheIjqEwj~ql{z6<5Sl4FjXijeahRO z%b8Z=ytVyO&rKM_y9xGH!)iHXiRC|1Wp+-*?PMj!IYNcY8&Yz&u^Oc!W ztu$XjX_gi$XNZyw-NEcc9j>&`>w#ttT@_HcSxXv70nf>Ta6|We_H=+9utV!TYI*R} zw(2fJo3I7Ux0KTITrk91#{2A?%8KioG*-uS%P(o}W?%v#)o(=}{m3)NX9y}xcR zdq9!`$Kk>`OnhgfBwLOH@uaX^IEk#cqai~eaa$sP*a!CWhl=>&eeH3SUaQ2w>937Z k&?Jr{N)NoJad_3ipqP~iJ?e+** + + target/dependency/org/fusesource/jansi/internal/native + lib/jansi-native + + ** + + src/bin bin From ab54d17dc2ec355c1e002e8751739edd9a96fcc3 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Fri, 17 Sep 2021 12:18:27 -0300 Subject: [PATCH 087/188] [MNG-7253] Display relocation message defined in model Move logging to DefaultArtifactDescriptorReader This closes #544 --- .../DefaultProjectDependenciesResolver.java | 12 ------------ .../DefaultArtifactDescriptorReader.java | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java index 7500e43d2a38..3644b67ef408 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java @@ -181,18 +181,6 @@ public DependencyResolutionResult resolve( DependencyResolutionRequest request ) depRequest.setRoot( node ); - if ( logger.isWarnEnabled() ) - { - for ( DependencyNode child : node.getChildren() ) - { - if ( !child.getRelocations().isEmpty() ) - { - logger.warn( "The artifact " + child.getRelocations().get( 0 ) + " has been relocated to " - + child.getDependency().getArtifact() ); - } - } - } - if ( logger.isDebugEnabled() ) { node.accept( new GraphLogger( project ) ); diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java index c2ba0a3d729a..888f4581b460 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java @@ -68,6 +68,8 @@ import org.eclipse.aether.spi.locator.Service; import org.eclipse.aether.spi.locator.ServiceLocator; import org.eclipse.aether.transfer.ArtifactNotFoundException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Benjamin Bentmann @@ -77,6 +79,8 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader, Service { + private static final Logger LOGGER = LoggerFactory.getLogger( DefaultArtifactDescriptorReader.class ); + private RemoteRepositoryManager remoteRepositoryManager; private VersionResolver versionResolver; @@ -316,10 +320,20 @@ private Model loadPom( RepositorySystemSession session, ArtifactDescriptorReques if ( relocation != null ) { result.addRelocation( a ); - a = + Artifact relocatedArtifact = new RelocatedArtifact( a, relocation.getGroupId(), relocation.getArtifactId(), relocation.getVersion() ); - result.setArtifact( a ); + if ( LOGGER.isWarnEnabled() ) + { + String message = "The artifact " + a + " has been relocated to " + relocatedArtifact; + if ( relocation.getMessage() != null ) + { + message += ": " + relocation.getMessage(); + } + LOGGER.warn( message ); + } + result.setArtifact( relocatedArtifact ); + a = relocatedArtifact; } else { From 8882a9c599013182e42f0c7c321396c23b84dbe0 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 29 May 2021 09:31:49 -0400 Subject: [PATCH 088/188] [MNG-7164] Add constructor MojoExecutionException(Throwable) This closes #474 --- .../plugin/AbstractMojoExecutionException.java | 12 ++++++++++++ .../apache/maven/plugin/MojoExecutionException.java | 13 +++++++++++++ .../apache/maven/plugin/MojoFailureException.java | 13 +++++++++++++ 3 files changed, 38 insertions(+) diff --git a/maven-plugin-api/src/main/java/org/apache/maven/plugin/AbstractMojoExecutionException.java b/maven-plugin-api/src/main/java/org/apache/maven/plugin/AbstractMojoExecutionException.java index 52aded3d654d..e8df3095f212 100644 --- a/maven-plugin-api/src/main/java/org/apache/maven/plugin/AbstractMojoExecutionException.java +++ b/maven-plugin-api/src/main/java/org/apache/maven/plugin/AbstractMojoExecutionException.java @@ -41,6 +41,18 @@ public AbstractMojoExecutionException( String message, Throwable cause ) super( message, cause ); } + /** + * Constructs a new {@code AbstractMojoExecutionException} exception wrapping an underlying {@code Throwable}. + * + * @param cause the cause which is saved for later retrieval by the {@link #getCause()} method. + * A {@code null} value is permitted, and indicates that the cause is nonexistent or unknown. + * @since 3.8.3 + */ + public AbstractMojoExecutionException( Throwable cause ) + { + super( cause ); + } + public String getLongMessage() { return longMessage; diff --git a/maven-plugin-api/src/main/java/org/apache/maven/plugin/MojoExecutionException.java b/maven-plugin-api/src/main/java/org/apache/maven/plugin/MojoExecutionException.java index 4d8c416e077d..6d089898600c 100644 --- a/maven-plugin-api/src/main/java/org/apache/maven/plugin/MojoExecutionException.java +++ b/maven-plugin-api/src/main/java/org/apache/maven/plugin/MojoExecutionException.java @@ -76,4 +76,17 @@ public MojoExecutionException( String message ) { super( message ); } + + /** + * Constructs a new {@code MojoExecutionException} exception wrapping an underlying {@code Throwable}. + * + * @param cause the cause which is saved for later retrieval by the {@link #getCause()} method. + * A {@code null} value is permitted, and indicates that the cause is nonexistent or unknown. + * @since 3.8.3 + */ + public MojoExecutionException( Throwable cause ) + { + super( cause ); + } + } diff --git a/maven-plugin-api/src/main/java/org/apache/maven/plugin/MojoFailureException.java b/maven-plugin-api/src/main/java/org/apache/maven/plugin/MojoFailureException.java index 342d081f00b2..72faec679eb9 100644 --- a/maven-plugin-api/src/main/java/org/apache/maven/plugin/MojoFailureException.java +++ b/maven-plugin-api/src/main/java/org/apache/maven/plugin/MojoFailureException.java @@ -65,4 +65,17 @@ public MojoFailureException( String message, Throwable cause ) { super( message, cause ); } + + /** + * Constructs a new {@code MojoFailureException} exception wrapping an underlying {@code Throwable}. + * + * @param cause the cause which is saved for later retrieval by the {@link #getCause()} method. + * A {@code null} value is permitted, and indicates that the cause is nonexistent or unknown. + * @since 3.8.3 + */ + public MojoFailureException( Throwable cause ) + { + super( cause ); + } + } From 0a6bbb8301717d386e6588a7ea32e3e2451c7060 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 9 Sep 2021 16:10:25 +0200 Subject: [PATCH 089/188] [MNG-7235] Speed improvements when calculating the sorted project graph This closes #530 --- .../graph/DefaultProjectDependencyGraph.java | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java b/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java index e0067f1fe4ae..7804312c9f90 100644 --- a/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java +++ b/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java @@ -22,8 +22,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Set; @@ -42,9 +45,13 @@ public class DefaultProjectDependencyGraph implements ProjectDependencyGraph { - private ProjectSorter sorter; + private final ProjectSorter sorter; - private List allProjects; + private final List allProjects; + + private final Map order; + + private final Map projects; /** * Creates a new project dependency graph based on the specified projects. @@ -59,6 +66,16 @@ public DefaultProjectDependencyGraph( Collection projects ) super(); this.allProjects = Collections.unmodifiableList( new ArrayList<>( projects ) ); this.sorter = new ProjectSorter( projects ); + List sorted = this.sorter.getSortedProjects(); + this.order = new HashMap<>( sorted.size() ); + this.projects = new HashMap<>( sorted.size() ); + int index = 0; + for ( MavenProject project : sorted ) + { + String id = ProjectSorter.getId( project ); + this.projects.put( id, project ); + this.order.put( project, index++ ); + } } /** @@ -78,6 +95,16 @@ public DefaultProjectDependencyGraph( final List allProjects, super(); this.allProjects = Collections.unmodifiableList( new ArrayList<>( allProjects ) ); this.sorter = new ProjectSorter( projects ); + List sorted = this.sorter.getSortedProjects(); + this.order = new HashMap<>( sorted.size() ); + this.projects = new HashMap<>( sorted.size() ); + int index = 0; + for ( MavenProject project : sorted ) + { + String id = ProjectSorter.getId( project ); + this.projects.put( id, project ); + this.order.put( project, index++ ); + } } /** @@ -140,15 +167,13 @@ private void getUpstreamProjects( String projectId, Collection projectId private List getSortedProjects( Set projectIds ) { List result = new ArrayList<>( projectIds.size() ); - - for ( MavenProject mavenProject : sorter.getSortedProjects() ) + for ( String projectId : projectIds ) { - if ( projectIds.contains( ProjectSorter.getId( mavenProject ) ) ) - { - result.add( mavenProject ); - } + result.add( projects.get( projectId ) ); } + Collections.sort( result, new MavenProjectComparator() ); + return result; } @@ -158,4 +183,12 @@ public String toString() return sorter.getSortedProjects().toString(); } + private class MavenProjectComparator implements Comparator + { + @Override + public int compare( MavenProject o1, MavenProject o2 ) + { + return order.get( o1 ) - order.get( o2 ); + } + } } From ff8e977a158738155dc465c6a97ffaf31982d739 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Mon, 27 Sep 2021 20:28:25 +0200 Subject: [PATCH 090/188] [maven-release-plugin] prepare release maven-3.8.3 --- apache-maven/pom.xml | 2 +- maven-artifact/pom.xml | 2 +- maven-builder-support/pom.xml | 2 +- maven-compat/pom.xml | 2 +- maven-core/pom.xml | 2 +- maven-embedder/pom.xml | 2 +- maven-model-builder/pom.xml | 2 +- maven-model/pom.xml | 2 +- maven-plugin-api/pom.xml | 2 +- maven-repository-metadata/pom.xml | 2 +- maven-resolver-provider/pom.xml | 2 +- maven-settings-builder/pom.xml | 2 +- maven-settings/pom.xml | 2 +- maven-slf4j-provider/pom.xml | 2 +- pom.xml | 6 +++--- 15 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index b6068d0fc972..c17f8a6d5e6a 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 apache-maven diff --git a/maven-artifact/pom.xml b/maven-artifact/pom.xml index 5203f1b79592..6cf8468499a4 100644 --- a/maven-artifact/pom.xml +++ b/maven-artifact/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-artifact diff --git a/maven-builder-support/pom.xml b/maven-builder-support/pom.xml index 191bfc5967d0..959d8ec3fc84 100644 --- a/maven-builder-support/pom.xml +++ b/maven-builder-support/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-builder-support diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index 46259815a4fe..75e2289d2f06 100644 --- a/maven-compat/pom.xml +++ b/maven-compat/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-compat diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 748ce6cd3960..d4c5111666c3 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-core diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 7a3cc7e0d14a..1c632c93f884 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-embedder diff --git a/maven-model-builder/pom.xml b/maven-model-builder/pom.xml index 06d42d38e31b..8cb1008a6675 100644 --- a/maven-model-builder/pom.xml +++ b/maven-model-builder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-model-builder diff --git a/maven-model/pom.xml b/maven-model/pom.xml index 0e002c0c2f5e..df81d72f91c0 100644 --- a/maven-model/pom.xml +++ b/maven-model/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-model diff --git a/maven-plugin-api/pom.xml b/maven-plugin-api/pom.xml index a0a708926b69..a1a72a1967b4 100644 --- a/maven-plugin-api/pom.xml +++ b/maven-plugin-api/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-plugin-api diff --git a/maven-repository-metadata/pom.xml b/maven-repository-metadata/pom.xml index b4ac0f489b00..4b4cc2b88999 100644 --- a/maven-repository-metadata/pom.xml +++ b/maven-repository-metadata/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-repository-metadata diff --git a/maven-resolver-provider/pom.xml b/maven-resolver-provider/pom.xml index ca317a9edeca..52e94e5c3c7b 100644 --- a/maven-resolver-provider/pom.xml +++ b/maven-resolver-provider/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-resolver-provider diff --git a/maven-settings-builder/pom.xml b/maven-settings-builder/pom.xml index dd0c09bb9ce8..677c13999c0c 100644 --- a/maven-settings-builder/pom.xml +++ b/maven-settings-builder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-settings-builder diff --git a/maven-settings/pom.xml b/maven-settings/pom.xml index 6fa967c38ca3..b77437c27c9a 100644 --- a/maven-settings/pom.xml +++ b/maven-settings/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-settings diff --git a/maven-slf4j-provider/pom.xml b/maven-slf4j-provider/pom.xml index 802d226c9c0a..eea89b72de1e 100644 --- a/maven-slf4j-provider/pom.xml +++ b/maven-slf4j-provider/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3-SNAPSHOT + 3.8.3 maven-slf4j-provider diff --git a/pom.xml b/pom.xml index 65f5d22411a2..f584a2e60d55 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ under the License. maven - 3.8.3-SNAPSHOT + 3.8.3 pom Apache Maven @@ -77,7 +77,7 @@ under the License. ref/3-LATEST None **/package-info.java - 2021-08-04T19:03:41Z + 2021-09-27T18:25:22Z @@ -101,7 +101,7 @@ under the License. scm:git:https://gitbox.apache.org/repos/asf/maven.git scm:git:https://gitbox.apache.org/repos/asf/maven.git https://github.com/apache/maven/tree/${project.scm.tag} - maven-3.8.2 + maven-3.8.3 jira From 21e597ec777f0b74eed4e067b58b6eb8b0c9fad4 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Mon, 27 Sep 2021 20:28:37 +0200 Subject: [PATCH 091/188] [maven-release-plugin] prepare for next development iteration --- apache-maven/pom.xml | 2 +- maven-artifact/pom.xml | 2 +- maven-builder-support/pom.xml | 2 +- maven-compat/pom.xml | 2 +- maven-core/pom.xml | 2 +- maven-embedder/pom.xml | 2 +- maven-model-builder/pom.xml | 2 +- maven-model/pom.xml | 2 +- maven-plugin-api/pom.xml | 2 +- maven-repository-metadata/pom.xml | 2 +- maven-resolver-provider/pom.xml | 2 +- maven-settings-builder/pom.xml | 2 +- maven-settings/pom.xml | 2 +- maven-slf4j-provider/pom.xml | 2 +- pom.xml | 4 ++-- 15 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index c17f8a6d5e6a..5f713bb71c29 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT apache-maven diff --git a/maven-artifact/pom.xml b/maven-artifact/pom.xml index 6cf8468499a4..68af732ea550 100644 --- a/maven-artifact/pom.xml +++ b/maven-artifact/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-artifact diff --git a/maven-builder-support/pom.xml b/maven-builder-support/pom.xml index 959d8ec3fc84..897fe185f4bc 100644 --- a/maven-builder-support/pom.xml +++ b/maven-builder-support/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-builder-support diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index 75e2289d2f06..221bf2c19ccd 100644 --- a/maven-compat/pom.xml +++ b/maven-compat/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-compat diff --git a/maven-core/pom.xml b/maven-core/pom.xml index d4c5111666c3..86aea1ff2319 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-core diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 1c632c93f884..af2cd81ce593 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-embedder diff --git a/maven-model-builder/pom.xml b/maven-model-builder/pom.xml index 8cb1008a6675..e08f1af28731 100644 --- a/maven-model-builder/pom.xml +++ b/maven-model-builder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-model-builder diff --git a/maven-model/pom.xml b/maven-model/pom.xml index df81d72f91c0..f7e07c866bac 100644 --- a/maven-model/pom.xml +++ b/maven-model/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-model diff --git a/maven-plugin-api/pom.xml b/maven-plugin-api/pom.xml index a1a72a1967b4..630a46cf283b 100644 --- a/maven-plugin-api/pom.xml +++ b/maven-plugin-api/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-plugin-api diff --git a/maven-repository-metadata/pom.xml b/maven-repository-metadata/pom.xml index 4b4cc2b88999..0c9e5318dc62 100644 --- a/maven-repository-metadata/pom.xml +++ b/maven-repository-metadata/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-repository-metadata diff --git a/maven-resolver-provider/pom.xml b/maven-resolver-provider/pom.xml index 52e94e5c3c7b..f941dd0e3577 100644 --- a/maven-resolver-provider/pom.xml +++ b/maven-resolver-provider/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-resolver-provider diff --git a/maven-settings-builder/pom.xml b/maven-settings-builder/pom.xml index 677c13999c0c..2ffbd9457d8e 100644 --- a/maven-settings-builder/pom.xml +++ b/maven-settings-builder/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-settings-builder diff --git a/maven-settings/pom.xml b/maven-settings/pom.xml index b77437c27c9a..c585d573387f 100644 --- a/maven-settings/pom.xml +++ b/maven-settings/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-settings diff --git a/maven-slf4j-provider/pom.xml b/maven-slf4j-provider/pom.xml index eea89b72de1e..e63956fcf359 100644 --- a/maven-slf4j-provider/pom.xml +++ b/maven-slf4j-provider/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven maven - 3.8.3 + 3.8.4-SNAPSHOT maven-slf4j-provider diff --git a/pom.xml b/pom.xml index f584a2e60d55..a5848644d563 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ under the License. maven - 3.8.3 + 3.8.4-SNAPSHOT pom Apache Maven @@ -77,7 +77,7 @@ under the License. ref/3-LATEST None **/package-info.java - 2021-09-27T18:25:22Z + 2021-09-27T18:28:35Z From b6186e2c7714158b5a2709f4af9d40b194c53f55 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Mon, 27 Sep 2021 22:16:35 +0200 Subject: [PATCH 092/188] Remove swap file --- .../src/main/assembly/.component.xml.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 apache-maven/src/main/assembly/.component.xml.swp diff --git a/apache-maven/src/main/assembly/.component.xml.swp b/apache-maven/src/main/assembly/.component.xml.swp deleted file mode 100644 index 52c487e4a78f44dad9a6220103ec18dab7e0e89c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2Ux*t;9LJ|sYpb?O1w{mz#)@sd?B=c%+iN^X?{XNt>p#tp?;n+atIrV|a#CCfJl4>gbba*>_Y%xqgrOqiBu*)5js7nErf z)0S;d3MRDCZM%tQre9M9QUyj(AkdBM;hhTyC&qK3^@Eu`^zPjYBQ#7+QUy{4QUy{4 zQUy{4QUy{4QUy{4ZWINyw}m{1V7A5qHRI1MD?a05`jIM-Dv&CWDv&CWDv&CWDv&CW zDv&CWDv&CWD)2v4z;X!r34XsB{sI7h{~!GS|H_?&dC3Q@E!beJ0V|#3*cFB7VHQ2g00}k+X%S`UIEX5BVZT!V+SGM zf-k_Q;C*l&ya0S)g9Weye7T*F&%s;ZMG$}nI1L^Kzu!v8_uw;d5nKT0z#_S zWg8(sfUm&YKm!{T!9lPW+yj2Tg^*9cyWmyefv3PxFa{m~zugR7`z9zO{FPsEEuR3HB9!LM26tJNX%&_d<$e(r zGSFV2XSmO7E&bk<%jyQWQ|%?uTlDe+lYy?V z*ptoDT8k@+e@ar_vNWA8QPoqLwH383K|SVk>2TX}-5&J=0V75|UxrTmG@DI4Ez#c$ zs|U@sdQ8}?x;=1s7{jW}*SQ!q6OrjA6Oqu>k!sUAA29mqAH*2vCXoqPw4MK6+=G!Z z6h7(lfot#=ubsJQ3B|L*(tL@Hk~D4kO{PtUc}zG=*gZ3EZZdz@J&wARdK138+{RHk zrp$i3f7|;J=gC<3q4U==XRfDwWxiILF0L9yi7_^Z`<3cylZ__?1A}Dal^~8VI*^!E zEz4(4*7EHZMrPJ$N(R1-q?L=cLbgqn|_DL1W}2X=-CZYFU9YJePF?HQE2j+Ahv&oBgGFd%@2lqTbw^~NSaguo)&*blhGpxihUF?u9&6l*y3DVk!V19#(G7>+T60_| z%_#A%nAkTSp6kyaYlOAwfUlMy3a+d8q{0E*wlybhOute*mT772O`84lxkmqdu7Rk{ zLbX~fADcUqot`frpRW`vHFLtq89Dk-4Z6x1p5)CAPx5A?Mh0$XrbvERO>w|isLl7D z={KB2B*Vs?PRHmRjGUgpxn%Qnd9E4-ndL%hOV}(!!re%K#lw#_DRceV*dWSdHg9m7 zx|V1LR+G`DTw=b!hAQ0Nw7F6cNl{BU)a7liBheIjqEwj~ql{z6<5Sl4FjXijeahRO z%b8Z=ytVyO&rKM_y9xGH!)iHXiRC|1Wp+-*?PMj!IYNcY8&Yz&u^Oc!W ztu$XjX_gi$XNZyw-NEcc9j>&`>w#ttT@_HcSxXv70nf>Ta6|We_H=+9utV!TYI*R} zw(2fJo3I7Ux0KTITrk91#{2A?%8KioG*-uS%P(o}W?%v#)o(=}{m3)NX9y}xcR zdq9!`$Kk>`OnhgfBwLOH@uaX^IEk#cqai~eaa$sP*a!CWhl=>&eeH3SUaQ2w>937Z k&?Jr{N)NoJad_3ipqP~iJ?e+ Date: Wed, 29 Sep 2021 11:29:35 +0100 Subject: [PATCH 093/188] [MNG-7270] Switch to shell alternative to "which" In some circumstances the init script calls `which`, which may or may not be available on the host system. Instead, use `command -v`, which is nearly equivalent. One area it differs is if the command being queried is defined as a shell alias. To avoid that, call `unset -f command` to avoid the situation where "command" has been re-defined as a shell function. See here for more information on this approach: Tested with bash, sh (bash invoked as sh), posh, dash, zsh and mksh. This closes #556 --- apache-maven/src/bin/mvn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn index 90f9a758d9cf..dfa384b8e141 100755 --- a/apache-maven/src/bin/mvn +++ b/apache-maven/src/bin/mvn @@ -94,7 +94,7 @@ if $mingw ; then fi if [ -z "$JAVA_HOME" ] ; then - JAVACMD=`which java` + JAVACMD="`\\unset -f command; \\command -v java`" else JAVACMD="$JAVA_HOME/bin/java" fi From 5c36bf5ef78a162cefea47ccdaf0d28e01c1426c Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sat, 16 Oct 2021 15:21:28 +0200 Subject: [PATCH 094/188] [MNG-7312] Revert ThreadLocal approach from MNG-6843 and MNG-7251 Revert "[MNG-7251] Fix threadLocalArtifactsHolder leaking into cloned project" This reverts commit 4e5b3d55545e5f03f05ac7b0cd1b56689df36201. Revert "[MNG-6843] Parallel build fails due to missing JAR artifacts in compilePath" This reverts commit 76d5f0d942f52650d3bdf775b6af42d23d69066b. === This closes #595 --- .../apache/maven/project/MavenProject.java | 102 +++++++++--------- .../maven/project/MavenProjectTest.java | 43 -------- 2 files changed, 48 insertions(+), 97 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index 94d678814534..db0f4a90116f 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -92,9 +92,13 @@ public class MavenProject implements Cloneable { + private static final Logger LOGGER = LoggerFactory.getLogger( MavenProject.class ); + public static final String EMPTY_PROJECT_GROUP_ID = "unknown"; + public static final String EMPTY_PROJECT_ARTIFACT_ID = "empty-project"; + public static final String EMPTY_PROJECT_VERSION = "0"; private Model model; @@ -107,6 +111,10 @@ public class MavenProject private Set resolvedArtifacts; + private ArtifactFilter artifactFilter; + + private Set artifacts; + private Artifact parentArtifact; private Set pluginArtifacts; @@ -143,7 +151,8 @@ public class MavenProject private Artifact artifact; - private ThreadLocal threadLocalArtifactsHolder = newThreadLocalArtifactsHolder(); + // calculated. + private Map artifactMap; private Model originalModel; @@ -176,21 +185,12 @@ public class MavenProject public MavenProject() { Model model = new Model(); + model.setGroupId( EMPTY_PROJECT_GROUP_ID ); model.setArtifactId( EMPTY_PROJECT_ARTIFACT_ID ); model.setVersion( EMPTY_PROJECT_VERSION ); - setModel( model ); - } - private static ThreadLocal newThreadLocalArtifactsHolder() - { - return new ThreadLocal() - { - protected ArtifactsHolder initialValue() - { - return new ArtifactsHolder(); - } - }; + setModel( model ); } public MavenProject( Model model ) @@ -695,11 +695,10 @@ public void addLicense( License license ) public void setArtifacts( Set artifacts ) { - ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder.get(); - artifactsHolder.artifacts = artifacts; + this.artifacts = artifacts; // flush the calculated artifactMap - artifactsHolder.artifactMap = null; + artifactMap = null; } /** @@ -712,36 +711,34 @@ public void setArtifacts( Set artifacts ) */ public Set getArtifacts() { - ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder.get(); - if ( artifactsHolder.artifacts == null ) + if ( artifacts == null ) { - if ( artifactsHolder.artifactFilter == null || resolvedArtifacts == null ) + if ( artifactFilter == null || resolvedArtifacts == null ) { - artifactsHolder.artifacts = new LinkedHashSet<>(); + artifacts = new LinkedHashSet<>(); } else { - artifactsHolder.artifacts = new LinkedHashSet<>( resolvedArtifacts.size() * 2 ); + artifacts = new LinkedHashSet<>( resolvedArtifacts.size() * 2 ); for ( Artifact artifact : resolvedArtifacts ) { - if ( artifactsHolder.artifactFilter.include( artifact ) ) + if ( artifactFilter.include( artifact ) ) { - artifactsHolder.artifacts.add( artifact ); + artifacts.add( artifact ); } } } } - return artifactsHolder.artifacts; + return artifacts; } public Map getArtifactMap() { - ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder.get(); - if ( artifactsHolder.artifactMap == null ) + if ( artifactMap == null ) { - artifactsHolder.artifactMap = ArtifactUtils.artifactMapByVersionlessId( getArtifacts() ); + artifactMap = ArtifactUtils.artifactMapByVersionlessId( getArtifacts() ); } - return artifactsHolder.artifactMap; + return artifactMap; } public void setPluginArtifacts( Set pluginArtifacts ) @@ -1186,8 +1183,7 @@ public MavenProject clone() { throw new UnsupportedOperationException( e ); } - // clone must have it's own TL, otherwise the artifacts are intermingled! - clone.threadLocalArtifactsHolder = newThreadLocalArtifactsHolder(); + clone.deepCopy( this ); return clone; @@ -1230,7 +1226,6 @@ private void deepCopy( MavenProject project ) // copy fields file = project.file; basedir = project.basedir; - threadLocalArtifactsHolder.set( project.threadLocalArtifactsHolder.get().copy() ); // don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be // sure! @@ -1239,6 +1234,11 @@ private void deepCopy( MavenProject project ) setDependencyArtifacts( Collections.unmodifiableSet( project.getDependencyArtifacts() ) ); } + if ( project.getArtifacts() != null ) + { + setArtifacts( Collections.unmodifiableSet( project.getArtifacts() ) ); + } + if ( project.getParentFile() != null ) { parentFile = new File( project.getParentFile().getAbsolutePath() ); @@ -1433,9 +1433,8 @@ public DependencyFilter getExtensionDependencyFilter() public void setResolvedArtifacts( Set artifacts ) { this.resolvedArtifacts = ( artifacts != null ) ? artifacts : Collections.emptySet(); - ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder.get(); - artifactsHolder.artifacts = null; - artifactsHolder.artifactMap = null; + this.artifacts = null; + this.artifactMap = null; } /** @@ -1448,10 +1447,9 @@ public void setResolvedArtifacts( Set artifacts ) */ public void setArtifactFilter( ArtifactFilter artifactFilter ) { - ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder.get(); - artifactsHolder.artifactFilter = artifactFilter; - artifactsHolder.artifacts = null; - artifactsHolder.artifactMap = null; + this.artifactFilter = artifactFilter; + this.artifacts = null; + this.artifactMap = null; } /** @@ -1481,7 +1479,13 @@ public void addLifecyclePhase( String lifecyclePhase ) // ---------------------------------------------------------------------------------------------------------------- // - // D E P R E C A T E D - Everything below will be removed for Maven 4.0.0 + // + // D E P R E C A T E D + // + // + // ---------------------------------------------------------------------------------------------------------------- + // + // Everything below will be removed for Maven 4.0.0 // // ---------------------------------------------------------------------------------------------------------------- @@ -1502,6 +1506,7 @@ public String getModulePathAdjustment( MavenProject moduleProject ) if ( moduleFile != null ) { File moduleDir = moduleFile.getCanonicalFile().getParentFile(); + module = moduleDir.getName(); } @@ -1822,6 +1827,7 @@ public Reporting getReporting() public void setReportArtifacts( Set reportArtifacts ) { this.reportArtifacts = reportArtifacts; + reportArtifactMap = null; } @@ -1838,6 +1844,7 @@ public Map getReportArtifactMap() { reportArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getReportArtifacts() ); } + return reportArtifactMap; } @@ -1845,6 +1852,7 @@ public Map getReportArtifactMap() public void setExtensionArtifacts( Set extensionArtifacts ) { this.extensionArtifacts = extensionArtifacts; + extensionArtifactMap = null; } @@ -1861,6 +1869,7 @@ public Map getExtensionArtifactMap() { extensionArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getExtensionArtifacts() ); } + return extensionArtifactMap; } @@ -1878,6 +1887,7 @@ public List getReportPlugins() public Xpp3Dom getReportConfiguration( String pluginGroupId, String pluginArtifactId, String reportSetId ) { Xpp3Dom dom = null; + // ---------------------------------------------------------------------- // I would like to be able to lookup the Mojo object using a key but // we have a limitation in modello that will be remedied shortly. So @@ -1981,20 +1991,4 @@ public void setProjectBuildingRequest( ProjectBuildingRequest projectBuildingReq { this.projectBuilderConfiguration = projectBuildingRequest; } - - private static class ArtifactsHolder - { - private ArtifactFilter artifactFilter; - private Set artifacts; - private Map artifactMap; - - ArtifactsHolder copy() - { - ArtifactsHolder copy = new ArtifactsHolder(); - copy.artifactFilter = artifactFilter; - copy.artifacts = artifacts != null ? new LinkedHashSet<>( artifacts ) : null; - copy.artifactMap = artifactMap != null ? new LinkedHashMap<>( artifactMap ) : null; - return copy; - } - } } diff --git a/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java b/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java index 2344d8f77345..6b4258b3fde9 100644 --- a/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/MavenProjectTest.java @@ -21,18 +21,13 @@ import java.io.File; import java.io.IOException; -import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; -import org.apache.maven.artifact.Artifact; import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.model.Profile; -import org.mockito.Mockito; public class MavenProjectTest extends AbstractMavenProjectTestCase @@ -193,44 +188,6 @@ public void testCloneWithBaseDir() assertEquals( "Base directory is preserved across clone", projectToClone.getBasedir(), clonedProject.getBasedir() ); } - public void testCloneWithArtifacts() - throws InterruptedException - { - Artifact initialArtifact = Mockito.mock( Artifact.class, "initialArtifact" ); - MavenProject originalProject = new MavenProject(); - originalProject.setArtifacts( Collections.singleton( initialArtifact ) ); - assertEquals( "Sanity check: originalProject returns artifact that has just been set", - Collections.singleton( initialArtifact ), originalProject.getArtifacts() ); - - final MavenProject clonedProject = originalProject.clone(); - - assertEquals( "Cloned project returns the artifact that was set for the original project", - Collections.singleton( initialArtifact ), clonedProject.getArtifacts() ); - - Artifact anotherArtifact = Mockito.mock( Artifact.class, "anotherArtifact" ); - clonedProject.setArtifacts( Collections.singleton( anotherArtifact ) ); - assertEquals( "Sanity check: clonedProject returns artifact that has just been set", - Collections.singleton( anotherArtifact ), clonedProject.getArtifacts() ); - - assertEquals( "Original project returns the artifact that was set initially (not the one for clonedProject)", - Collections.singleton( initialArtifact ), originalProject.getArtifacts() ); - - final AtomicReference> artifactsFromThread = new AtomicReference<>(); - Thread thread = new Thread( new Runnable() - { - @Override - public void run() - { - artifactsFromThread.set( clonedProject.getArtifacts() ); - } - } ); - thread.start(); - thread.join(); - - assertEquals( "Another thread does not see the same artifacts", - Collections.emptySet(), artifactsFromThread.get() ); - } - public void testUndefinedOutputDirectory() throws Exception { From c9a03660f83981a3fa71e50178c8aeae67d26219 Mon Sep 17 00:00:00 2001 From: Maximilian Novikov Date: Tue, 10 Aug 2021 20:10:28 +0200 Subject: [PATCH 095/188] Merge pull request #4 in ABFX/maven-forked from incremental-maven-3.6.3 to MNG-7129/maven-3.6.3-incremental Squashed commit of the following: commit 21c620a34ddbbf84b3c44014b069a7b222cf91a7 Author: Maximilian Novikov Date: Tue Aug 10 19:41:41 2021 +0200 Merge pull request #3 in ABFX/maven-forked from code-cleanup-2 to incremental-maven-3.6.3 Squashed commit of the following: commit 3401739ec9eb957fb03887f6a3c24477c9c3327b Author: Alexander Ashitkin Date: Tue Aug 10 13:37:13 2021 -0400 cleanup db specifics commit 5d32f00559951445ecaf7d5ec4d847541c10e7e9 Author: Alexander Ashitkin Date: Tue Aug 10 11:05:28 2021 -0400 cleanup db specifics commit fcec28f82c0d447de64032c610b39fa75bb344b0 Merge: 6fd401af2 5b0dc1858 Author: Alexander Ashitkin Date: Mon Aug 9 13:22:16 2021 +0100 Pull request #9: Remote cache setup Merge in BND/maven-forked from feature/remote-cache-setup to incremental-maven-3.6.3 * commit '5b0dc1858cf4ca499502f0741b2f3bf2ac55530c': remote cache setup - fail fast, baseline build, diff reporting, documentation. commit 5b0dc1858cf4ca499502f0741b2f3bf2ac55530c Author: Alexander Ashitkin Date: Mon Mar 22 03:30:03 2021 +0100 remote cache setup - fail fast, baseline build, diff reporting, documentation. commit 6fd401af285692df568312ee66ee00edfe21f1cc Author: Maximilian Novikov Date: Tue Apr 13 17:36:49 2021 +0100 Pull request #8: Incremental Maven - added non-overrideable cache entries Merge in BND/maven-forked from non-overritable-build-info to incremental-maven-3.6.3 Squashed commit of the following: commit 405bbef8a59cabc0b83e9a64717f65fbd6fb9e3d Author: maximilian.novikov@db.com Date: Mon Apr 12 20:18:27 2021 +0200 Incremental Maven - added non-overrideable cache entries - review fixes commit 197704672756e558fb3521e16859d0be324044b8 Author: maximilian.novikov@db.com Date: Fri Apr 9 11:35:48 2021 +0200 Incremental Maven - added non-overrideable cache entries commit 64c4b1f5cbdf920ad43560f34cc5be56d4557acf Author: Alexander Ashitkin Date: Tue Mar 9 04:10:20 2021 +0100 injected version commit 727e507ae2fd90dce7011f3f1c76eb4969577d5e Author: maximilian.novikov@db.com Date: Wed Jan 13 16:17:25 2021 +0100 Incremental Maven - Java 11 fix commit b2f297566d5afcb0a285985cb5540685a28cafec Author: maximilian.novikov@db.com Date: Tue Jan 12 14:10:08 2021 +0100 Incremental Maven - initial commit --- .gitignore | 1 + Documentation/CACHE-HOWTO.md | 204 ++++ Documentation/CACHE-PARAMETERS.md | 52 + Documentation/CACHE-REMOTE.md | 249 +++++ Documentation/CACHE.md | 170 ++++ Documentation/maven-cache-config.xml | 102 ++ README.md | 5 + .../appended-resources/META-INF/LICENSE.vm | 3 +- .../appended-resources/licenses/EDL-1.0.txt | 23 + .../appended-resources/licenses/GPL-3.0.txt | 674 +++++++++++++ .../appended-resources/licenses/LGPL-3.0.txt | 165 +++ .../appended-resources/licenses/MPL-1.1.txt | 472 +++++++++ maven-core/pom.xml | 47 + .../maven/caching/ArtifactsRepository.java | 42 + .../apache/maven/caching/CacheContext.java | 58 ++ .../apache/maven/caching/CacheController.java | 52 + .../maven/caching/CacheControllerImpl.java | 942 +++++++++++++++++ .../org/apache/maven/caching/CacheDiff.java | 345 +++++++ .../apache/maven/caching/CacheEventSpy.java | 49 + .../org/apache/maven/caching/CacheResult.java | 122 +++ .../java/org/apache/maven/caching/Clock.java | 42 + .../caching/DefaultPluginScanConfig.java | 63 ++ .../maven/caching/HttpRepositoryImpl.java | 336 +++++++ .../caching/LocalArtifactsRepository.java | 47 + .../maven/caching/LocalRepositoryImpl.java | 496 +++++++++ .../maven/caching/MojoExecutionManager.java | 178 ++++ .../maven/caching/MojoParametersListener.java | 102 ++ .../maven/caching/PluginScanConfig.java | 41 + .../maven/caching/PluginScanConfigImpl.java | 161 +++ .../apache/maven/caching/ProjectUtils.java | 197 ++++ .../caching/RemoteArtifactsRepository.java | 42 + .../apache/maven/caching/RestoreStatus.java | 31 + .../maven/caching/ScanConfigProperties.java | 45 + .../org/apache/maven/caching/ZipUtils.java | 116 +++ .../DependencyNotResolvedException.java | 31 + .../maven/caching/checksum/DigestUtils.java | 189 ++++ .../maven/caching/checksum/KeyUtils.java | 64 ++ .../caching/checksum/MavenProjectInput.java | 950 ++++++++++++++++++ .../MultimoduleDiscoveryStrategy.java | 33 + .../maven/caching/checksum/WalkKey.java | 95 ++ .../maven/caching/hash/CloseableBuffer.java | 185 ++++ .../org/apache/maven/caching/hash/Hash.java | 61 ++ .../maven/caching/hash/HashAlgorithm.java | 46 + .../maven/caching/hash/HashChecksum.java | 67 ++ .../maven/caching/hash/HashFactory.java | 79 ++ .../apache/maven/caching/hash/HexUtils.java | 56 ++ .../maven/caching/hash/ReflectionUtils.java | 61 ++ .../org/apache/maven/caching/hash/SHA.java | 103 ++ .../maven/caching/hash/ThreadLocalBuffer.java | 86 ++ .../maven/caching/hash/ThreadLocalDigest.java | 71 ++ .../org/apache/maven/caching/hash/XX.java | 98 ++ .../org/apache/maven/caching/hash/XXMM.java | 67 ++ .../maven/caching/xml/AllExternalSrategy.java | 42 + .../apache/maven/caching/xml/BuildInfo.java | 273 +++++ .../apache/maven/caching/xml/CacheConfig.java | 108 ++ .../maven/caching/xml/CacheConfigImpl.java | 579 +++++++++++ .../apache/maven/caching/xml/CacheSource.java | 30 + .../apache/maven/caching/xml/CacheState.java | 30 + .../apache/maven/caching/xml/DtoUtils.java | 219 ++++ .../caching/xml/SentinelVersionStartegy.java | 51 + .../apache/maven/caching/xml/XmlService.java | 145 +++ .../maven/graph/DefaultGraphBuilder.java | 73 ++ .../lifecycle/internal/DependencyContext.java | 21 +- .../internal/IDependencyContext.java | 47 + .../lifecycle/internal/MojoExecutor.java | 266 ++++- .../internal/NoResolutionContext.java | 88 ++ .../plugin/DefaultBuildPluginManager.java | 40 +- .../org/apache/maven/plugin/MojoCheker.java | 38 + .../apache/maven/plugin/MojoExecution.java | 24 +- .../maven/project/DefaultProjectBuilder.java | 31 +- .../apache/maven/project/MavenProject.java | 12 + .../main/resources/cache-config-instance.xml | 92 ++ .../src/main/resources/cache-config.xsd | 620 ++++++++++++ .../main/resources/cache-domain-instance.xml | 44 + .../src/main/resources/cache-domain.xsd | 167 +++ .../apache/maven/caching/BuildInfoTest.java | 113 +++ .../checksum/MavenProjectInputTest.java | 85 ++ .../maven/caching/checksum/SHAHashTest.java | 72 ++ .../maven/caching/checksum/XXHashTest.java | 132 +++ .../maven/caching/hash/HexUtilsTest.java | 50 + .../maven/caching/xml/CacheConfigTest.java | 35 + .../internal/stub/MojoExecutorStub.java | 9 +- pom.xml | 5 +- 83 files changed, 11472 insertions(+), 85 deletions(-) create mode 100644 Documentation/CACHE-HOWTO.md create mode 100644 Documentation/CACHE-PARAMETERS.md create mode 100644 Documentation/CACHE-REMOTE.md create mode 100644 Documentation/CACHE.md create mode 100644 Documentation/maven-cache-config.xml create mode 100644 apache-maven/src/main/appended-resources/licenses/EDL-1.0.txt create mode 100644 apache-maven/src/main/appended-resources/licenses/GPL-3.0.txt create mode 100644 apache-maven/src/main/appended-resources/licenses/LGPL-3.0.txt create mode 100644 apache-maven/src/main/appended-resources/licenses/MPL-1.1.txt create mode 100644 maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/CacheContext.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/CacheController.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/CacheResult.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/Clock.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/MojoParametersListener.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/RestoreStatus.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/ScanConfigProperties.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/ZipUtils.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/checksum/WalkKey.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/Hash.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/HashChecksum.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/HashFactory.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/HexUtils.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/SHA.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/XX.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/hash/XXMM.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/xml/CacheSource.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/xml/CacheState.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java create mode 100644 maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java create mode 100644 maven-core/src/main/java/org/apache/maven/lifecycle/internal/IDependencyContext.java create mode 100644 maven-core/src/main/java/org/apache/maven/lifecycle/internal/NoResolutionContext.java create mode 100644 maven-core/src/main/java/org/apache/maven/plugin/MojoCheker.java create mode 100644 maven-core/src/main/resources/cache-config-instance.xml create mode 100644 maven-core/src/main/resources/cache-config.xsd create mode 100644 maven-core/src/main/resources/cache-domain-instance.xml create mode 100644 maven-core/src/main/resources/cache-domain.xsd create mode 100644 maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java create mode 100644 maven-core/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java create mode 100644 maven-core/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java create mode 100644 maven-core/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java create mode 100644 maven-core/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java create mode 100644 maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java diff --git a/.gitignore b/.gitignore index f85dc5684299..5824f498a88d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ target/ .classpath .settings/ .svn/ +.cache/ bin/ # Intellij *.ipr diff --git a/Documentation/CACHE-HOWTO.md b/Documentation/CACHE-HOWTO.md new file mode 100644 index 000000000000..aa15f626af65 --- /dev/null +++ b/Documentation/CACHE-HOWTO.md @@ -0,0 +1,204 @@ + + +### Overview + +Cache configuration provides you additional control over incremental maven behavior. Follow it step by step to +understand how it works and figure out your optimal config + +### Minimal config + +Absolutely minimal config which enables incremental maven with local cache + +```xml + + + + + true + XX + + + + + {*.java,*.xml,*.properties} + + + +``` + +### Enabling remote cache + +Just add `` section under `` + +```xml + + + true + XX + + https://yourserver:port + + +``` + +### Adding more file types to input + +Add all the project specific source code files in ``. Scala in this case: + +```xml + + + + {*.java,*.xml,*.properties,*.scala} + + +``` + +### Adding source directory for bespoke project layouts + +In most of the cases incremental maven will recognize directories automatically by build introspection. If not, you can +add additional directories with ``. Also you can filter out undesirable dirs and files by using exclude tag + +```xml + + + + {*.java,*.xml,*.properties,*.scala} + importantdir/ + tempfile.out + + +``` + +### Plugin property is env specific (breaks checksum and caching) + +Consider to exclude env specific properties: + +```xml + + + + ... + + + + argLine + + + +``` + +Implications - builds with different `argLine` will have identical checksum. Validate that is semantically valid. + +### Plugin property points to directory where only subset of files is relevant + +If plugin configuration property points to `somedir` it will be scanned with default glob. You can tweak it with custom +processing rule + +```xml + + + + ... + + + + + + + + +``` + +### Local repository is not updated because `install` is cached + +Add `executionControl/runAlways` section + +```xml + + + + ... + + + ... + + + + + + unpack-autoupdate + + + install + + + + +``` + +### I occasionally cached build with `-DskipTests=true` and tests do not run now + +If you add command line flags to your build, they do not participate in effective pom - maven defers final value +resolution to plugin runtime. To invalidate build if filed value is different in runtime, add reconciliation section +to `executionControl`: + +```xml + + + + ... + + + + + + + + + + +``` + +Please notice `skipValue` attribute. It denotes value which forces skipped execution. +Read `propertyName="skipTests" skipValue="true"` as if property skipTests has value true, plugin will skip execution If +you declare such value incremental maven will reuse appropriate full-build though technically they are different, but +because full-build is better it is safe to reuse + +### How to renormalize line endings in working copy after committing .gitattributes (git 2.16+) + +Ensure you've committed (and ideally pushed everything) - no changes in working copy. After that: + +```shell +# Rewrite objects and update index +git add --renormalize . +# Commit changes +git commit -m "Normalizing line endings" +# Remove working copy paths from git cache +git rm --cached -r . +# Refresh with new line endings +git reset --hard +``` + +### I want to cache interim build and override it later with final version + +Solution: set `-Dremote.cache.save.final=true` to nodes which produce final builds. Such builds will not be overridden +and eventually will replace all interim builds \ No newline at end of file diff --git a/Documentation/CACHE-PARAMETERS.md b/Documentation/CACHE-PARAMETERS.md new file mode 100644 index 000000000000..7633ddbea158 --- /dev/null +++ b/Documentation/CACHE-PARAMETERS.md @@ -0,0 +1,52 @@ + + +# Overview + +This documents contains various configuration parameters supported by cache engine + +## Command line flags + +| Parameter | Description | Usage Scenario | +| ----------- | ----------- | ----------- | +| `-Dremote.cache.configPath=true/false` | Location of cache configuration file | Cache config is not in default location | +| `-Dremote.cache.enabled=true/false` | Remote cache and associated features disabled/enabled | To remove noise from logs then remote cache is not available | +| `-Dremote.cache.save.enabled=true/false` | Remote cache save allowed or not | To designate nodes which allowed to push in remote shared cache | +| `-Dremote.cache.save.final=true/false` | Is it allowed or not to override produced cache | To ensure that reference build is not overriden by interim build | +| `-Dremote.cache.failFast=true/false` | Fail on the first module whcih cannot be restored from cache | Remote cache setup/tuning/troubleshooting | +| `-Dremote.cache.baselineUrl=` | Location of baseline build for comparison | Remote cache setup/tuning/troubleshooting | + +## Project level properties + +Project level parameters allow overriding global parameters on project level Must be specified as project properties: + +```xml + + + ... + + {*.css} + + +``` + +| Parameter | Description | +| ----------------------------- | ----------- | +| `remote.cache.input.glob` | Project specific glob to select sources. Overrides global glob. | +| `remote.cache.input` | Property prefix to mark paths which must be additionally scanned for source code. Value of property starting with this prefix will be treated as path relatively to current project/module | +| `remote.cache.exclude` | Property prefix to mark paths which must be excluded from source code search. Value of property starting with this prefix will be treated as path to current project/module | +| `remote.cache.processPlugins` | Introspect plugins to find inputs or not. Default is true. | diff --git a/Documentation/CACHE-REMOTE.md b/Documentation/CACHE-REMOTE.md new file mode 100644 index 000000000000..f5fe38721d70 --- /dev/null +++ b/Documentation/CACHE-REMOTE.md @@ -0,0 +1,249 @@ + + +# Overview + +This document describes generic approach to cache setup. The process require expertise in maven equivalent to expertise +required to author and Maven your project build, it implies good knowledge of both Maven and the project. Due to Maven +model limitation the process is manual, but allows you to achieve sufficient control and transparency over caching +logic. + +# Step-By-Step + +## Fork branch for cache setup purposes + +It is recommended to fork branch for cache setup purposes as you might need to do changes to project build as long as +you go. + +## Setup http server to store artifacts + +In order to share build results you need shared storage. Basically any http server which supports http PUT/GET/HEAD +operations will work. In our case it is a Nginx OSS with file system module. Add the url to config and +change `remote@enabled` to true: + +```xml + + + http://your-buildcache-url + +``` + +Known limitations: auth is not supported yet + +## Build selection + +In order to share build results, you need a golden source of builds. Build stored in cache ideally should be a build +assembled in the most correct, comprehensive and complete way. In such a case you can make sure that whoever reuses such +build doesn't compromise quality of own build. Often per pull requests builds are the best candidates to populate cache +because they seed cache fast and provide sufficient quality safeguards. + +## CI Build setup to seed shared cache + +In order to share build results, you need to store builds in the shared storage. Default scheme is to configure +designated CI nodes only to push in cache and prohibit elsewhere. In order to allow writes in remote cache add jvm +property to designated CI builds. + +``` +-Dremote.cache.save.enabled=true +``` + +Run your branch, review log and ensure that artifacts are uploaded to remote cache. Now, rerun build and ensure that it +completes almost instantly because it is fully cached. Hint: consider limiting first attempts to single agent/node to +simplify troubleshooting. + +## Normalize local builds to reuse CI build cache + +As practice shows, developers often don't realize that builds they run in local and CI environments are different. So +straightforward attempt to reuse remote cache in local build usually results in cache misses because of difference in +plugins, parameters, profiles, environment, etc. In order to reuse results you might need to change poms, cache config, +CI jobs and the project itself. This part is usually most challenging and time-consuming. Follow steps below to +iteratively achieve working configuration. + +### Before you start + +Before you start, please keep in mind basic principles: + +* Cache is checksum based, it is a complex hash function essentially. In order to to produce the same hash the source + code, effective poms and dependencies should match. +* There is no built-in normalization of line endings in this implementation, file checksum calculation is raw bytes + based. The most obvious implication could be illustrated by a simple Git checkout. By default git will check out + source code with CRLF line endings on win and LF on Linux. Because of that builds over same commit on a Linux agent + and local build on Windows workstation will yield different checksums. +* Parameters of plugins are manually tracked ony. For example to avoid of accidentally reusing builds which never run + tests ensure that critical surfire parameters are tracked (`skipTests` and similar) in config. The same applies for + all over plugins. + +### Configure local build in debug mode + +To minimize distractions and simplify understanding of discrepancies following is recommended: + +* Run build with single threaded builder to make sure logs from different modules do not interfere +* Enable cache fail fast mode to focus on the blocking failure +* Provide reference to the CI build as a baseline for comparison between your local and remote builds. Go to the + reference CI build and one of the final lines of the build should be + +``` +[INFO] [CACHE][artifactId] Saved to remote cache https://your-cache-url/<...>/915296a3-4596-4eb5-bf37-f6e13ebe087e/cache-report.xml. +``` + +followed by a link to a `cache-report.xml` file. The `cache-report.xml` contains aggregated information about the +produced cache and could be used as a baseline for comparison. + +* Run local build. Command line should look similar to this: + +```bash +mvnw verify -Dremote.cache.failFast=true -Dremote.cache.baselineUrl=https://url-from-ci-build-to-cache-report.xml +``` + +Once discrepancy between remote and local builds detected cache will fail with diagnostic info +in `target/incremental-maven` directory: + +``` +* buildinfo-baseline-3c64673e23259e6f.xml - build specficiation from baseline build +* buildinfo-db43936e0666ce7.xml - build specification of locall build +* buildsdiff.xml - comparison report with list of discrepancies +``` + +Review `buildsdiff.xml` file and eliminate detected discrepancies.You can also diff build-info files directly to get low +level insights. See techniques to configure cache in [How-To](CACHE-HOWTO.md) and troubleshooting of typical issues in +the section below. + +# Common issues + +## Issue 1: Local checkout is with different line endings + +Solution: normalise line endings. Current implementation doesn't have built-in line endings normalization, it has to be +done externally. In git it is recommended to use `.gitattributes` file to establish consistent line endings across all +envs for file types specific to this project + +## Issue 2: Effective poms mismatch because of plugins filtering by profiles + +Different profiles between remote and local builds results in different text of effective poms and break checksums. +Solution: instead of adding/removing specific plugins from build altogether with profiles use profile specific `skip` +or `disabled` flags instead. Instead of: + + ``` + + + run-plugin-in-ci-only + + + + surefire-report-maven-plugin + + + + + + + + + ``` + +Use: + + ```xml + + + + true + + + + + maven-surefire-plugin + + + ${skip.plugin.property} + + + + + + + run-plugin-in-ci-only + + + false + + + + ``` + +Hint: effective poms could be found in `buildinfo` files under `/build/projectsInputInfo/item[@type='pom']` +xpath (`item type="pom"`). + +## Issue 3: Effective pom mismatch because of environment specific properties + +Potential reason: Sometimes it is not possible to avoid discrepancies in different environments - for example if you +need to invoke command line command, it will be likely different on win and linux. Such commands will appear in +effective pom as a different literal values and will result in checksum mismatch Solution: filter out such properties +from cache effective pom: + +```xml + + + + ... + + + + argLine + + + +``` + +## Issue 4: Unexpected or transient files in checksum calculation + +Potential reasons: plugins or tests emit temporary files (logs and similar) in non-standard locations Solution: adjust +global exclusions list to filter out unexpected files: + +``` + + tempfile.out + +``` + +see sample config for exact syntax + +## Issue 5: Difference in tracked plugin properties + +Tracked property in config means it is critical for determining is build up to date or not. Discrepancies could happen +for any plugin for a number of reasons. Example: local build is using java target 1.6, remote: 1.8. `buildsdiff.xml` +will produce something like + +``` + +``` + +Solution is at your discretion. If the property is tracked, out-of-date status is fair and expected. If you want to +relax consistency rules in favor of compatibility, remove property from tracked list + +## Issue 5: Version changes invalidate effective pom checksum + +Current implementation doesn't support version changes between cache entries. It will result in cache invalidation for +each new version. +To mitigate the issue please consider migrating off traditional maven release approach - try to use single version id in +project (eg `MY-PROJECT-LOCAL`). Such approach simplifies git branching workflow significantly. + +Deployment of artifacts with specific version from builds with cache is not supported yet. + diff --git a/Documentation/CACHE.md b/Documentation/CACHE.md new file mode 100644 index 000000000000..391becc7b5f7 --- /dev/null +++ b/Documentation/CACHE.md @@ -0,0 +1,170 @@ + + +## Overview + +Idea of Incremental Maven is to specify module inputs and outputs and make them known to standard maven core. This +allows accurate analysis and determination of out-of-date build artifacts in the build dependencies graph. Making the +dependency graph analysis deterministic leads to improvements in build times by avoiding re-building unnecessary +modules. +Cache does not make any low-level interventions to build process and delegates actual build work to maven core. This +guarantees that build results are identical to results produced by standard maven and are fully reproducible. +To achieve accurate input and outputs calculation incremental maven combines automatic introspection +of [project object model](https://maven.apache.org/pom.html#What_is_the_POM) in conjunction with configuration-driven +rules for fine-grained content and execution control. For content analysis it digests based approach which is more +reliable over widely used file timestamps in tools like Make or Apache Ant. Deterministic build state allows reliably +cache even intermediate outputs of build and share them between teams using remote cache. Deterministic inputs +calculation allows distributed and parallel builds running in heterogeneous environments (like cloud of build agents) +could efficiently reuse cached build artifacts. Therefore incremental maven is particularly well-suited for large maven +projects that have significant number of small modules. Remote cache in conjunction with precise input identification +effectively enables "change once - build once" approach. + +### Maven insights + +The challenge of implementing build cache in Maven is that domain model is overly generic and doesn't support well +reproducible builds. You might have never thought of that, but it is a reality that 2 different Maven builds from the +same source code normally produce 2 different results. The question here is tolerance level - can you accept particular +discrepancies or not. For most of teams artifacts produced in the same build environment from the same source code will +be considered equivalent and technical differences between them (like different timestamps in jar manifests) could be +ignored. Now consider scenario when artifact is first produced with compiler X and cached but later without touching a +update compiler changes to Y and yields significantly different outcomes of compilation. Ask yourself a question \- am I +consider artifacts of such builds equivalent? Both Yes and No outcomes are pretty possible and could be even desirable +in different scenarios. When productivity and performance are the primary concerns it could be desirable to tolerate +insignificant discrepancies and maximise reuse of cached builds. As long as correctness in focus there could be demand +to comply with the exact release process. In the same way as with classic Maven, decision stays with you - what is +acceptable difference between builds. In the same way as with classic Maven the previous build is just an approximation +of today build with some tolerance (implementation, configuration and environment driven). + +### Implementation insights + +At very simple form, the incremental maven is essentially a hash function which takes maven project and produces hash +code (checksum). Then hash value is used to fetch and restore build result. +As with any hash, there could be collisions and instabilities. Collision could happen if the same hash produced from the +different build states and will result in unintended reuse. Instability means that same input yields different hash sums +in different runs - resulting in cache miss. The ultimate target is to achieve desired balance between collisions ( +sufficient correctness) and stability (sufficient reuse). In current implementation this is achieved by configuring +project specific processing rules in static configuration file. To avoid unintentional collisions and achieve better +correctness need to ensure that every critical file and plugin parameter accounted in build inputs. In order to achieve +better reuse need to ensure that non-critical files (test logs, readme and similar) and non-critical plugin parameters ( +like number of threads in build) are filtered out from build inputs. Essentially cache configuration is a process of +inspecting build, taking these decision and reflect them in the cache configuration. + +Please notice though idea of perfectly matching builds might be tempting, but it is not practical with regard to +caching. Perfect correctness means that not a single build could be reused and renders whole idea of builds caching +useless. Whatever build tool you use, there will be always a tradeoff which might be acceptable or not in particular +situation. Incremental Maven provides flexible and transparent control over caching policy and allows achieving desired +outcomes - maximize reusability or maximize equivalence between pre-cached candidates and requested builds. + +## Usage + +Cornerstone principle of using this tool is that it is delivered as is. Though the tool went through thorough +verification it's still consumer's responsibility to verify final product quality. + +### Recommended Scenarios + +Given all the information above, the Incremental Maven is recommended to use in scenarios when productivity and +performance are in priority. Typical cases are: + +* Speedup CI. In conjunction with remote cache incremental maven could drastically reduce build times, validate pull + requests faster and reduce load on CI nodes +* Speedup developer builds. By reusing cached builds developers could verify changes much faster and be more productive. + No more `-DskipTests` and similar. +* Assemble artifacts faster. In some development models it might be critical to have as fast build/deploy cycle as + possible. Caching helps to cut down time drastically in such scenarios because it doesn't require to build cached + dependencies. + +For cases there correctness must be ensured (eg prod builds), it is recommended to disable cache and do clean builds. +This also allows you to validate cache correctness and reconcile cache outcomes on CI process. + +## Getting Started + +To on-board incremental maven you need to complete several steps: + +* Get incremental maven distribution +* Add cache config in .mvn +* Validate build results and iteratively adjust config to project specifics +* Migrate CI to incremental maven with remote cache (to get full benefit) - optional + +### Get incremental maven distribution + +The recommended way is to add [Takari Maven Wrapper](https://github.com/takari/maven-wrapper) to your project. In that +case `maven-wrapper.properties` should reference the latest incremental maven distribution: + +```properties +distributionUrl=https://your-server/maven-incremental.zip +wrapperUrl=https://your-server/maven-wrapper-0.5.5.jar +``` + +Benefits of using maven wrapper are following: + +* simple distribution across workstations and CI envs +* maven stays compatible to your branch +* further upgrades are simplified significantly + If you refuse wrapper - then download, unzip and install it just as usual maven. Further it will be assumed you use + maven wrapper (`mvnw`) + +### Adding cache config + +Copy [default config](maven-cache-config.xml) and [xml schema](../maven-core/src/main/resources/cache-config.xsd) +to [.mvn](https://maven.apache.org/configure.html) dir of yor project. +To get overall understanding of cache machinery it is recommended to review the config and read comments. In typical +scenario you need to adjust: + +* remote cache location +* source code files glob +* plugins reconciliation rules - add critical plugin parameters to reconciliation +* add non-standard source code locations (most of locations discovered automatically from project and plugins config, + but still there might be edge cases) + +See also: + +* [Remote cache setup](CACHE-REMOTE.md) - instruction how to setup shared cache +* [Cache How-To](CACHE-HOWTO.md) - cookbook for frequently encountered questions +* [Cache Parameters](CACHE-PARAMETERS.md) - description of supported parameters +* Attached [sample config file](maven-cache-config.xml) and elements annotations in xsd schema. (Ctrl+Q in idea should + show annotations in popup) + +### Adjusting cache config + +Having incremental maven and the config in place you're all set. To run first cacheable build just +execute: `mvnw clean install` + +* Ensure that the config is picked up and incremental maven is picked up. Just check log output - you will notice cache + related output or initialization error message. +* Navigate to your local repo directory - there should be sibling next to your local repo named `cache` +* Find `buildinfo.xml` for typical module and review it. Ensure that + * expected source code files are present in build info + * all critical plugins and their critical parameters are covered by config + +Notice - in configuration you should find best working trade-off between fairness and cache efficiency. Adding +unnecessary rules and checks could reduce both performance and cache efficiency (hit rate). + +### Adding caching CI and remote cache + +To leverage remote cache feature you need web server which supports get/put operations +like [Nginx OSS](http://nginx.org/en/) (with fs module) or binary repo in Artifactory. It is recommended to populate +remote cache from CI build. Benefits are: + +* such scheme provides predictable and consistent artifacts in remote cache +* usually CI builds project fast enough to populate cache for team members See [Remote cache setup](CACHE-REMOTE.md) for + detailed description of cache setup + +## Credits +CacheConfigImpl +* Maximilian Novikov - Project lead. Idea, design, coordination and verification. +* Alexander Ashitkin - Co-design and implementation of the majority of functionality +* Alexander Novoselov - Hashing module implementation \ No newline at end of file diff --git a/Documentation/maven-cache-config.xml b/Documentation/maven-cache-config.xml new file mode 100644 index 000000000000..a2a7ad8ee1c3 --- /dev/null +++ b/Documentation/maven-cache-config.xml @@ -0,0 +1,102 @@ + + + + + + true + SHA-256 + true + + PROJECT-LOCAL + + + http://host:port + + + 3 + + + + + + + {*.java,*.groovy,*.yaml,*.svcd,*.proto,*assembly.xml,assembly*.xml,*logback.xml,*.vm,*.ini,*.jks,*.properties,*.sh,*.bat} + + src/ + pom.xml + + + + 111 + + + + + + + + 1 + 2 + + + + + + + + + + + my-execution-id + + + install + + + deploy + + + deploy-local + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index 0c77dabf55ae..88b0a333f257 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,11 @@ build, reporting and documentation from a central piece of information. If you think you have found a bug, please file an issue in the [Maven Issue Tracker](https://issues.apache.org/jira/browse/MNG). +Incremental Build and Cache +------------- +This maven version supports Incremental Build feature which calculates out-of-date modules in the build dependencies graph and improves build times by avoiding re-building unnecessary modules. +Read [cache guide](Documentation/CACHE.md) for more details + Documentation ------------- diff --git a/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm b/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm index b589e36e0222..7182bea25132 100644 --- a/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm +++ b/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm @@ -25,6 +25,7 @@ subject to the terms and conditions of the following licenses: #set ( $apacheMavenGroupIds = [ "org.apache.maven", "org.apache.maven.wagon", "org.apache.maven.resolver", "org.apache.maven.shared" ] ) #set ( $MITLicenseNames = [ "MIT License", "MIT license", "The MIT License" ] ) +#set ( $CDDLLicenseNames = [ "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0", "CDDL/GPLv2+CE", "CDDL 1.1", "GPL2 w/ CPE" ] ) #foreach ( $project in $projects ) #**##foreach ( $license in $project.licenses ) #* *##set ( $groupId = $project.artifact.groupId ) @@ -41,7 +42,7 @@ subject to the terms and conditions of the following licenses: #* *##set ( $spdx = 'Apache-2.0' ) #* *##else #* *### unrecognized license will require analysis to know obligations -#* *##set ( $spdx = 'unrecognized' ) +#* *##set ( $spdx = "unrecognized: $license.name $license.url" ) #* *##end #* *### #* *### fix project urls that are wrong in pom diff --git a/apache-maven/src/main/appended-resources/licenses/EDL-1.0.txt b/apache-maven/src/main/appended-resources/licenses/EDL-1.0.txt new file mode 100644 index 000000000000..259e0377f30f --- /dev/null +++ b/apache-maven/src/main/appended-resources/licenses/EDL-1.0.txt @@ -0,0 +1,23 @@ +Eclipse Distribution License - v 1.0 +Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided +that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or other materials provided +with the distribution. +- Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse +or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/apache-maven/src/main/appended-resources/licenses/GPL-3.0.txt b/apache-maven/src/main/appended-resources/licenses/GPL-3.0.txt new file mode 100644 index 000000000000..e72bfddabc15 --- /dev/null +++ b/apache-maven/src/main/appended-resources/licenses/GPL-3.0.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. \ No newline at end of file diff --git a/apache-maven/src/main/appended-resources/licenses/LGPL-3.0.txt b/apache-maven/src/main/appended-resources/licenses/LGPL-3.0.txt new file mode 100644 index 000000000000..153d416dc8d2 --- /dev/null +++ b/apache-maven/src/main/appended-resources/licenses/LGPL-3.0.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. \ No newline at end of file diff --git a/apache-maven/src/main/appended-resources/licenses/MPL-1.1.txt b/apache-maven/src/main/appended-resources/licenses/MPL-1.1.txt new file mode 100644 index 000000000000..7bcf5c0e2885 --- /dev/null +++ b/apache-maven/src/main/appended-resources/licenses/MPL-1.1.txt @@ -0,0 +1,472 @@ +http://www.mozilla.org/MPL/MPL-1.1.html + + + MOZILLA PUBLIC LICENSE + Version 1.1 + + --------------- + +1. Definitions. + + 1.0.1. "Commercial Use" means distribution or otherwise making the + Covered Code available to a third party. + + 1.1. "Contributor" means each entity that creates or contributes to + the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the Original + Code, prior Modifications used by a Contributor, and the Modifications + made by that particular Contributor. + + 1.3. "Covered Code" means the Original Code or Modifications or the + combination of the Original Code and Modifications, in each case + including portions thereof. + + 1.4. "Electronic Distribution Mechanism" means a mechanism generally + accepted in the software development community for the electronic + transfer of data. + + 1.5. "Executable" means Covered Code in any form other than Source + Code. + + 1.6. "Initial Developer" means the individual or entity identified + as the Initial Developer in the Source Code notice required by Exhibit + A. + + 1.7. "Larger Work" means a work which combines Covered Code or + portions thereof with code not governed by the terms of this License. + + 1.8. "License" means this document. + + 1.8.1. "Licensable" means having the right to grant, to the maximum + extent possible, whether at the time of the initial grant or + subsequently acquired, any and all of the rights conveyed herein. + + 1.9. "Modifications" means any addition to or deletion from the + substance or structure of either the Original Code or any previous + Modifications. When Covered Code is released as a series of files, a + Modification is: + A. Any addition to or deletion from the contents of a file + containing Original Code or previous Modifications. + + B. Any new file that contains any part of the Original Code or + previous Modifications. + + 1.10. "Original Code" means Source Code of computer software code + which is described in the Source Code notice required by Exhibit A as + Original Code, and which, at the time of its release under this + License is not already Covered Code governed by this License. + + 1.10.1. "Patent Claims" means any patent claim(s), now owned or + hereafter acquired, including without limitation, method, process, + and apparatus claims, in any patent Licensable by grantor. + + 1.11. "Source Code" means the preferred form of the Covered Code for + making modifications to it, including all modules it contains, plus + any associated interface definition files, scripts used to control + compilation and installation of an Executable, or source code + differential comparisons against either the Original Code or another + well known, available Covered Code of the Contributor's choice. The + Source Code can be in a compressed or archival form, provided the + appropriate decompression or de-archiving software is widely available + for no charge. + + 1.12. "You" (or "Your") means an individual or a legal entity + exercising rights under, and complying with all of the terms of, this + License or a future version of this License issued under Section 6.1. + For legal entities, "You" includes any entity which controls, is + controlled by, or is under common control with You. For purposes of + this definition, "control" means (a) the power, direct or indirect, + to cause the direction or management of such entity, whether by + contract or otherwise, or (b) ownership of more than fifty percent + (50%) of the outstanding shares or beneficial ownership of such + entity. + +2. Source Code License. + + 2.1. The Initial Developer Grant. + The Initial Developer hereby grants You a world-wide, royalty-free, + non-exclusive license, subject to third party intellectual property + claims: + (a) under intellectual property rights (other than patent or + trademark) Licensable by Initial Developer to use, reproduce, + modify, display, perform, sublicense and distribute the Original + Code (or portions thereof) with or without Modifications, and/or + as part of a Larger Work; and + + (b) under Patents Claims infringed by the making, using or + selling of Original Code, to make, have made, use, practice, + sell, and offer for sale, and/or otherwise dispose of the + Original Code (or portions thereof). + + (c) the licenses granted in this Section 2.1(a) and (b) are + effective on the date Initial Developer first distributes + Original Code under the terms of this License. + + (d) Notwithstanding Section 2.1(b) above, no patent license is + granted: 1) for code that You delete from the Original Code; 2) + separate from the Original Code; or 3) for infringements caused + by: i) the modification of the Original Code or ii) the + combination of the Original Code with other software or devices. + + 2.2. Contributor Grant. + Subject to third party intellectual property claims, each Contributor + hereby grants You a world-wide, royalty-free, non-exclusive license + + (a) under intellectual property rights (other than patent or + trademark) Licensable by Contributor, to use, reproduce, modify, + display, perform, sublicense and distribute the Modifications + created by such Contributor (or portions thereof) either on an + unmodified basis, with other Modifications, as Covered Code + and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using, or + selling of Modifications made by that Contributor either alone + and/or in combination with its Contributor Version (or portions + of such combination), to make, use, sell, offer for sale, have + made, and/or otherwise dispose of: 1) Modifications made by that + Contributor (or portions thereof); and 2) the combination of + Modifications made by that Contributor with its Contributor + Version (or portions of such combination). + + (c) the licenses granted in Sections 2.2(a) and 2.2(b) are + effective on the date Contributor first makes Commercial Use of + the Covered Code. + + (d) Notwithstanding Section 2.2(b) above, no patent license is + granted: 1) for any code that Contributor has deleted from the + Contributor Version; 2) separate from the Contributor Version; + 3) for infringements caused by: i) third party modifications of + Contributor Version or ii) the combination of Modifications made + by that Contributor with other software (except as part of the + Contributor Version) or other devices; or 4) under Patent Claims + infringed by Covered Code in the absence of Modifications made by + that Contributor. + +3. Distribution Obligations. + + 3.1. Application of License. + The Modifications which You create or to which You contribute are + governed by the terms of this License, including without limitation + Section 2.2. The Source Code version of Covered Code may be + distributed only under the terms of this License or a future version + of this License released under Section 6.1, and You must include a + copy of this License with every copy of the Source Code You + distribute. You may not offer or impose any terms on any Source Code + version that alters or restricts the applicable version of this + License or the recipients' rights hereunder. However, You may include + an additional document offering the additional rights described in + Section 3.5. + + 3.2. Availability of Source Code. + Any Modification which You create or to which You contribute must be + made available in Source Code form under the terms of this License + either on the same media as an Executable version or via an accepted + Electronic Distribution Mechanism to anyone to whom you made an + Executable version available; and if made available via Electronic + Distribution Mechanism, must remain available for at least twelve (12) + months after the date it initially became available, or at least six + (6) months after a subsequent version of that particular Modification + has been made available to such recipients. You are responsible for + ensuring that the Source Code version remains available even if the + Electronic Distribution Mechanism is maintained by a third party. + + 3.3. Description of Modifications. + You must cause all Covered Code to which You contribute to contain a + file documenting the changes You made to create that Covered Code and + the date of any change. You must include a prominent statement that + the Modification is derived, directly or indirectly, from Original + Code provided by the Initial Developer and including the name of the + Initial Developer in (a) the Source Code, and (b) in any notice in an + Executable version or related documentation in which You describe the + origin or ownership of the Covered Code. + + 3.4. Intellectual Property Matters + (a) Third Party Claims. + If Contributor has knowledge that a license under a third party's + intellectual property rights is required to exercise the rights + granted by such Contributor under Sections 2.1 or 2.2, + Contributor must include a text file with the Source Code + distribution titled "LEGAL" which describes the claim and the + party making the claim in sufficient detail that a recipient will + know whom to contact. If Contributor obtains such knowledge after + the Modification is made available as described in Section 3.2, + Contributor shall promptly modify the LEGAL file in all copies + Contributor makes available thereafter and shall take other steps + (such as notifying appropriate mailing lists or newsgroups) + reasonably calculated to inform those who received the Covered + Code that new knowledge has been obtained. + + (b) Contributor APIs. + If Contributor's Modifications include an application programming + interface and Contributor has knowledge of patent licenses which + are reasonably necessary to implement that API, Contributor must + also include this information in the LEGAL file. + + (c) Representations. + Contributor represents that, except as disclosed pursuant to + Section 3.4(a) above, Contributor believes that Contributor's + Modifications are Contributor's original creation(s) and/or + Contributor has sufficient rights to grant the rights conveyed by + this License. + + 3.5. Required Notices. + You must duplicate the notice in Exhibit A in each file of the Source + Code. If it is not possible to put such notice in a particular Source + Code file due to its structure, then You must include such notice in a + location (such as a relevant directory) where a user would be likely + to look for such a notice. If You created one or more Modification(s) + You may add your name as a Contributor to the notice described in + Exhibit A. You must also duplicate this License in any documentation + for the Source Code where You describe recipients' rights or ownership + rights relating to Covered Code. You may choose to offer, and to + charge a fee for, warranty, support, indemnity or liability + obligations to one or more recipients of Covered Code. However, You + may do so only on Your own behalf, and not on behalf of the Initial + Developer or any Contributor. You must make it absolutely clear than + any such warranty, support, indemnity or liability obligation is + offered by You alone, and You hereby agree to indemnify the Initial + Developer and every Contributor for any liability incurred by the + Initial Developer or such Contributor as a result of warranty, + support, indemnity or liability terms You offer. + + 3.6. Distribution of Executable Versions. + You may distribute Covered Code in Executable form only if the + requirements of Section 3.1-3.5 have been met for that Covered Code, + and if You include a notice stating that the Source Code version of + the Covered Code is available under the terms of this License, + including a description of how and where You have fulfilled the + obligations of Section 3.2. The notice must be conspicuously included + in any notice in an Executable version, related documentation or + collateral in which You describe recipients' rights relating to the + Covered Code. You may distribute the Executable version of Covered + Code or ownership rights under a license of Your choice, which may + contain terms different from this License, provided that You are in + compliance with the terms of this License and that the license for the + Executable version does not attempt to limit or alter the recipient's + rights in the Source Code version from the rights set forth in this + License. If You distribute the Executable version under a different + license You must make it absolutely clear that any terms which differ + from this License are offered by You alone, not by the Initial + Developer or any Contributor. You hereby agree to indemnify the + Initial Developer and every Contributor for any liability incurred by + the Initial Developer or such Contributor as a result of any such + terms You offer. + + 3.7. Larger Works. + You may create a Larger Work by combining Covered Code with other code + not governed by the terms of this License and distribute the Larger + Work as a single product. In such a case, You must make sure the + requirements of this License are fulfilled for the Covered Code. + +4. Inability to Comply Due to Statute or Regulation. + + If it is impossible for You to comply with any of the terms of this + License with respect to some or all of the Covered Code due to + statute, judicial order, or regulation then You must: (a) comply with + the terms of this License to the maximum extent possible; and (b) + describe the limitations and the code they affect. Such description + must be included in the LEGAL file described in Section 3.4 and must + be included with all distributions of the Source Code. Except to the + extent prohibited by statute or regulation, such description must be + sufficiently detailed for a recipient of ordinary skill to be able to + understand it. + +5. Application of this License. + + This License applies to code to which the Initial Developer has + attached the notice in Exhibit A and to related Covered Code. + +6. Versions of the License. + + 6.1. New Versions. + Netscape Communications Corporation ("Netscape") may publish revised + and/or new versions of the License from time to time. Each version + will be given a distinguishing version number. + + 6.2. Effect of New Versions. + Once Covered Code has been published under a particular version of the + License, You may always continue to use it under the terms of that + version. You may also choose to use such Covered Code under the terms + of any subsequent version of the License published by Netscape. No one + other than Netscape has the right to modify the terms applicable to + Covered Code created under this License. + + 6.3. Derivative Works. + If You create or use a modified version of this License (which you may + only do in order to apply it to code which is not already Covered Code + governed by this License), You must (a) rename Your license so that + the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", + "MPL", "NPL" or any confusingly similar phrase do not appear in your + license (except to note that your license differs from this License) + and (b) otherwise make it clear that Your version of the license + contains terms which differ from the Mozilla Public License and + Netscape Public License. (Filling in the name of the Initial + Developer, Original Code or Contributor in the notice described in + Exhibit A shall not of themselves be deemed to be modifications of + this License.) + +7. DISCLAIMER OF WARRANTY. + + COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF + DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. + THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE + IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, + YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE + COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER + OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF + ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +8. TERMINATION. + + 8.1. This License and the rights granted hereunder will terminate + automatically if You fail to comply with terms herein and fail to cure + such breach within 30 days of becoming aware of the breach. All + sublicenses to the Covered Code which are properly granted shall + survive any termination of this License. Provisions which, by their + nature, must remain in effect beyond the termination of this License + shall survive. + + 8.2. If You initiate litigation by asserting a patent infringement + claim (excluding declatory judgment actions) against Initial Developer + or a Contributor (the Initial Developer or Contributor against whom + You file such action is referred to as "Participant") alleging that: + + (a) such Participant's Contributor Version directly or indirectly + infringes any patent, then any and all rights granted by such + Participant to You under Sections 2.1 and/or 2.2 of this License + shall, upon 60 days notice from Participant terminate prospectively, + unless if within 60 days after receipt of notice You either: (i) + agree in writing to pay Participant a mutually agreeable reasonable + royalty for Your past and future use of Modifications made by such + Participant, or (ii) withdraw Your litigation claim with respect to + the Contributor Version against such Participant. If within 60 days + of notice, a reasonable royalty and payment arrangement are not + mutually agreed upon in writing by the parties or the litigation claim + is not withdrawn, the rights granted by Participant to You under + Sections 2.1 and/or 2.2 automatically terminate at the expiration of + the 60 day notice period specified above. + + (b) any software, hardware, or device, other than such Participant's + Contributor Version, directly or indirectly infringes any patent, then + any rights granted to You by such Participant under Sections 2.1(b) + and 2.2(b) are revoked effective as of the date You first made, used, + sold, distributed, or had made, Modifications made by that + Participant. + + 8.3. If You assert a patent infringement claim against Participant + alleging that such Participant's Contributor Version directly or + indirectly infringes any patent where such claim is resolved (such as + by license or settlement) prior to the initiation of patent + infringement litigation, then the reasonable value of the licenses + granted by such Participant under Sections 2.1 or 2.2 shall be taken + into account in determining the amount or value of any payment or + license. + + 8.4. In the event of termination under Sections 8.1 or 8.2 above, + all end user license agreements (excluding distributors and resellers) + which have been validly granted by You or any distributor hereunder + prior to termination shall survive termination. + +9. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL + DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, + OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR + ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY + CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, + WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER + COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN + INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF + LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY + RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW + PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE + EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO + THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +10. U.S. GOVERNMENT END USERS. + + The Covered Code is a "commercial item," as that term is defined in + 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer + software" and "commercial computer software documentation," as such + terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 + C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), + all U.S. Government End Users acquire Covered Code with only those + rights set forth herein. + +11. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. This License shall be governed by + California law provisions (except to the extent applicable law, if + any, provides otherwise), excluding its conflict-of-law provisions. + With respect to disputes in which at least one party is a citizen of, + or an entity chartered or registered to do business in the United + States of America, any litigation relating to this License shall be + subject to the jurisdiction of the Federal Courts of the Northern + District of California, with venue lying in Santa Clara County, + California, with the losing party responsible for costs, including + without limitation, court costs and reasonable attorneys' fees and + expenses. The application of the United Nations Convention on + Contracts for the International Sale of Goods is expressly excluded. + Any law or regulation which provides that the language of a contract + shall be construed against the drafter shall not apply to this + License. + +12. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or indirectly, + out of its utilization of rights under this License and You agree to + work with Initial Developer and Contributors to distribute such + responsibility on an equitable basis. Nothing herein is intended or + shall be deemed to constitute any admission of liability. + +13. MULTIPLE-LICENSED CODE. + + Initial Developer may designate portions of the Covered Code as + "Multiple-Licensed". "Multiple-Licensed" means that the Initial + Developer permits you to utilize portions of the Covered Code under + Your choice of the MPL or the alternative licenses, if any, specified + by the Initial Developer in the file described in Exhibit A. + +EXHIBIT A -Mozilla Public License. + + ``The contents of this file are subject to the Mozilla Public License + Version 1.1 (the "License"); you may not use this file except in + compliance with the License. You may obtain a copy of the License at + https://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + License for the specific language governing rights and limitations + under the License. + + The Original Code is ______________________________________. + + The Initial Developer of the Original Code is ________________________. + Portions created by ______________________ are Copyright (C) ______ + _______________________. All Rights Reserved. + + Contributor(s): ______________________________________. + + Alternatively, the contents of this file may be used under the terms + of the _____ license (the "[___] License"), in which case the + provisions of [______] License are applicable instead of those + above. If you wish to allow use of your version of this file only + under the terms of the [____] License and not to allow others to use + your version of this file under the MPL, indicate your decision by + deleting the provisions above and replace them with the notice and + other provisions required by the [___] License. If you do not delete + the provisions above, a recipient may use your version of this file + under either the MPL or the [___] License." + + [NOTE: The text of this Exhibit A may differ slightly from the text of + the notices in the Source Code files of the Original Code. You should + use the text of this Exhibit A rather than the text found in the + Original Code Source Code for Your Modifications.] diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 86aea1ff2319..8f60c1bea85f 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -149,6 +149,32 @@ under the License. hamcrest-library test + + org.apache.httpcomponents + httpclient + 4.5.6 + + + net.openhft + zero-allocation-hashing + 0.9 + + + jakarta.xml.bind + jakarta.xml.bind-api + 2.3.3 + + + com.sun.xml.bind + jaxb-impl + 2.3.3 + runtime + + + com.github.albfernandez + juniversalchardet + 2.4.0 + @@ -169,6 +195,7 @@ under the License. plugin-manager.txt project-builder.txt src/site/resources/design/** + src/main/resources/cache-* @@ -225,6 +252,26 @@ under the License. + + org.codehaus.mojo + jaxb2-maven-plugin + 2.5.0 + + + xjc + + xjc + + + + + org.apache.maven.caching.jaxb + + src/main/resources/cache-config.xsd + src/main/resources/cache-domain.xsd + + + diff --git a/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java b/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java new file mode 100644 index 000000000000..65315498c7ff --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java @@ -0,0 +1,42 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.caching.jaxb.CacheReportType; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.execution.MavenSession; + +import java.io.IOException; + +/** + * ArtifactsRepository + */ +public interface ArtifactsRepository +{ + + BuildInfo findBuild( CacheContext context ) throws IOException; + + void saveBuildInfo( CacheResult cacheResult, BuildInfo buildInfo ) throws IOException; + + void saveArtifactFile( CacheResult cacheResult, Artifact artifact ) throws IOException; + + void saveCacheReport( String buildId, MavenSession session, CacheReportType cacheReport ) throws IOException; +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java b/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java new file mode 100644 index 000000000000..569286d8b841 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java @@ -0,0 +1,58 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.caching.jaxb.ProjectsInputInfoType; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.project.MavenProject; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * CacheContext + */ +public class CacheContext +{ + private final MavenProject project; + private final ProjectsInputInfoType inputInfo; + private final MavenSession session; + + public CacheContext( MavenProject project, ProjectsInputInfoType inputInfo, MavenSession session ) + { + this.project = checkNotNull( project ); + this.inputInfo = checkNotNull( inputInfo ); + this.session = checkNotNull( session ); + } + + public MavenProject getProject() + { + return project; + } + + public ProjectsInputInfoType getInputInfo() + { + return inputInfo; + } + + public MavenSession getSession() + { + return session; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheController.java b/maven-core/src/main/java/org/apache/maven/caching/CacheController.java new file mode 100644 index 000000000000..a91c284e2414 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheController.java @@ -0,0 +1,52 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.MojoExecutionEvent; +import org.apache.maven.lifecycle.internal.ProjectIndex; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.project.MavenProject; + +import java.util.List; +import java.util.Map; + +/** + * CacheController + */ +public interface CacheController +{ + + CacheResult findCachedBuild( MavenSession session, + MavenProject project, + ProjectIndex projectIndex, + List mojoExecutions ); + + boolean restoreProjectArtifacts( CacheResult cacheResult ); + + void save( CacheResult cacheResult, + List mojoExecutions, + Map executionEvents ); + + boolean isForcedExecution( MavenProject project, MojoExecution execution ); + + void saveCacheReport( MavenSession session ); + +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java new file mode 100644 index 000000000000..ad9d490c6ebb --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -0,0 +1,942 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.mutable.MutableBoolean; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.caching.checksum.KeyUtils; +import org.apache.maven.caching.checksum.MavenProjectInput; +import org.apache.maven.caching.hash.HashAlgorithm; +import org.apache.maven.caching.hash.HashFactory; +import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.caching.jaxb.BuildDiffType; +import org.apache.maven.caching.jaxb.BuildInfoType; +import org.apache.maven.caching.jaxb.CacheReportType; +import org.apache.maven.caching.jaxb.CompletedExecutionType; +import org.apache.maven.caching.jaxb.DigestItemType; +import org.apache.maven.caching.jaxb.ProjectReportType; +import org.apache.maven.caching.jaxb.ProjectsInputInfoType; +import org.apache.maven.caching.jaxb.PropertyNameType; +import org.apache.maven.caching.jaxb.TrackedPropertyType; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.CacheSource; +import org.apache.maven.caching.xml.DtoUtils; +import org.apache.maven.caching.xml.XmlService; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.MojoExecutionEvent; +import org.apache.maven.lifecycle.internal.ProjectIndex; +import org.apache.maven.plugin.MavenPluginManager; +import org.apache.maven.plugin.Mojo; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.descriptor.Parameter; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; +import org.apache.maven.repository.RepositorySystem; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.util.ReflectionUtils; + +import javax.annotation.Nonnull; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigInteger; +import java.nio.charset.StandardCharsets; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.regex.Pattern; + +import static java.nio.file.StandardOpenOption.CREATE; +import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; +import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.apache.commons.lang3.StringUtils.replace; +import static org.apache.commons.lang3.StringUtils.split; +import static org.apache.maven.caching.CacheResult.empty; +import static org.apache.maven.caching.CacheResult.failure; +import static org.apache.maven.caching.CacheResult.partialSuccess; +import static org.apache.maven.caching.CacheResult.rebuilded; +import static org.apache.maven.caching.CacheResult.success; +import static org.apache.maven.caching.HttpRepositoryImpl.BUILDINFO_XML; +import static org.apache.maven.caching.checksum.KeyUtils.getVersionlessProjectKey; +import static org.apache.maven.caching.checksum.MavenProjectInput.CACHE_IMPLMENTATION_VERSION; + +/** + * CacheControllerImpl + */ +@Component( role = CacheController.class ) +public class CacheControllerImpl implements CacheController +{ + + public static final String FILE_SEPARATOR_SUBST = "_"; + private static final String GENERATEDSOURCES = "generatedsources"; + private static final String GENERATEDSOURCES_PREFIX = GENERATEDSOURCES + FILE_SEPARATOR_SUBST; + @Requirement + private Logger logger; + + @Requirement + private MavenPluginManager mavenPluginManager; + + @Requirement + private MavenProjectHelper projectHelper; + + @Requirement + private LocalArtifactsRepository localCache; + + @Requirement + private RemoteArtifactsRepository remoteCache; + + @Requirement + private CacheConfig cacheConfig; + + @Requirement + private RepositorySystem repoSystem; + + @Requirement + private ArtifactHandlerManager artifactHandlerManager; + + @Requirement + private XmlService xmlService; + + private final ConcurrentMap artifactDigestByKey = new ConcurrentHashMap<>(); + + private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); + + private volatile BuildInfoType.Scm scm; + + @Override + @Nonnull + public CacheResult findCachedBuild( MavenSession session, MavenProject project, ProjectIndex projectIndex, + List mojoExecutions ) + { + + final String highestRequestPhase = Iterables.getLast( mojoExecutions ).getLifecyclePhase(); + if ( !ProjectUtils.isLaterPhase( highestRequestPhase, "post-clean" ) ) + { + return empty(); + } + + logInfo( project, "Attempting to restore project from build cache" ); + + ProjectsInputInfoType inputInfo = calculateInput( project, session, projectIndex ); + + final CacheContext context = new CacheContext( project, inputInfo, session ); + // remote build first + CacheResult result = findCachedBuild( mojoExecutions, context ); + + if ( !result.isSuccess() && result.getContext() != null ) + { + + logDebug( project, "Remote cache is incomplete or missing, trying local build" ); + + CacheResult localBuild = findLocalBuild( mojoExecutions, context ); + + if ( localBuild.isSuccess() || ( localBuild.isPartialSuccess() && !result.isPartialSuccess() ) ) + { + result = localBuild; + } + } + cacheResults.put( getVersionlessProjectKey( project ), result ); + + return result; + } + + private CacheResult findCachedBuild( List mojoExecutions, CacheContext context ) + { + BuildInfo cachedBuild = null; + try + { + cachedBuild = localCache.findBuild( context ); + return analyzeResult( context, mojoExecutions, cachedBuild ); + } + catch ( Exception e ) + { + logError( context.getProject(), "Cannot read cached build", e ); + return cachedBuild != null ? failure( cachedBuild, context ) : failure( context ); + } + } + + private CacheResult findLocalBuild( List mojoExecutions, CacheContext context ) + { + BuildInfo localBuild = null; + try + { + localBuild = localCache.findLocalBuild( context ); + return analyzeResult( context, mojoExecutions, localBuild ); + } + catch ( Exception e ) + { + logError( context.getProject(), "Cannot read local build", e ); + return localBuild != null ? failure( localBuild, context ) : failure( context ); + } + } + + private CacheResult analyzeResult( CacheContext context, List mojoExecutions, BuildInfo info ) + { + + try + { + if ( info != null ) + { + + final MavenProject project = context.getProject(); + final ProjectsInputInfoType inputInfo = context.getInputInfo(); + + logInfo( project, "Found cached build, restoring from cache " + inputInfo.getChecksum() ); + + if ( logger.isDebugEnabled() ) + { + logDebug( project, "Cached build details: " + info.toString() ); + } + + final String cacheImplementationVersion = info.getCacheImplementationVersion(); + if ( !CACHE_IMPLMENTATION_VERSION.equals( cacheImplementationVersion ) ) + { + logger.warn( + "Maven and cached build implementations mismatch, caching might not work correctly. " + + "Implementation version: " + CACHE_IMPLMENTATION_VERSION + ", cached build: " + + info.getCacheImplementationVersion() ); + } + + final List cachedSegment = info.getCachedSegment( mojoExecutions ); + + if ( !info.isAllExecutionsPresent( cachedSegment, logger ) ) + { + logInfo( project, "Cached build doesn't contains all requested plugin executions, cannot restore" ); + return failure( info, context ); + } + + if ( !isCachedSegmentPropertiesPresent( project, info, cachedSegment ) ) + { + logInfo( project, "Cached build violates cache rules, cannot restore" ); + return failure( info, context ); + } + + final String highestRequestPhase = Iterables.getLast( mojoExecutions ).getLifecyclePhase(); + final String highestCompletedGoal = info.getHighestCompletedGoal(); + if ( ProjectUtils.isLaterPhase( highestRequestPhase, highestCompletedGoal ) && !canIgnoreMissingSegment( + info, mojoExecutions ) ) + { + logInfo( project, + "Project restored partially. Highest cached goal: " + highestCompletedGoal + ", requested: " + + highestRequestPhase ); + return partialSuccess( info, context ); + } + + return success( info, context ); + } + else + { + logInfo( context.getProject(), "Project is not found in cache" ); + return empty( context ); + } + } + catch ( Exception e ) + { + logger.error( "Failed to restore project", e ); + localCache.clearCache( context ); + return empty( context ); + } + } + + private boolean canIgnoreMissingSegment( BuildInfo info, List mojoExecutions ) + { + final List postCachedSegment = info.getPostCachedSegment( mojoExecutions ); + for ( MojoExecution mojoExecution : postCachedSegment ) + { + if ( !cacheConfig.canIgnore( mojoExecution ) ) + { + return false; + } + } + return true; + } + + @Override + public boolean restoreProjectArtifacts( CacheResult cacheResult ) + { + + final BuildInfo buildInfo = cacheResult.getBuildInfo(); + final CacheContext context = cacheResult.getContext(); + final MavenProject project = context.getProject(); + + final ArtifactType artifact = buildInfo.getArtifact(); + artifact.setVersion( project.getVersion() ); + + try + { + if ( isNotBlank( artifact.getFileName() ) ) + { + // TODO if remote is forced, probably need to refresh or reconcile all files + final Path artifactFile = localCache.getArtifactFile( context, cacheResult.getSource(), artifact ); + if ( !Files.exists( artifactFile ) ) + { + logInfo( project, "Missing file for cached build, cannot restore. File: " + artifactFile ); + return false; + } + logDebug( project, "Setting project artifact " + artifact.getArtifactId() + " from: " + artifactFile ); + project.getArtifact().setFile( artifactFile.toFile() ); + project.getArtifact().setResolved( true ); + putChecksum( artifact, context.getInputInfo().getChecksum() ); + } + + for ( ArtifactType attachedArtifact : buildInfo.getAttachedArtifacts() ) + { + attachedArtifact.setVersion( project.getVersion() ); + if ( isNotBlank( attachedArtifact.getFileName() ) ) + { + final Path attachedArtifactFile = localCache.getArtifactFile( context, cacheResult.getSource(), + attachedArtifact ); + if ( !Files.exists( attachedArtifactFile ) ) + { + logInfo( project, + "Missing file for cached build, cannot restore project. File: " + + attachedArtifactFile ); + project.getArtifact().setFile( null ); + project.getArtifact().setResolved( false ); + project.getAttachedArtifacts().clear(); + return false; + } + logDebug( project, + "Attaching artifact " + artifact.getArtifactId() + " from: " + attachedArtifactFile ); + if ( StringUtils.startsWith( attachedArtifact.getClassifier(), GENERATEDSOURCES_PREFIX ) ) + { + // generated sources artifact + restoreGeneratedSources( attachedArtifact, attachedArtifactFile, project ); + } + else + { + projectHelper.attachArtifact( project, attachedArtifact.getType(), + attachedArtifact.getClassifier(), attachedArtifactFile.toFile() ); + } + putChecksum( attachedArtifact, context.getInputInfo().getChecksum() ); + } + } + } + catch ( Exception e ) + { + project.getArtifact().setFile( null ); + project.getArtifact().setResolved( false ); + project.getAttachedArtifacts().clear(); + logError( project, "Cannot restore cache, continuing with normal build.", e ); + return false; + } + + return true; + } + + private void putChecksum( ArtifactType artifact, String projectChecksum ) + { + + final DigestItemType projectArtifact = DtoUtils.createdDigestedByProjectChecksum( artifact, projectChecksum ); + final String dependencyKey = KeyUtils.getArtifactKey( artifact ); + artifactDigestByKey.put( dependencyKey, projectArtifact ); + + if ( !"pom".equals( artifact.getType() ) ) + { + final ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() ); + ArtifactType copy = DtoUtils.copy( artifact ); + copy.setType( artifactHandler.getPackaging() ); + artifactDigestByKey.put( KeyUtils.getArtifactKey( copy ), projectArtifact ); + copy.setType( artifactHandler.getExtension() ); + artifactDigestByKey.put( KeyUtils.getArtifactKey( copy ), projectArtifact ); + } + } + + private ProjectsInputInfoType calculateInput( MavenProject project, MavenSession session, + ProjectIndex projectIndex ) + { + try + { + final MavenProjectInput inputs = new MavenProjectInput( project, session, cacheConfig, projectIndex, + artifactDigestByKey, repoSystem, artifactHandlerManager, logger, localCache, remoteCache ); + return inputs.calculateChecksum( cacheConfig.getHashFactory() ); + } + catch ( Exception e ) + { + throw new RuntimeException( "Failed to calculate checksums for " + project.getArtifactId(), e ); + } + } + + @Override + public void save( CacheResult cacheResult, List mojoExecutions, + Map executionEvents ) + { + + CacheContext context = cacheResult.getContext(); + + if ( context == null || context.getInputInfo() == null ) + { + logger.info( "Cannot save project in cache, skipping" ); + return; + } + + final MavenProject project = context.getProject(); + final MavenSession session = context.getSession(); + try + { + + attachGeneratedSources( project ); + attachOutputs( project ); + + final Artifact projectArtifact = project.getArtifact(); + final HashFactory hashFactory = cacheConfig.getHashFactory(); + final HashAlgorithm algorithm = hashFactory.createAlgorithm(); + final ArtifactType projectArtifactDto = artifactDto( project.getArtifact(), algorithm ); + + final List attachedArtifacts = + project.getAttachedArtifacts() != null ? project.getAttachedArtifacts() : Collections.emptyList(); + List attachedArtifactDtos = artifactDtos( attachedArtifacts, algorithm ); + + List completedExecution = buildExecutionInfo( mojoExecutions, executionEvents ); + + final BuildInfo buildInfo = new BuildInfo( session.getGoals(), projectArtifactDto, attachedArtifactDtos, + context.getInputInfo(), completedExecution, hashFactory.getAlgorithm() ); + populateGitInfo( buildInfo, session ); + buildInfo.getDto().setFinal( cacheConfig.isSaveFinal() ); + cacheResults.put( getVersionlessProjectKey( project ), rebuilded( cacheResult, buildInfo ) ); + + // if package phase presence means new artifacts were packaged + if ( project.hasLifecyclePhase( "package" ) ) + { + localCache.beforeSave( context ); + localCache.saveBuildInfo( cacheResult, buildInfo ); + if ( projectArtifact.getFile() != null ) + { + localCache.saveArtifactFile( cacheResult, projectArtifact ); + putChecksum( projectArtifactDto, context.getInputInfo().getChecksum() ); + } + for ( Artifact attachedArtifact : attachedArtifacts ) + { + if ( attachedArtifact.getFile() != null && isOutputArtifact( + attachedArtifact.getFile().getName() ) ) + { + localCache.saveArtifactFile( cacheResult, attachedArtifact ); + } + } + for ( ArtifactType attachedArtifactDto : attachedArtifactDtos ) + { + putChecksum( attachedArtifactDto, context.getInputInfo().getChecksum() ); + } + } + else + { + localCache.saveBuildInfo( cacheResult, buildInfo ); + } + + if ( cacheConfig.isBaselineDiffEnabled() ) + { + produceDiffReport( cacheResult, buildInfo ); + } + + } + catch ( Exception e ) + { + try + { + logger.error( "Failed to save project, cleaning cache. Project: " + project, e ); + localCache.clearCache( context ); + } + catch ( Exception ex ) + { + logger.error( "Failed to clean cache due to unexpected error:", e ); + } + } + } + + public void produceDiffReport( CacheResult cacheResult, BuildInfo buildInfo ) + { + MavenProject project = cacheResult.getContext().getProject(); + Optional baselineHolder = remoteCache.findBaselineBuild( project ); + if ( baselineHolder.isPresent() ) + { + BuildInfo baseline = baselineHolder.get(); + String outputDirectory = project.getBuild().getDirectory(); + Path reportOutputDir = Paths.get( outputDirectory, "incremental-maven" ); + logInfo( project, "Saving cache builds diff to: " + reportOutputDir ); + BuildDiffType diff = new CacheDiff( buildInfo.getDto(), baseline.getDto(), cacheConfig ).compare(); + try + { + Files.createDirectories( reportOutputDir ); + final ProjectsInputInfoType baselineInputs = baseline.getDto().getProjectsInputInfo(); + final String checksum = baselineInputs.getChecksum(); + Files.write( reportOutputDir.resolve( "buildinfo-baseline-" + checksum + ".xml" ), + xmlService.toBytes( baseline.getDto() ), TRUNCATE_EXISTING, CREATE ); + Files.write( reportOutputDir.resolve( "buildinfo-" + checksum + ".xml" ), + xmlService.toBytes( buildInfo.getDto() ), TRUNCATE_EXISTING, CREATE ); + Files.write( reportOutputDir.resolve( "buildsdiff-" + checksum + ".xml" ), + xmlService.toBytes( diff ), TRUNCATE_EXISTING, CREATE ); + final Optional pom = CacheDiff.findPom( buildInfo.getDto().getProjectsInputInfo() ); + if ( pom.isPresent() ) + { + Files.write( reportOutputDir.resolve( "effective-pom-" + checksum + ".xml" ), + pom.get().getValue().getBytes( StandardCharsets.UTF_8 ), + TRUNCATE_EXISTING, CREATE ); + } + final Optional baselinePom = CacheDiff.findPom( baselineInputs ); + if ( baselinePom.isPresent() ) + { + Files.write( reportOutputDir.resolve( + "effective-pom-baseline-" + baselineInputs.getChecksum() + ".xml" ), + baselinePom.get().getValue().getBytes( StandardCharsets.UTF_8 ), + TRUNCATE_EXISTING, CREATE ); + } + } + catch ( IOException e ) + { + logError( project, "Cannot produce build diff for project", e ); + } + } + else + { + logInfo( project, "Cannot find project in baseline build, skipping diff" ); + } + } + + private List artifactDtos( List attachedArtifacts, HashAlgorithm digest ) throws IOException + { + List result = new ArrayList<>(); + for ( Artifact attachedArtifact : attachedArtifacts ) + { + if ( attachedArtifact.getFile() != null && isOutputArtifact( attachedArtifact.getFile().getName() ) ) + { + result.add( artifactDto( attachedArtifact, digest ) ); + } + } + return result; + } + + private ArtifactType artifactDto( Artifact projectArtifact, HashAlgorithm algorithm ) throws IOException + { + final ArtifactType dto = DtoUtils.createDto( projectArtifact ); + if ( projectArtifact.getFile() != null && projectArtifact.getFile().isFile() ) + { + final Path file = projectArtifact.getFile().toPath(); + dto.setFileHash( algorithm.hash( file ) ); + dto.setFileSize( BigInteger.valueOf( Files.size( file ) ) ); + } + return dto; + } + + private List buildExecutionInfo( List mojoExecutions, + Map executionEvents ) + { + List list = new ArrayList<>(); + for ( MojoExecution mojoExecution : mojoExecutions ) + { + final String executionKey = ProjectUtils.mojoExecutionKey( mojoExecution ); + final MojoExecutionEvent executionEvent = executionEvents.get( executionKey ); + CompletedExecutionType executionInfo = new CompletedExecutionType(); + executionInfo.setExecutionKey( executionKey ); + executionInfo.setMojoClassName( mojoExecution.getMojoDescriptor().getImplementation() ); + if ( executionEvent != null ) + { + recordMojoProperties( executionInfo, executionEvent ); + } + list.add( executionInfo ); + } + return list; + } + + private void recordMojoProperties( CompletedExecutionType execution, MojoExecutionEvent executionEvent ) + { + final MojoExecution mojoExecution = executionEvent.getExecution(); + + final boolean logAll = cacheConfig.isLogAllProperties( mojoExecution ); + List trackedProperties = cacheConfig.getTrackedProperties( mojoExecution ); + List noLogProperties = cacheConfig.getNologProperties( mojoExecution ); + List forceLogProperties = cacheConfig.getLoggedProperties( mojoExecution ); + final Mojo mojo = executionEvent.getMojo(); + + final File baseDir = executionEvent.getProject().getBasedir(); + final String baseDirPath = FilenameUtils.normalizeNoEndSeparator( baseDir.getAbsolutePath() ) + File.separator; + + final List parameters = mojoExecution.getMojoDescriptor().getParameters(); + for ( Parameter parameter : parameters ) + { + // editable parameters could be configured by user + if ( !parameter.isEditable() ) + { + continue; + } + + final String propertyName = parameter.getName(); + final boolean tracked = isTracked( propertyName, trackedProperties ); + if ( !tracked && isExcluded( propertyName, logAll, noLogProperties, forceLogProperties ) ) + { + continue; + } + + try + { + final Object value = ReflectionUtils.getValueIncludingSuperclasses( propertyName, mojo ); + DtoUtils.addProperty( execution, propertyName, value, baseDirPath, tracked ); + } + catch ( IllegalAccessException e ) + { + logInfo( executionEvent.getProject(), + "Cannot get property " + propertyName + " value from " + mojo + ": " + e.getMessage() ); + if ( tracked ) + { + throw new IllegalArgumentException( + "Property configured in cache introspection config for " + mojo + " is not accessible: " + + propertyName ); + } + } + } + } + + private boolean isExcluded( String propertyName, boolean logAll, List excludedProperties, + List forceLogProperties ) + { + + if ( !forceLogProperties.isEmpty() ) + { + for ( PropertyNameType logProperty : forceLogProperties ) + { + if ( StringUtils.equals( propertyName, logProperty.getPropertyName() ) ) + { + return false; + } + } + return true; + } + + if ( !excludedProperties.isEmpty() ) + { + for ( PropertyNameType excludedProperty : excludedProperties ) + { + if ( StringUtils.equals( propertyName, excludedProperty.getPropertyName() ) ) + { + return true; + } + } + return false; + } + + return !logAll; + } + + private boolean isTracked( String propertyName, List trackedProperties ) + { + for ( TrackedPropertyType trackedProperty : trackedProperties ) + { + if ( StringUtils.equals( propertyName, trackedProperty.getPropertyName() ) ) + { + return true; + } + } + return false; + } + + private boolean isCachedSegmentPropertiesPresent( MavenProject project, BuildInfo buildInfo, + List mojoExecutions ) + { + for ( MojoExecution mojoExecution : mojoExecutions ) + { + + // completion of all mojos checked above, so we expect tp have execution info here + final List trackedProperties = cacheConfig.getTrackedProperties( mojoExecution ); + final CompletedExecutionType cachedExecution = buildInfo.findMojoExecutionInfo( mojoExecution ); + + if ( cachedExecution == null ) + { + logInfo( project, + "Execution is not cached. Plugin: " + mojoExecution.getExecutionId() + ", goal" + + mojoExecution.getGoal() ); + return false; + } + + if ( !DtoUtils.containsAllProperties( cachedExecution, trackedProperties ) ) + { + logInfo( project, "Build info doesn't match rules. Plugin: " + mojoExecution.getExecutionId() ); + return false; + } + } + return true; + } + + private void logDebug( MavenProject project, String message ) + { + if ( logger.isDebugEnabled() ) + { + logger.debug( "[CACHE][" + project.getArtifactId() + "] " + message ); + } + } + + private void logInfo( MavenProject project, String message ) + { + logger.info( "[CACHE][" + project.getArtifactId() + "] " + message ); + } + + private void logError( MavenProject project, String message, Exception e ) + { + logger.error( "[CACHE][" + project.getArtifactId() + "] " + message, e ); + } + + @Override + public boolean isForcedExecution( MavenProject project, MojoExecution execution ) + { + + if ( cacheConfig.isForcedExecution( execution ) ) + { + return true; + } + final Properties properties = project.getProperties(); + final String alwaysRunPlugins = properties.getProperty( "remote.cache.alwaysRunPlugins" ); + ArrayList alwaysRunPluginsList = new ArrayList<>(); + if ( alwaysRunPlugins != null ) + { + alwaysRunPluginsList = Lists.newArrayList( split( alwaysRunPlugins, "," ) ); + } + for ( String pluginAndGoal : alwaysRunPluginsList ) + { + final String[] tokens = pluginAndGoal.split( ":" ); + final String alwaysRunPlugin = tokens[0]; + String alwaysRunGoal = tokens.length == 1 ? "*" : tokens[1]; + if ( StringUtils.equals( execution.getPlugin().getArtifactId(), alwaysRunPlugin ) && ( "*".equals( + alwaysRunGoal ) || StringUtils.equals( execution.getGoal(), alwaysRunGoal ) ) ) + { + return true; + } + } + return false; + } + + @Override + public void saveCacheReport( MavenSession session ) + { + try + { + + CacheReportType cacheReport = new CacheReportType(); + for ( CacheResult result : cacheResults.values() ) + { + ProjectReportType projectReport = new ProjectReportType(); + CacheContext context = result.getContext(); + MavenProject project = context.getProject(); + projectReport.setGroupId( project.getGroupId() ); + projectReport.setArtifactId( project.getArtifactId() ); + projectReport.setChecksum( context.getInputInfo().getChecksum() ); + boolean checksumMatched = result.getStatus() != RestoreStatus.EMPTY; + projectReport.setChecksumMatched( checksumMatched ); + projectReport.setLifecycleMatched( checksumMatched && result.isSuccess() ); + projectReport.setSource( String.valueOf( result.getSource() ) ); + if ( result.getSource() == CacheSource.REMOTE ) + { + projectReport.setUrl( remoteCache.getResourceUrl( context, BUILDINFO_XML ) ); + } + else if ( result.getSource() == CacheSource.BUILD && cacheConfig.isSaveToRemote() ) + { + projectReport.setSharedToRemote( true ); + projectReport.setUrl( remoteCache.getResourceUrl( context, BUILDINFO_XML ) ); + } + cacheReport.getProject().add( projectReport ); + } + + String buildId = UUID.randomUUID().toString(); + localCache.saveCacheReport( buildId, session, cacheReport ); + } + catch ( Exception e ) + { + logger.error( "Cannot save incremental build aggregated report", e ); + } + } + + private void populateGitInfo( BuildInfo buildInfo, MavenSession session ) throws IOException + { + if ( scm == null ) + { + synchronized ( this ) + { + if ( scm == null ) + { + try + { + scm = ProjectUtils.readGitInfo( session ); + } + catch ( IOException e ) + { + scm = new BuildInfoType.Scm(); + logger.error( "Cannot populate git info", e ); + } + } + } + } + buildInfo.getDto().setScm( scm ); + } + + private void zipAndAttachArtifact( MavenProject project, Path dir, String classifier ) throws IOException + { + + try ( final InputStream inputStream = ZipUtils.zipFolder( dir ) ) + { + File tempFile = File.createTempFile( "maven-incremental", project.getArtifactId() ); + tempFile.deleteOnExit(); + Files.copy( inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING ); + projectHelper.attachArtifact( project, "zip", classifier, tempFile ); + } + } + + private String pathToClassifier( Path relative ) + { + final int nameCount = relative.getNameCount(); + List segments = new ArrayList<>( nameCount + 1 ); + for ( int i = 0; i < nameCount; i++ ) + { + segments.add( relative.getName( i ).toFile().getName() ); + } + // todo handle _ in file names + return GENERATEDSOURCES_PREFIX + StringUtils.join( segments.iterator(), FILE_SEPARATOR_SUBST ); + } + + private Path classifierToPath( Path outputDir, String classifier ) + { + classifier = StringUtils.removeStart( classifier, GENERATEDSOURCES_PREFIX ); + final String relPath = replace( classifier, FILE_SEPARATOR_SUBST, File.separator ); + return outputDir.resolve( relPath ); + } + + private void restoreGeneratedSources( ArtifactType artifact, Path artifactFilePath, MavenProject project ) + throws IOException + { + final Path targetDir = Paths.get( project.getBuild().getDirectory() ); + final Path outputDir = classifierToPath( targetDir, artifact.getClassifier() ); + try ( InputStream is = Files.newInputStream( artifactFilePath ) ) + { + if ( Files.exists( outputDir ) ) + { + FileUtils.cleanDirectory( outputDir.toFile() ); + } + else + { + Files.createDirectories( outputDir ); + } + ZipUtils.unzip( is, outputDir ); + } + } + + //TODO: move to config + public void attachGeneratedSources( MavenProject project ) throws IOException + { + final Path targetDir = Paths.get( project.getBuild().getDirectory() ); + + final Path generatedSourcesDir = targetDir.resolve( "generated-sources" ); + attachDirIfNotEmpty( generatedSourcesDir, targetDir, project ); + + final Path generatedTestSourcesDir = targetDir.resolve( "generated-test-sources" ); + attachDirIfNotEmpty( generatedTestSourcesDir, targetDir, project ); + + Set sourceRoots = new TreeSet<>(); + if ( project.getCompileSourceRoots() != null ) + { + sourceRoots.addAll( project.getCompileSourceRoots() ); + } + if ( project.getTestCompileSourceRoots() != null ) + { + sourceRoots.addAll( project.getTestCompileSourceRoots() ); + } + + for ( String sourceRoot : sourceRoots ) + { + final Path sourceRootPath = Paths.get( sourceRoot ); + if ( Files.isDirectory( sourceRootPath ) && sourceRootPath.startsWith( + targetDir ) && !( sourceRootPath.startsWith( generatedSourcesDir ) || sourceRootPath.startsWith( + generatedTestSourcesDir ) ) ) + { // dir within target + attachDirIfNotEmpty( sourceRootPath, targetDir, project ); + } + } + } + + private void attachOutputs( MavenProject project ) throws IOException + { + final List attachedDirs = cacheConfig.getAttachedOutputs(); + for ( String dir : attachedDirs ) + { + final Path targetDir = Paths.get( project.getBuild().getDirectory() ); + final Path outputDir = targetDir.resolve( dir ); + attachDirIfNotEmpty( outputDir, targetDir, project ); + } + } + + private void attachDirIfNotEmpty( Path candidateSubDir, Path parentDir, MavenProject project ) throws IOException + { + if ( Files.isDirectory( candidateSubDir ) && hasFiles( candidateSubDir ) ) + { + final Path relativePath = parentDir.relativize( candidateSubDir ); + final String classifier = pathToClassifier( relativePath ); + zipAndAttachArtifact( project, candidateSubDir, classifier ); + logDebug( project, "Attached directory: " + candidateSubDir ); + } + } + + private boolean hasFiles( Path candidateSubDir ) throws IOException + { + final MutableBoolean hasFiles = new MutableBoolean(); + Files.walkFileTree( candidateSubDir, new SimpleFileVisitor() + { + @Override + public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttributes ) + { + hasFiles.setTrue(); + return FileVisitResult.TERMINATE; + } + } ); + return hasFiles.booleanValue(); + } + + private boolean isOutputArtifact( String name ) + { + List excludePatterns = cacheConfig.getExcludePatterns(); + for ( Pattern pattern : excludePatterns ) + { + if ( pattern.matcher( name ).matches() ) + { + return false; + } + } + return true; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java b/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java new file mode 100644 index 000000000000..9e066a598eff --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java @@ -0,0 +1,345 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.google.common.base.Optional; +import com.google.common.collect.Sets; +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.caching.jaxb.BuildDiffType; +import org.apache.maven.caching.jaxb.BuildInfoType; +import org.apache.maven.caching.jaxb.CompletedExecutionType; +import org.apache.maven.caching.jaxb.DigestItemType; +import org.apache.maven.caching.jaxb.MismatchType; +import org.apache.maven.caching.jaxb.ProjectsInputInfoType; +import org.apache.maven.caching.jaxb.PropertyValueType; +import org.apache.maven.caching.xml.CacheConfig; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * Utility class for comparing 2 builds + */ +public class CacheDiff +{ + + private final CacheConfig config; + private final BuildInfoType current; + private final BuildInfoType baseline; + private final LinkedList report; + + public CacheDiff( BuildInfoType current, BuildInfoType baseline, CacheConfig config ) + { + this.current = current; + this.baseline = baseline; + this.config = config; + this.report = new LinkedList<>(); + } + + public BuildDiffType compare() + { + + if ( !StringUtils.equals( current.getHashFunction(), baseline.getHashFunction() ) ) + { + addNewMismatch( + "hashFunction", + current.getHashFunction(), + baseline.getHashFunction(), + "Different algorithms render caches not comparable and cached could not be reused", + "Ensure the same algorithm as remote" + ); + } + compareEffectivePoms( current.getProjectsInputInfo(), baseline.getProjectsInputInfo() ); + compareExecutions( current.getExecutions(), baseline.getExecutions() ); + compareFiles( current.getProjectsInputInfo(), baseline.getProjectsInputInfo() ); + compareDependencies( current.getProjectsInputInfo(), baseline.getProjectsInputInfo() ); + + final BuildDiffType buildDiffType = new BuildDiffType(); + buildDiffType.getMismatch().addAll( report ); + return buildDiffType; + } + + private void compareEffectivePoms( ProjectsInputInfoType current, ProjectsInputInfoType baseline ) + { + Optional currentPom = findPom( current ); + String currentPomHash = currentPom.isPresent() ? currentPom.get().getHash() : null; + + Optional baseLinePom = findPom( baseline ); + String baselinePomHash = baseLinePom.isPresent() ? baseLinePom.get().getHash() : null; + + if ( !StringUtils.equals( currentPomHash, baselinePomHash ) ) + { + addNewMismatch( + "effectivePom", currentPomHash, baselinePomHash, + "Difference in effective pom suggests effectively different builds which cannot be reused", + "Compare raw content of effective poms and eliminate differences. " + + "See How-To for common techniques" + ); + } + } + + public static Optional findPom( ProjectsInputInfoType projectInputs ) + { + for ( DigestItemType digestItemType : projectInputs.getItem() ) + { + if ( "pom".equals( digestItemType.getType() ) ) + { + return Optional.of( digestItemType ); + + } + } + return Optional.absent(); + } + + private void compareFiles( ProjectsInputInfoType current, ProjectsInputInfoType baseline ) + { + + final Map currentFiles = new HashMap<>(); + for ( DigestItemType item : current.getItem() ) + { + if ( "file".equals( item.getType() ) ) + { + currentFiles.put( item.getValue(), item ); + } + } + + final Map baselineFiles = new HashMap<>(); + for ( DigestItemType item : baseline.getItem() ) + { + if ( "file".equals( item.getType() ) ) + { + baselineFiles.put( item.getValue(), item ); + } + } + + final Sets.SetView currentVsBaseline = Sets.difference( currentFiles.keySet(), baselineFiles.keySet() ); + final Sets.SetView baselineVsCurrent = Sets.difference( baselineFiles.keySet(), currentFiles.keySet() ); + + if ( !currentVsBaseline.isEmpty() || !baselineVsCurrent.isEmpty() ) + { + addNewMismatch( "source files", + "Remote and local cache contain different sets of input files. " + + "Added files: " + currentVsBaseline + ". Removed files: " + baselineVsCurrent, + "To match remote and local caches should have identical file sets." + + " Unnecessary and transient files must be filtered out to make file sets match" + + " - see configuration guide" + ); + return; + } + + for ( Map.Entry entry : currentFiles.entrySet() ) + { + String filePath = entry.getKey(); + DigestItemType currentFile = entry.getValue(); + // should be null safe because sets are compared above for differences + final DigestItemType baselineFile = baselineFiles.get( filePath ); + if ( !StringUtils.equals( currentFile.getHash(), baselineFile.getHash() ) ) + { + + String reason = "File content is different."; + if ( currentFile.getEol() != null && baselineFile.getEol() != null && !StringUtils.equals( + baselineFile.getEol(), currentFile.getEol() ) ) + { + reason += " Different line endings detected (text files relevant). " + + "Remote: " + baselineFile.getEol() + ", local: " + currentFile.getEol() + "."; + } + if ( currentFile.getCharset() != null && baselineFile.getCharset() != null && !StringUtils.equals( + baselineFile.getCharset(), currentFile.getCharset() ) ) + { + reason += " Different charset detected (text files relevant). " + + "Remote: " + baselineFile.getEol() + ", local: " + currentFile.getEol() + "."; + } + + addNewMismatch( filePath, currentFile.getHash(), baselineFile.getHash(), reason, + "Different content manifests different build outcome. " + + "Ensure that difference is not caused by environment specifics, like line separators" + ); + } + } + } + + private void compareDependencies( ProjectsInputInfoType current, ProjectsInputInfoType baseline ) + { + final Map currentDependencies = new HashMap<>(); + for ( DigestItemType digestItemType : current.getItem() ) + { + if ( "dependency".equals( digestItemType.getType() ) ) + { + currentDependencies.put( digestItemType.getValue(), digestItemType ); + } + } + final Map baselineDependencies = new HashMap<>(); + for ( DigestItemType item : baseline.getItem() ) + { + if ( "dependency".equals( item.getType() ) ) + { + baselineDependencies.put( item.getValue(), item ); + } + } + + final Sets.SetView currentVsBaseline = + Sets.difference( currentDependencies.keySet(), baselineDependencies.keySet() ); + final Sets.SetView baselineVsCurrent = + Sets.difference( baselineDependencies.keySet(), currentDependencies.keySet() ); + + if ( !currentVsBaseline.isEmpty() || !baselineVsCurrent.isEmpty() ) + { + addNewMismatch( "dependencies files", + "Remote and local builds contain different sets of dependencies and cannot be matched. " + + "Added dependencies: " + currentVsBaseline + ". Removed dependencies: " + + baselineVsCurrent, + "Remote and local builds should have identical dependencies. " + + "The difference manifests changes in downstream dependencies or introduced snapshots." + ); + return; + } + + for ( Map.Entry entry : currentDependencies.entrySet() ) + { + String dependencyKey = entry.getKey(); + DigestItemType currentDependency = entry.getValue(); + // null safe - sets compared for differences above + final DigestItemType baselineDependency = baselineDependencies.get( dependencyKey ); + if ( !StringUtils.equals( currentDependency.getHash(), baselineDependency.getHash() ) ) + { + addNewMismatch( dependencyKey, currentDependency.getHash(), baselineDependency.getHash(), + "Downstream project or snapshot changed", + "Find downstream project and investigate difference in the downstream project. " + + "Enable fail fast mode and single threaded execution to simplify debug." + ); + } + } + } + + + private void compareExecutions( BuildInfoType.Executions current, BuildInfoType.Executions baseline ) + { + Map baselineExecutionsByKey = new HashMap<>(); + for ( CompletedExecutionType completedExecutionType : baseline.getExecution() ) + { + baselineExecutionsByKey.put( completedExecutionType.getExecutionKey(), completedExecutionType ); + } + + Map currentExecutionsByKey = new HashMap<>(); + for ( CompletedExecutionType e1 : current.getExecution() ) + { + currentExecutionsByKey.put( e1.getExecutionKey(), e1 ); + } + + // such situation normally means different poms and mismatch in effective poms, + // but in any case it is helpful to report + for ( CompletedExecutionType baselineExecution : baseline.getExecution() ) + { + if ( !currentExecutionsByKey.containsKey( baselineExecution.getExecutionKey() ) ) + { + addNewMismatch( + baselineExecution.getExecutionKey(), + "Baseline build contains excessive plugin " + baselineExecution.getExecutionKey(), + "Different set of plugins produces different build results. " + + "Exclude non-critical plugins or make sure plugin sets match" + ); + } + } + + for ( CompletedExecutionType currentExecution : current.getExecution() ) + { + if ( !baselineExecutionsByKey.containsKey( currentExecution.getExecutionKey() ) ) + { + addNewMismatch( + currentExecution.getExecutionKey(), + "Cached build doesn't contain plugin " + currentExecution.getExecutionKey(), + "Different set of plugins produces different build results. " + + "Filter out non-critical plugins or make sure remote cache always run full build " + + "with all plugins" + ); + continue; + } + + final CompletedExecutionType baselineExecution = + baselineExecutionsByKey.get( currentExecution.getExecutionKey() ); + comparePlugins( currentExecution, baselineExecution ); + } + } + + private void comparePlugins( CompletedExecutionType current, CompletedExecutionType baseline ) + { + // TODO add support for skip values + final List trackedProperties = new ArrayList<>(); + for ( PropertyValueType propertyValueType : current.getConfiguration().getProperty() ) + { + if ( propertyValueType.isTracked() ) + { + trackedProperties.add( propertyValueType ); + } + } + if ( trackedProperties.isEmpty() ) + { + return; + } + + final Map baselinePropertiesByName = new HashMap<>(); + for ( PropertyValueType propertyValueType : baseline.getConfiguration().getProperty() ) + { + baselinePropertiesByName.put( propertyValueType.getName(), propertyValueType ); + } + + for ( PropertyValueType p : trackedProperties ) + { + final PropertyValueType baselineValue = baselinePropertiesByName.get( p.getName() ); + if ( baselineValue == null || !StringUtils.equals( baselineValue.getValue(), p.getValue() ) ) + { + addNewMismatch( + p.getName(), + p.getValue(), + baselineValue == null ? null : baselineValue.getValue(), + "Plugin: " + current.getExecutionKey() + + " has mismatch in tracked property and cannot be reused", + "Align properties between remote and local build or remove property from tracked " + + "list if mismatch could be tolerated. In some cases it is possible to add skip value " + + "to ignore lax mismatch" + ); + } + } + } + + private void addNewMismatch( String item, String current, String baseline, String reason, + String resolution ) + { + final MismatchType mismatch = new MismatchType(); + mismatch.setItem( item ); + mismatch.setCurrent( current ); + mismatch.setBaseline( baseline ); + mismatch.setReason( reason ); + mismatch.setResolution( resolution ); + report.add( mismatch ); + } + + private void addNewMismatch( String property, String reason, String resolution ) + { + final MismatchType mismatchType = new MismatchType(); + mismatchType.setItem( property ); + mismatchType.setReason( reason ); + mismatchType.setResolution( resolution ); + report.add( mismatchType ); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java b/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java new file mode 100644 index 000000000000..99f7e1a72542 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java @@ -0,0 +1,49 @@ +package org.apache.maven.caching; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.eventspy.AbstractEventSpy; +import org.apache.maven.eventspy.EventSpy; +import org.apache.maven.execution.ExecutionEvent; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; + +/** + * Triggers cache report generation on build completion + */ +@Component( role = EventSpy.class ) +public class CacheEventSpy extends AbstractEventSpy +{ + @Requirement + private CacheController cacheController; + + @Override + public void onEvent( Object event ) throws Exception + { + if ( event instanceof ExecutionEvent ) + { + ExecutionEvent executionEvent = (ExecutionEvent) event; + if ( executionEvent.getType() == ExecutionEvent.Type.SessionEnded ) + { + cacheController.saveCacheReport( executionEvent.getSession() ); + } + } + } +} \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheResult.java b/maven-core/src/main/java/org/apache/maven/caching/CacheResult.java new file mode 100644 index 000000000000..8d886764f8b8 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheResult.java @@ -0,0 +1,122 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.CacheSource; + +import static java.util.Objects.requireNonNull; + +/** + * CacheResult + */ +public class CacheResult +{ + private final RestoreStatus status; + private final BuildInfo buildInfo; + private final CacheContext context; + + private CacheResult( RestoreStatus status, BuildInfo buildInfo, CacheContext context ) + { + this.status = requireNonNull( status ); + this.buildInfo = buildInfo; + this.context = context; + } + + public static CacheResult empty( CacheContext context ) + { + requireNonNull( context ); + return new CacheResult( RestoreStatus.EMPTY, null, context ); + } + + public static CacheResult empty() + { + return new CacheResult( RestoreStatus.EMPTY, null, null ); + } + + public static CacheResult failure( BuildInfo buildInfo, CacheContext context ) + { + requireNonNull( buildInfo ); + requireNonNull( context ); + return new CacheResult( RestoreStatus.FAILURE, buildInfo, context ); + } + + public static CacheResult success( BuildInfo buildInfo, CacheContext context ) + { + requireNonNull( buildInfo ); + requireNonNull( context ); + return new CacheResult( RestoreStatus.SUCCESS, buildInfo, context ); + } + + public static CacheResult partialSuccess( BuildInfo buildInfo, CacheContext context ) + { + requireNonNull( buildInfo ); + requireNonNull( context ); + return new CacheResult( RestoreStatus.PARTIAL, buildInfo, context ); + } + + public static CacheResult failure( CacheContext context ) + { + requireNonNull( context ); + return new CacheResult( RestoreStatus.FAILURE, null, context ); + } + + public static CacheResult rebuilded( CacheResult orig, BuildInfo buildInfo ) + { + requireNonNull( orig ); + requireNonNull( buildInfo ); + return new CacheResult( orig.status, buildInfo, orig.context ); + } + + public boolean isSuccess() + { + return status == RestoreStatus.SUCCESS; + } + + public BuildInfo getBuildInfo() + { + return buildInfo; + } + + public CacheSource getSource() + { + return buildInfo != null ? buildInfo.getSource() : null; + } + + public CacheContext getContext() + { + return context; + } + + public boolean isPartialSuccess() + { + return status == RestoreStatus.PARTIAL; + } + + public RestoreStatus getStatus() + { + return status; + } + + public boolean isFinal() + { + return buildInfo != null && buildInfo.getDto().isFinal(); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/Clock.java b/maven-core/src/main/java/org/apache/maven/caching/Clock.java new file mode 100644 index 000000000000..ce0c487c669c --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/Clock.java @@ -0,0 +1,42 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import static java.util.concurrent.TimeUnit.NANOSECONDS; + +/** + * Clock + */ +public class Clock +{ + public static long time() + { + return System.nanoTime(); + } + + public static long elapsed( long time ) + { + return NANOSECONDS.toMillis( time() - time ); + } + + private Clock() + { + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java b/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java new file mode 100644 index 000000000000..408d097cf10e --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java @@ -0,0 +1,63 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.caching.jaxb.DirScanConfigType; + +import javax.annotation.Nonnull; + +/** + * DefaultPluginScanConfig + */ +public class DefaultPluginScanConfig implements PluginScanConfig +{ + + @Override + public boolean isSkip() + { + return false; + } + + @Override + public boolean accept( String propertyName ) + { + return true; + } + + @Override + @Nonnull + public PluginScanConfig mergeWith( PluginScanConfig overrideSource ) + { + return overrideSource; + } + + @Nonnull + @Override + public ScanConfigProperties getTagScanProperties( String tagName ) + { + return new ScanConfigProperties( true, "*" ); + } + + @Override + public DirScanConfigType dto() + { + return null; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java new file mode 100644 index 000000000000..fbbe509bb28d --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java @@ -0,0 +1,336 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.google.common.base.Optional; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpHead; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.entity.InputStreamEntity; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.caching.checksum.MavenProjectInput; +import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.caching.jaxb.BuildInfoType; +import org.apache.maven.caching.jaxb.CacheReportType; +import org.apache.maven.caching.jaxb.ProjectReportType; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.CacheSource; +import org.apache.maven.caching.xml.XmlService; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.LegacySupport; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.logging.Logger; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; + +/** + * HttpRepositoryImpl + */ +@Component( role = RemoteArtifactsRepository.class ) +public class HttpRepositoryImpl implements RemoteArtifactsRepository +{ + + public static final String BUILDINFO_XML = "buildinfo.xml"; + public static final String CACHE_REPORT_XML = "cache-report.xml"; + + @Requirement + private Logger logger; + + @Requirement + LegacySupport legacySupport; + + @Requirement + XmlService xmlService; + + @Requirement + private CacheConfig cacheConfig; + + @SuppressWarnings( {"checkstyle:constantname", "checkstyle:magicnumber"} ) + private static final ThreadLocal httpClient = new ThreadLocal() + { + @Override + protected HttpClient initialValue() + { + int timeoutSeconds = 60; + RequestConfig config = RequestConfig.custom().setConnectTimeout( + timeoutSeconds * 1000 ).setConnectionRequestTimeout( timeoutSeconds * 1000 ).setSocketTimeout( + timeoutSeconds * 1000 ).build(); + return HttpClientBuilder.create().setDefaultRequestConfig( config ).build(); + } + }; + + @Override + public BuildInfo findBuild( CacheContext context ) + { + final String resourceUrl = getResourceUrl( context, BUILDINFO_XML ); + String artifactId = context.getProject().getArtifactId(); + if ( exists( artifactId, resourceUrl ) ) + { + final byte[] bytes = getResourceContent( resourceUrl, artifactId ); + final BuildInfoType dto = xmlService.fromBytes( BuildInfoType.class, bytes ); + return new BuildInfo( dto, CacheSource.REMOTE ); + } + return null; + } + + @Override + public byte[] getArtifactContent( CacheContext context, ArtifactType artifact ) + { + return getResourceContent( getResourceUrl( context, artifact.getFileName() ), + context.getProject().getArtifactId() ); + } + + @Override + public void saveBuildInfo( CacheResult cacheResult, BuildInfo buildInfo ) throws IOException + { + CacheContext context = cacheResult.getContext(); + final String resourceUrl = getResourceUrl( cacheResult.getContext(), BUILDINFO_XML ); + putToRemoteCache( new ByteArrayInputStream( xmlService.toBytes( buildInfo.getDto() ) ), resourceUrl, + context.getProject().getArtifactId() ); + } + + + @Override + public void saveCacheReport( String buildId, MavenSession session, CacheReportType cacheReport ) throws IOException + { + MavenProject rootProject = session.getTopLevelProject(); + final String resourceUrl = cacheConfig.getUrl() + "/" + MavenProjectInput.CACHE_IMPLMENTATION_VERSION + + "/" + rootProject.getGroupId() + + "/" + rootProject.getArtifactId() + + "/" + buildId + + "/" + CACHE_REPORT_XML; + putToRemoteCache( new ByteArrayInputStream( xmlService.toBytes( cacheReport ) ), resourceUrl, + rootProject.getArtifactId() ); + } + + @Override + public void saveArtifactFile( CacheResult cacheResult, Artifact artifact ) throws IOException + { + CacheContext context = cacheResult.getContext(); + final String resourceUrl = getResourceUrl( cacheResult.getContext(), ProjectUtils.normalizedName( artifact ) ); + try ( InputStream inputStream = Files.newInputStream( artifact.getFile().toPath() ) ) + { + putToRemoteCache( inputStream, resourceUrl, context.getProject().getArtifactId() ); + } + } + + @SuppressWarnings( "checkstyle:magicnumber" ) + private boolean exists( String logReference, String url ) + { + HttpHead head = null; + try + { + head = new HttpHead( url ); + HttpResponse response = httpClient.get().execute( head ); + int statusCode = response.getStatusLine().getStatusCode(); + logger.info( "[CACHE][" + logReference + "] Checking " + url + ". Status: " + statusCode ); + return statusCode == 200; + } + catch ( IOException e ) + { + throw new RuntimeException( "Cannot check " + url, e ); + } + finally + { + if ( head != null ) + { + head.releaseConnection(); + } + } + } + + @SuppressWarnings( "checkstyle:magicnumber" ) + public byte[] getResourceContent( String url, String logReference ) + { + HttpGet get = null; + try + { + get = new HttpGet( url ); + HttpResponse response = httpClient.get().execute( get ); + int statusCode = response.getStatusLine().getStatusCode(); + logger.info( "[CACHE][" + logReference + "] Downloading " + url + ". Status: " + statusCode ); + if ( statusCode != 200 ) + { + throw new RuntimeException( "Cannot download " + url + ", unexpected status code: " + statusCode ); + } + try ( InputStream content = response.getEntity().getContent() ) + { + return IOUtils.toByteArray( content ); + } + } + catch ( IOException e ) + { + throw new RuntimeException( "Cannot get " + url, e ); + } + finally + { + if ( get != null ) + { + get.releaseConnection(); + } + } + } + + @Override + public String getResourceUrl( CacheContext context, String filename ) + { + return getResourceUrl( filename, context.getProject().getGroupId(), context.getProject().getArtifactId(), + context.getInputInfo().getChecksum() ); + } + + private String getResourceUrl( String filename, String groupId, String artifactId, String checksum ) + { + return cacheConfig.getUrl() + "/" + MavenProjectInput.CACHE_IMPLMENTATION_VERSION + "/" + groupId + "/" + + artifactId + "/" + checksum + "/" + filename; + } + + /** + * @param logReference + * @param instream to be closed externally + */ + private void putToRemoteCache( InputStream instream, String url, String logReference ) throws IOException + { + + HttpPut httpPut = null; + try + { + httpPut = new HttpPut( url ); + httpPut.setEntity( new InputStreamEntity( instream ) ); + HttpResponse response = httpClient.get().execute( httpPut ); + int statusCode = response.getStatusLine().getStatusCode(); + logInfo( "Saved to remote cache " + url + ". RESPONSE CODE: " + statusCode, logReference ); + } + finally + { + if ( httpPut != null ) + { + httpPut.releaseConnection(); + } + } + } + + private final AtomicReference>> cacheReportSupplier = new AtomicReference<>(); + + @Override + public Optional findBaselineBuild( MavenProject project ) + { + final Optional> cachedProjectsHolder = findCacheInfo() + .transform( CacheReportType::getProject ); + if ( !cachedProjectsHolder.isPresent() ) + { + return Optional.absent(); + } + + Optional cachedProjectHolder = Optional.absent(); + for ( ProjectReportType p : cachedProjectsHolder.get() ) + { + if ( project.getArtifactId().equals( p.getArtifactId() ) && project.getGroupId().equals( + p.getGroupId() ) ) + { + cachedProjectHolder = Optional.of( p ); + break; + } + } + + if ( cachedProjectHolder.isPresent() ) + { + String url; + final ProjectReportType projectReport = cachedProjectHolder.get(); + if ( projectReport.isSetUrl() ) + { + url = cachedProjectHolder.get().getUrl(); + logInfo( "Retrieving baseline buildinfo: " + projectReport.getUrl(), project.getArtifactId() ); + } + else + { + url = getResourceUrl( BUILDINFO_XML, project.getGroupId(), + project.getArtifactId(), projectReport.getChecksum() ); + logInfo( "Baseline project record doesn't have url, trying default location", project.getArtifactId() ); + } + + try + { + if ( exists( project.getArtifactId(), url ) ) + { + byte[] content = getResourceContent( url, project.getArtifactId() ); + final BuildInfoType dto = xmlService.fromBytes( BuildInfoType.class, content ); + return Optional.of( new BuildInfo( dto, CacheSource.REMOTE ) ); + } + else + { + logInfo( "Project buildinfo not found, skipping diff", + project.getArtifactId() ); + } + } + catch ( Exception e ) + { + logger.warn( "[CACHE][" + project.getArtifactId() + "] Error restoring baseline build at url: " + + projectReport.getUrl() + ", skipping diff" ); + return Optional.absent(); + } + } + return Optional.absent(); + } + + private Optional findCacheInfo() + { + + Supplier> candidate = Suppliers.memoize( () -> + { + try + { + logInfo( "Downloading baseline cache report from: " + cacheConfig.getBaselineCacheUrl(), + "DEBUG" ); + byte[] content = getResourceContent( cacheConfig.getBaselineCacheUrl(), "cache-info" ); + CacheReportType cacheReportType = xmlService.fromBytes( CacheReportType.class, content ); + return Optional.of( cacheReportType ); + } + catch ( Exception e ) + { + logger.error( "Error downloading baseline report from: " + cacheConfig.getBaselineCacheUrl() + + ", skipping diff.", e ); + return Optional.absent(); + } + } ); + cacheReportSupplier.compareAndSet( null, candidate ); + + return cacheReportSupplier.get().get(); + } + + private void logInfo( String message, String logReference ) + { + logger.info( "[CACHE][" + logReference + "] " + message ); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java b/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java new file mode 100644 index 000000000000..c5916b2c64ba --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java @@ -0,0 +1,47 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.google.common.base.Optional; +import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.CacheSource; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; + +import java.io.IOException; +import java.nio.file.Path; + +/** + * LocalArtifactsRepository + */ +public interface LocalArtifactsRepository extends ArtifactsRepository +{ + + void beforeSave( CacheContext environment ) throws IOException; + + Path getArtifactFile( CacheContext context, CacheSource source, ArtifactType artifact ) throws IOException; + + void clearCache( CacheContext context ); + + Optional findBestMatchingBuild( MavenSession session, Dependency dependency ) throws IOException; + + BuildInfo findLocalBuild( CacheContext context ) throws IOException; +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java new file mode 100644 index 000000000000..ec75b476e4b4 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java @@ -0,0 +1,496 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.google.common.base.Function; +import com.google.common.base.Optional; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Multimap; +import com.google.common.collect.Ordering; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.caching.jaxb.BuildInfoType; +import org.apache.maven.caching.jaxb.CacheReportType; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.CacheSource; +import org.apache.maven.caching.xml.XmlService; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.LegacySupport; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.logging.Logger; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; + +import static java.nio.file.StandardOpenOption.CREATE; +import static java.nio.file.StandardOpenOption.CREATE_NEW; +import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; +import static java.util.concurrent.TimeUnit.DAYS; +import static java.util.concurrent.TimeUnit.HOURS; +import static java.util.concurrent.TimeUnit.MINUTES; +import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.apache.maven.caching.ProjectUtils.getMultimoduleRoot; +import static org.apache.maven.caching.checksum.MavenProjectInput.CACHE_IMPLMENTATION_VERSION; + +/** + * LocalRepositoryImpl + */ +@Component( role = LocalArtifactsRepository.class ) +public class LocalRepositoryImpl implements LocalArtifactsRepository +{ + + private static final String BUILDINFO_XML = "buildinfo.xml"; + private static final String LOOKUPINFO_XML = "lookupinfo.xml"; + private static final long ONE_HOUR_MILLIS = HOURS.toMillis( 1 ); + private static final long ONE_MINUTE_MILLIS = MINUTES.toMillis( 1 ); + private static final long ONE_DAY_MILLIS = DAYS.toMillis( 1 ); + private static final String EMPTY = ""; + private static final LastModifiedComparator LAST_MODIFIED_COMPARATOR = new LastModifiedComparator(); + private static final Function, Long> GET_LAST_MODIFIED = + pair -> pair.getRight().lastModified(); + + @Requirement + private Logger logger; + + @Requirement + private LegacySupport legacySupport; + + @Requirement + private RemoteArtifactsRepository remoteRepository; + + @Requirement + private XmlService xmlService; + + @Requirement + private CacheConfig cacheConfig; + + private final LoadingCache, Optional> bestBuildCache = + CacheBuilder.newBuilder().build( + CacheLoader.from( new Function, Optional>() + { + @Override + public Optional apply( Pair input ) + { + try + { + return findBestMatchingBuildImpl( input ); + } + catch ( IOException e ) + { + logger.error( "Cannot find dependency in cache", e ); + return Optional.absent(); + } + } + } ) ); + + @Override + public BuildInfo findLocalBuild( CacheContext context ) throws IOException + { + Path localBuildInfoPath = localBuildPath( context, BUILDINFO_XML, false ); + logDebug( context, "Checking local build info: " + localBuildInfoPath ); + if ( Files.exists( localBuildInfoPath ) ) + { + logInfo( context, "Local build found by checksum " + context.getInputInfo().getChecksum() ); + try + { + final BuildInfoType dto = xmlService.fromFile( BuildInfoType.class, localBuildInfoPath.toFile() ); + return new BuildInfo( dto, CacheSource.LOCAL ); + } + catch ( Exception e ) + { + logger.error( "Local build info is not valid, deleting: " + localBuildInfoPath, e ); + Files.delete( localBuildInfoPath ); + } + } + return null; + } + + @Override + public BuildInfo findBuild( CacheContext context ) throws IOException + { + + Path buildInfoPath = remoteBuildPath( context, BUILDINFO_XML ); + logDebug( context, "Checking if build is already downloaded: " + buildInfoPath ); + + if ( Files.exists( buildInfoPath ) ) + { + logInfo( context, "Downloaded build found by checksum " + context.getInputInfo().getChecksum() ); + try + { + final BuildInfoType dto = xmlService.fromFile( BuildInfoType.class, buildInfoPath.toFile() ); + return new BuildInfo( dto, CacheSource.REMOTE ); + } + catch ( Exception e ) + { + logger.error( "Downloaded build info is not valid, deleting: " + buildInfoPath, e ); + Files.delete( buildInfoPath ); + } + } + + if ( !cacheConfig.isRemoteCacheEnabled() ) + { + return null; + } + + try + { + + Path lookupInfoPath = remoteBuildPath( context, LOOKUPINFO_XML ); + if ( Files.exists( lookupInfoPath ) ) + { + final BasicFileAttributes fileAttributes = Files.readAttributes( lookupInfoPath, + BasicFileAttributes.class ); + final long lastModified = fileAttributes.lastModifiedTime().toMillis(); + final long created = fileAttributes.creationTime().toMillis(); + final long now = System.currentTimeMillis(); + // throttle remote cache calls, maven like + if ( now < created + ONE_HOUR_MILLIS && now < lastModified + ONE_MINUTE_MILLIS ) + { // fresh file, allow lookup every minute + logInfo( context, "Skipping remote lookup, last unsuccessful lookup less than 1m ago." ); + return null; + } + else if ( now < created + ONE_DAY_MILLIS && now < lastModified + ONE_HOUR_MILLIS ) + { // less than 1 day file, allow 1 per hour lookup + logInfo( context, "Skipping remote lookup, last unsuccessful lookup less than 1h ago." ); + return null; + } + else if ( now > created + ONE_DAY_MILLIS && now < lastModified + ONE_DAY_MILLIS ) + { // more than 1 day file, allow 1 per day lookup + logInfo( context, "Skipping remote lookup, last unsuccessful lookup less than 1d ago." ); + return null; + } + } + + final BuildInfo buildInfo = remoteRepository.findBuild( context ); + if ( buildInfo != null ) + { + logInfo( context, "Build info downloaded from remote repo, saving to: " + buildInfoPath ); + Files.createDirectories( buildInfoPath.getParent() ); + Files.write( buildInfoPath, xmlService.toBytes( buildInfo.getDto() ), CREATE_NEW ); + } + else + { + FileUtils.touch( lookupInfoPath.toFile() ); + } + return buildInfo; + } + catch ( Exception e ) + { + logger.error( "Remote build info is not valid, cached data is not compatible", e ); + return null; + } + } + + @Override + public void clearCache( CacheContext context ) + { + try + { + final Path buildCacheDir = buildCacheDir( context ); + Path artifactCacheDir = buildCacheDir.getParent(); + + if ( !Files.exists( artifactCacheDir ) ) + { + return; + } + + List cacheDirs = new ArrayList<>(); + for ( Path dir : Files.newDirectoryStream( artifactCacheDir ) ) + { + if ( Files.isDirectory( dir ) ) + { + cacheDirs.add( dir ); + } + } + if ( cacheDirs.size() > cacheConfig.getMaxLocalBuildsCached() ) + { + Collections.sort( cacheDirs, LAST_MODIFIED_COMPARATOR ); + for ( Path dir : cacheDirs.subList( 0, cacheDirs.size() - cacheConfig.getMaxLocalBuildsCached() ) ) + { + FileUtils.deleteDirectory( dir.toFile() ); + } + } + final Path path = localBuildDir( context ); + if ( Files.exists( path ) ) + { + FileUtils.deleteDirectory( path.toFile() ); + } + } + catch ( IOException e ) + { + final String artifactId = context.getProject().getArtifactId(); + throw new RuntimeException( + "Failed to cleanup local cache of " + artifactId + " on build failure, it might be inconsistent", + e ); + } + } + + @Override + public Optional findBestMatchingBuild( MavenSession session, Dependency dependency ) + { + return bestBuildCache.getUnchecked( Pair.of( session, dependency ) ); + } + + + private Optional findBestMatchingBuildImpl( Pair dependencySession ) + throws IOException + { + final MavenSession session = dependencySession.getLeft(); + final Dependency dependency = dependencySession.getRight(); + + final Path artifactCacheDir = artifactCacheDir( session, dependency.getGroupId(), dependency.getArtifactId() ); + + final Multimap, Pair> filesByVersion = ArrayListMultimap.create(); + + Files.walkFileTree( artifactCacheDir, new SimpleFileVisitor() + { + @Override + public FileVisitResult visitFile( Path o, BasicFileAttributes basicFileAttributes ) + { + final File file = o.toFile(); + if ( file.getName().equals( BUILDINFO_XML ) ) + { + try + { + final BuildInfoType dto = xmlService.fromFile( BuildInfoType.class, file ); + final Pair buildInfoAndFile = Pair.of( new BuildInfo( dto, CacheSource.LOCAL ), + file ); + final String cachedVersion = dto.getArtifact().getVersion(); + final String cachedBranch = getScmRef( dto.getScm() ); + filesByVersion.put( Pair.of( cachedVersion, cachedBranch ), buildInfoAndFile ); + if ( isNotBlank( cachedBranch ) ) + { + filesByVersion.put( Pair.of( EMPTY, cachedBranch ), buildInfoAndFile ); + } + if ( isNotBlank( cachedVersion ) ) + { + filesByVersion.put( Pair.of( cachedVersion, EMPTY ), buildInfoAndFile ); + } + } + catch ( Exception e ) + { + // version is unusable nothing we can do here + logger.error( "Build info is not compatible to current maven implementation: " + file ); + } + } + return FileVisitResult.CONTINUE; + } + } ); + + if ( filesByVersion.isEmpty() ) + { + return Optional.absent(); + } + + final String currentRef = getScmRef( ProjectUtils.readGitInfo( session ) ); + // first lets try by branch and version + Collection> bestMatched = new LinkedList<>(); + if ( isNotBlank( currentRef ) ) + { + bestMatched = filesByVersion.get( Pair.of( dependency.getVersion(), currentRef ) ); + } + if ( Iterables.isEmpty( bestMatched ) ) + { + // then by version + bestMatched = filesByVersion.get( Pair.of( dependency.getVersion(), EMPTY ) ); + } + if ( Iterables.isEmpty( bestMatched ) && isNotBlank( currentRef ) ) + { + // then by branch + bestMatched = filesByVersion.get( Pair.of( EMPTY, currentRef ) ); + } + if ( Iterables.isEmpty( bestMatched ) ) + { + // ok lets take all + bestMatched = filesByVersion.values(); + } + + List> orderedFiles = Ordering.natural().onResultOf( + GET_LAST_MODIFIED ).reverse().sortedCopy( bestMatched ); + return Optional.of( orderedFiles.get( 0 ).getLeft() ); + } + + private String getScmRef( BuildInfoType.Scm scm ) + { + if ( scm != null ) + { + return scm.isSetSourceBranch() ? scm.getSourceBranch() : scm.getRevision(); + } + else + { + return EMPTY; + } + } + + @Override + public Path getArtifactFile( CacheContext context, CacheSource source, ArtifactType artifact ) throws IOException + { + if ( source == CacheSource.LOCAL ) + { + return localBuildPath( context, artifact.getFileName(), false ); + } + else + { + Path cachePath = remoteBuildPath( context, artifact.getFileName() ); + if ( !Files.exists( cachePath ) && cacheConfig.isRemoteCacheEnabled() ) + { + final byte[] artifactContent = remoteRepository.getArtifactContent( context, artifact ); + if ( artifactContent != null ) + { + Files.write( cachePath, artifactContent, CREATE_NEW ); + } + } + return cachePath; + } + } + + @Override + public void beforeSave( CacheContext environment ) + { + clearCache( environment ); + } + + @Override + public void saveBuildInfo( CacheResult cacheResult, BuildInfo buildInfo ) throws IOException + { + final Path path = localBuildPath( cacheResult.getContext(), BUILDINFO_XML, true ); + Files.write( path, xmlService.toBytes( buildInfo.getDto() ), TRUNCATE_EXISTING, CREATE ); + if ( cacheConfig.isRemoteCacheEnabled() && cacheConfig.isSaveToRemote() && !cacheResult.isFinal() ) + { + remoteRepository.saveBuildInfo( cacheResult, buildInfo ); + } + } + + @Override + public void saveCacheReport( String buildId, MavenSession session, CacheReportType cacheReport ) throws IOException + { + Path path = Paths.get( getMultimoduleRoot( session ), "target", "maven-incremental" ); + Files.createDirectories( path ); + Files.write( path.resolve( "cache-report." + buildId + ".xml" ), xmlService.toBytes( cacheReport ), + TRUNCATE_EXISTING, CREATE ); + if ( cacheConfig.isRemoteCacheEnabled() && cacheConfig.isSaveToRemote() ) + { + logger.info( "[CACHE] Saving cache report on build completion" ); + remoteRepository.saveCacheReport( buildId, session, cacheReport ); + } + } + + @Override + public void saveArtifactFile( CacheResult cacheResult, Artifact artifact ) throws IOException + { + // safe artifacts to cache + File artifactFile = artifact.getFile(); + Path cachePath = localBuildPath( cacheResult.getContext(), ProjectUtils.normalizedName( artifact ), true ); + Files.copy( artifactFile.toPath(), cachePath, StandardCopyOption.REPLACE_EXISTING ); + if ( cacheConfig.isRemoteCacheEnabled() && cacheConfig.isSaveToRemote() && !cacheResult.isFinal() ) + { + remoteRepository.saveArtifactFile( cacheResult, artifact ); + } + } + + private Path buildCacheDir( CacheContext context ) throws IOException + { + final MavenProject project = context.getProject(); + final Path artifactCacheDir = artifactCacheDir( context.getSession(), project.getGroupId(), + project.getArtifactId() ); + return artifactCacheDir.resolve( context.getInputInfo().getChecksum() ); + } + + private Path artifactCacheDir( MavenSession session, String groupId, String artifactId ) throws IOException + { + final String localRepositoryRoot = session.getLocalRepository().getBasedir(); + final Path path = Paths.get( localRepositoryRoot, "..", "cache", CACHE_IMPLMENTATION_VERSION, groupId, + artifactId ).normalize(); + if ( !Files.exists( path ) ) + { + Files.createDirectories( path ); + } + return path; + } + + private Path remoteBuildPath( CacheContext context, String filename ) throws IOException + { + return buildCacheDir( context ).resolve( filename ); + } + + private Path localBuildPath( CacheContext context, String filename, boolean createDir ) throws IOException + { + final Path localBuildDir = localBuildDir( context ); + if ( createDir ) + { + Files.createDirectories( localBuildDir ); + } + return localBuildDir.resolve( filename ); + } + + private Path localBuildDir( CacheContext context ) throws IOException + { + return buildCacheDir( context ).resolve( "local" ); + } + + private void logDebug( CacheContext context, String message ) + { + logger.debug( "[CACHE][" + context.getProject().getArtifactId() + "] " + message ); + } + + private void logInfo( CacheContext context, String message ) + { + logger.info( "[CACHE][" + context.getProject().getArtifactId() + "] " + message ); + } + + private static class LastModifiedComparator implements Comparator + { + @Override + public int compare( Path p1, Path p2 ) + { + try + { + return Files.getLastModifiedTime( p1 ).compareTo( Files.getLastModifiedTime( p2 ) ); + } + catch ( IOException e ) + { + return 0; + } + } + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java b/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java new file mode 100644 index 000000000000..9c07e5815e69 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java @@ -0,0 +1,178 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.caching.jaxb.CompletedExecutionType; +import org.apache.maven.caching.jaxb.TrackedPropertyType; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.DtoUtils; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.Mojo; +import org.apache.maven.plugin.MojoCheker; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.util.ReflectionUtils; + +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.apache.maven.caching.ProjectUtils.mojoExecutionKey; + +/** + * MojoExecutionManager + */ +public class MojoExecutionManager implements MojoCheker +{ + + private final long createdTimestamp; + private final Logger logger; + private final MavenProject project; + private final BuildInfo buildInfo; + private final AtomicBoolean consistent; + private final CacheController cacheController; + private final CacheConfig cacheConfig; + + public MojoExecutionManager( MavenProject project, + CacheController cacheController, + BuildInfo buildInfo, + AtomicBoolean consistent, + Logger logger, CacheConfig cacheConfig ) + { + this.createdTimestamp = System.currentTimeMillis(); + this.project = project; + this.cacheController = cacheController; + this.buildInfo = buildInfo; + this.consistent = consistent; + this.logger = logger; + this.cacheConfig = cacheConfig; + } + + /** + * runtime check is rather expensive for cached build and better to be avoided when possible + */ + @Override + public boolean needCheck( MojoExecution mojoExecution, MavenSession session ) + { + return !cacheConfig.getTrackedProperties( mojoExecution ).isEmpty(); + } + + /** + * this implementation has side effect of consistency check to force local save if local run is different than + * cached + * + * @return false always returns false to prevent mojo execution + */ + @Override + public boolean check( MojoExecution execution, Mojo mojo, MavenSession session ) + { + + final CompletedExecutionType completedExecution = buildInfo.findMojoExecutionInfo( execution ); + final String fullGoalName = execution.getMojoDescriptor().getFullGoalName(); + + if ( completedExecution != null && !isParamsMatched( project, execution, mojo, completedExecution ) ) + { + logInfo( project, + "Mojo cached parameters mismatch with actual, forcing full project build. Mojo: " + fullGoalName ); + consistent.set( false ); + } + + if ( consistent.get() ) + { + long elapsed = System.currentTimeMillis() - createdTimestamp; + logInfo( project, "Skipping plugin execution (reconciled in " + elapsed + " millis): " + fullGoalName ); + } + + if ( logger.isDebugEnabled() ) + { + logger.debug( + "[CACHE][" + project.getArtifactId() + "] Checked " + fullGoalName + ", resolved mojo: " + mojo + + ", cached params:" + completedExecution ); + } + return false; + } + + private boolean isParamsMatched( MavenProject project, + MojoExecution mojoExecution, + Mojo mojo, + CompletedExecutionType completedExecution ) + { + + List tracked = cacheConfig.getTrackedProperties( mojoExecution ); + + for ( TrackedPropertyType trackedProperty : tracked ) + { + final String propertyName = trackedProperty.getPropertyName(); + + String expectedValue = DtoUtils.findPropertyValue( propertyName, completedExecution ); + if ( expectedValue == null && trackedProperty.isSetDefaultValue() ) + { + expectedValue = trackedProperty.getDefaultValue(); + } + + final String currentValue; + try + { + currentValue = String.valueOf( ReflectionUtils.getValueIncludingSuperclasses( propertyName, mojo ) ); + } + catch ( IllegalAccessException e ) + { + logError( project, "Cannot extract plugin property " + propertyName + " from mojo " + mojo, e ); + return false; + } + + if ( !StringUtils.equals( currentValue, expectedValue ) ) + { + if ( !StringUtils.equals( currentValue, trackedProperty.getSkipValue() ) ) + { + logInfo( project, + "Plugin parameter mismatch found. Parameter: " + propertyName + ", expected: " + + expectedValue + ", actual: " + currentValue ); + return false; + } + else + { + logWarn( project, + "Cache contains plugin execution with skip flag and might be incomplete. Property: " + + propertyName + ", execution: " + mojoExecutionKey( mojoExecution ) ); + } + } + } + return true; + } + + private void logInfo( MavenProject project, String message ) + { + logger.info( "[CACHE][" + project.getArtifactId() + "] " + message ); + } + + private void logError( MavenProject project, String message, Exception e ) + { + logger.error( "[CACHE][" + project.getArtifactId() + "] " + message, e ); + } + + private void logWarn( MavenProject project, String message ) + { + logger.warn( "[CACHE][" + project.getArtifactId() + "] " + message ); + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/MojoParametersListener.java b/maven-core/src/main/java/org/apache/maven/caching/MojoParametersListener.java new file mode 100644 index 000000000000..8750a8dcca67 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/MojoParametersListener.java @@ -0,0 +1,102 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.execution.MojoExecutionEvent; +import org.apache.maven.execution.MojoExecutionListener; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.logging.Logger; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +/** + * MojoParametersListener + */ +@Component( role = MojoExecutionListener.class, + hint = "MojoParametersListener" ) +public class MojoParametersListener implements MojoExecutionListener +{ + + private final ConcurrentMap> projectExecutions = + new ConcurrentHashMap<>(); + + @Requirement + private Logger logger; + + @Override + public void beforeMojoExecution( MojoExecutionEvent event ) + { + final String executionKey = ProjectUtils.mojoExecutionKey( event.getExecution() ); + logDebug( event.getProject(), + "Starting mojo execution: " + executionKey + ", class: " + event.getMojo().getClass() ); + final MavenProject project = event.getProject(); + Map projectEvents = projectExecutions.get( project ); + if ( projectEvents == null ) + { + Map candidate = new ConcurrentHashMap<>(); + projectEvents = projectExecutions.putIfAbsent( project, candidate ); + if ( projectEvents == null ) + { + projectEvents = candidate; + } + } + projectEvents.put( executionKey, event ); + } + + @Override + public void afterMojoExecutionSuccess( MojoExecutionEvent event ) throws MojoExecutionException + { + // do nothing + } + + @Override + public void afterExecutionFailure( MojoExecutionEvent event ) + { + //do nothing + } + + public Map getProjectExecutions( MavenProject project ) + { + return projectExecutions.get( project ); + } + + public void remove( MavenProject project ) + { + projectExecutions.remove( project ); + } + + private void logDebug( MavenProject project, String message ) + { + if ( logger.isDebugEnabled() ) + { + logger.debug( "[CACHE][" + project.getArtifactId() + "] " + message ); + } + } + + // private void logInfo(String message) { + // logger.info("[CACHE][" + project.getArtifactId() + "] " + message); + // } + +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java new file mode 100644 index 000000000000..93bcccba0b1c --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java @@ -0,0 +1,41 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.caching.jaxb.DirScanConfigType; + +import javax.annotation.Nonnull; + +/** + * PluginScanConfig + */ +public interface PluginScanConfig +{ + boolean isSkip(); + + boolean accept( String propertyName ); + + PluginScanConfig mergeWith( PluginScanConfig overrideSource ); + + @Nonnull + ScanConfigProperties getTagScanProperties( String tagName ); + + DirScanConfigType dto(); +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java new file mode 100644 index 000000000000..87791905100d --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java @@ -0,0 +1,161 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.caching.jaxb.DirScanConfigType; +import org.apache.maven.caching.jaxb.TagNameType; +import org.apache.maven.caching.jaxb.TagScanConfigType; + +import javax.annotation.Nonnull; +import java.util.List; + +/** + * PluginScanConfigImpl + */ +public class PluginScanConfigImpl implements PluginScanConfig +{ + + private final DirScanConfigType dto; + + public PluginScanConfigImpl( DirScanConfigType scanConfig ) + { + this.dto = scanConfig; + } + + @Override + public boolean isSkip() + { + return StringUtils.equals( dto.getMode(), "skip" ); + } + + @Override + public boolean accept( String tagName ) + { + // include or exclude is a choice element, could be only obe property set + + //noinspection ConstantConditions + final List includes = dto.getInclude(); + if ( !includes.isEmpty() ) + { + return findTagScanProperties( tagName ) != null; + } + + return !contains( dto.getExclude(), tagName ); + } + + private boolean contains( List excludes, String tagName ) + { + for ( TagNameType exclude : excludes ) + { + if ( StringUtils.equals( exclude.getTagName(), tagName ) ) + { + return true; + } + } + return false; + } + + @Nonnull + @Override + public PluginScanConfig mergeWith( final PluginScanConfig overrideConfig ) + { + + if ( dto == null ) + { + return overrideConfig; + } + + final DirScanConfigType override = overrideConfig.dto(); + if ( override == null ) + { + return this; + } + + if ( override.isIgnoreParent() ) + { + return overrideConfig; + } + + DirScanConfigType merged = new DirScanConfigType(); + if ( override.isSetMode() ) + { + merged.setMode( override.getMode() ); + } + else + { + merged.setMode( dto.getMode() ); + } + + merged.getExclude().addAll( dto.getExclude() ); + merged.getExclude().addAll( override.getExclude() ); + + merged.getInclude().addAll( dto.getInclude() ); + merged.getInclude().addAll( override.getInclude() ); + + return new PluginScanConfigImpl( merged ); + } + + @Nonnull + public ScanConfigProperties getTagScanProperties( String tagName ) + { + ScanConfigProperties scanProperties = findTagScanProperties( tagName ); + return scanProperties != null ? scanProperties : defaultScanConfig(); + } + + @Override + public DirScanConfigType dto() + { + return dto; + } + + private ScanConfigProperties findTagScanProperties( String tagName ) + { + ScanConfigProperties scanConfigProperties = findConfigByName( tagName, dto.getInclude() ); + if ( scanConfigProperties == null ) + { + scanConfigProperties = findConfigByName( tagName, dto.getTagScanConfig() ); + } + return scanConfigProperties; + } + + private ScanConfigProperties findConfigByName( String tagName, List configs ) + { + + if ( configs == null ) + { + return null; + } + + for ( TagScanConfigType config : configs ) + { + if ( StringUtils.equals( tagName, config.getTagName() ) ) + { + return new ScanConfigProperties( config.isRecursive(), config.getGlob() ); + } + } + return null; + } + + private static ScanConfigProperties defaultScanConfig() + { + return new ScanConfigProperties( true, null ); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java b/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java new file mode 100644 index 000000000000..176556850377 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java @@ -0,0 +1,197 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.caching.jaxb.BuildInfoType; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.internal.ProjectIndex; +import org.apache.maven.lifecycle.internal.builder.BuilderCommon; +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.project.MavenProject; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +import static com.google.common.base.Preconditions.checkArgument; +import static org.apache.commons.lang3.StringUtils.removeStart; +import static org.apache.commons.lang3.StringUtils.trim; +import static org.apache.maven.artifact.Artifact.LATEST_VERSION; +import static org.apache.maven.artifact.Artifact.SNAPSHOT_VERSION; + +/** + * ProjectUtils + */ +public class ProjectUtils +{ + + private static final List PHASES = Lists.newArrayList( + //clean + "pre-clean", "clean", "post-clean", + // default + "validate", "initialize", "generate-sources", "process-sources", "generate-resources", "process-resources", + "compile", "process-classes", "generate-test-sources", "process-test-sources", "generate-test-resources", + "process-test-resources", "test-compile", "process-test-classes", "test", "prepare-package", "package", + "pre-integration-test", "integration-test", "post-integration-test", "verify", "install", "deploy", + //site + "pre-site", "site", "post-site", "site-deploy" ); + + /** + * @param phase + * @param other + * @return true if the given phase is later than the other in maven lifecycle. Example: isLaterPhase("install", + * "clean") returns true; + */ + public static boolean isLaterPhase( String phase, String other ) + { + checkArgument( PHASES.contains( phase ), "Unsupported phase: " + phase ); + checkArgument( PHASES.contains( other ), "Unsupported phase: " + other ); + + return PHASES.indexOf( phase ) > PHASES.indexOf( other ); + } + + public static boolean isBuilding( Dependency dependency, ProjectIndex projectIndex ) + { + final MavenProject key = new MavenProject(); + key.setGroupId( dependency.getGroupId() ); + key.setArtifactId( dependency.getArtifactId() ); + key.setVersion( dependency.getVersion() ); + return projectIndex.getProjects().containsKey( BuilderCommon.getKey( key ) ); + } + + public static boolean isPomPackaging( MavenProject project ) + { + return project.getPackaging().equals( "pom" ) && !new File( getSrcDir( project ) ).exists(); + } + + public static boolean isPom( Artifact artifact ) + { + return artifact.getType().equals( "pom" ); + } + + public static boolean isPom( Dependency dependency ) + { + return dependency.getType().equals( "pom" ); + } + + public static boolean isSnapshot( String version ) + { + return version.endsWith( SNAPSHOT_VERSION ) || version.endsWith( LATEST_VERSION ); + } + + public static String getTargetDir( MavenProject project ) + { + return FilenameUtils.concat( project.getBasedir().getAbsolutePath(), "target" ); + } + + public static String getSrcDir( MavenProject project ) + { + return FilenameUtils.concat( project.getBasedir().getAbsolutePath(), "src" ); + } + + public static String normalizedName( Artifact artifact ) + { + + if ( artifact.getFile() == null ) + { + return null; + } + + StringBuilder filename = new StringBuilder( artifact.getArtifactId() ); + + if ( artifact.hasClassifier() ) + { + filename.append( "-" ).append( artifact.getClassifier() ); + } + + final ArtifactHandler artifactHandler = artifact.getArtifactHandler(); + if ( artifactHandler != null && StringUtils.isNotBlank( artifactHandler.getExtension() ) ) + { + filename.append( "." ).append( artifactHandler.getExtension() ); + } + return filename.toString(); + } + + public static String mojoExecutionKey( MojoExecution mojo ) + { + return StringUtils.join( Lists.newArrayList( StringUtils.defaultIfEmpty( mojo.getExecutionId(), "emptyExecId" ), + StringUtils.defaultIfEmpty( mojo.getGoal(), "emptyGoal" ), + StringUtils.defaultIfEmpty( mojo.getLifecyclePhase(), "emptyLifecyclePhase" ), + StringUtils.defaultIfEmpty( mojo.getArtifactId(), "emptyArtifactId" ), + StringUtils.defaultIfEmpty( mojo.getGroupId(), "emptyGroupId" ), + StringUtils.defaultIfEmpty( mojo.getVersion(), "emptyVersion" ) ), ":" ); + } + + public static String getMultimoduleRoot( MavenSession session ) + { + return System.getProperty( "maven.multiModuleProjectDirectory", session.getExecutionRootDirectory() ); + } + + public static BuildInfoType.Scm readGitInfo( MavenSession session ) throws IOException + { + final BuildInfoType.Scm scmCandidate = new BuildInfoType.Scm(); + final Path gitDir = Paths.get( getMultimoduleRoot( session ), ".git" ); + if ( Files.isDirectory( gitDir ) ) + { + final Path headFile = gitDir.resolve( "HEAD" ); + if ( Files.exists( headFile ) ) + { + String headRef = readFirstLine( headFile, "" ); + if ( headRef.startsWith( "ref: " ) ) + { + String branch = trim( removeStart( headRef, "ref: " ) ); + scmCandidate.setSourceBranch( branch ); + final Path refPath = gitDir.resolve( branch ); + if ( Files.exists( refPath ) ) + { + String revision = readFirstLine( refPath, "" ); + scmCandidate.setRevision( trim( revision ) ); + } + } + else + { + scmCandidate.setSourceBranch( headRef ); + scmCandidate.setRevision( headRef ); + } + } + } + return scmCandidate; + } + + + private static String readFirstLine( Path path, String defaultValue ) throws IOException + { + final List lines = Files.readAllLines( path, StandardCharsets.UTF_8 ); + return Iterables.getFirst( lines, defaultValue ); + } + + +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java b/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java new file mode 100644 index 000000000000..7c118c405739 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java @@ -0,0 +1,42 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.google.common.base.Optional; +import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.project.MavenProject; + +import java.io.IOException; + +/** + * RemoteArtifactsRepository + */ +public interface RemoteArtifactsRepository extends ArtifactsRepository +{ + + byte[] getArtifactContent( CacheContext context, ArtifactType artifact ) throws IOException; + + byte[] getResourceContent( String resourceUrl, String logReference ); + + String getResourceUrl( CacheContext context, String filename ); + + Optional findBaselineBuild( MavenProject project ); +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/RestoreStatus.java b/maven-core/src/main/java/org/apache/maven/caching/RestoreStatus.java new file mode 100644 index 000000000000..6bf8fefc2832 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/RestoreStatus.java @@ -0,0 +1,31 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * RestoreStatus + */ +public enum RestoreStatus +{ + EMPTY, + FAILURE, + PARTIAL, + SUCCESS +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/ScanConfigProperties.java b/maven-core/src/main/java/org/apache/maven/caching/ScanConfigProperties.java new file mode 100644 index 000000000000..bc9622a59fa8 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/ScanConfigProperties.java @@ -0,0 +1,45 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * ScanConfigProperties + */ +public class ScanConfigProperties +{ + private final boolean recursive; + private final String glob; + + public ScanConfigProperties( boolean recursive, String glob ) + { + this.recursive = recursive; + this.glob = glob; + } + + public boolean isRecursive() + { + return recursive; + } + + public String getGlob() + { + return glob; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/ZipUtils.java b/maven-core/src/main/java/org/apache/maven/caching/ZipUtils.java new file mode 100644 index 000000000000..9f15bb1d2460 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/ZipUtils.java @@ -0,0 +1,116 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.commons.io.IOUtils; + +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +/** + * ZipUtils + */ +public class ZipUtils +{ + + private static final int BUFFER_SIZE = 4096; + + public static InputStream zipFolder( final Path dir ) throws IOException + { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try ( ZipOutputStream zipOutputStream = new ZipOutputStream( out ) ) + { + processFolder( dir, zipOutputStream ); + } + return new ByteArrayInputStream( out.toByteArray() ); + } + + private static void processFolder( final Path dir, final ZipOutputStream zipOutputStream ) throws IOException + { + Files.walkFileTree( dir, new SimpleFileVisitor() + { + @Override + public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttributes ) throws IOException + { + final ZipEntry zipEntry = new ZipEntry( dir.relativize( path ).toString() ); + zipOutputStream.putNextEntry( zipEntry ); + try ( InputStream inputStream = Files.newInputStream( path ) ) + { + IOUtils.copy( inputStream, zipOutputStream ); + } + zipOutputStream.closeEntry(); + return FileVisitResult.CONTINUE; + } + } ); + } + + public static void unzip( InputStream is, Path out ) throws IOException + { + try ( ZipInputStream zis = new ZipInputStream( is ) ) + { + + ZipEntry entry = zis.getNextEntry(); + + while ( entry != null ) + { + File file = new File( out.toFile(), entry.getName() ); + file.setLastModified( entry.getTime() ); + + if ( entry.isDirectory() ) + { + file.mkdirs(); + } + else + { + File parent = file.getParentFile(); + + if ( !parent.exists() ) + { + parent.mkdirs(); + } + + try ( BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream( file ) ) ) + { + byte[] buffer = new byte[BUFFER_SIZE]; + int location; + while ( ( location = zis.read( buffer ) ) != -1 ) + { + bos.write( buffer, 0, location ); + } + } + } + entry = zis.getNextEntry(); + } + } + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java new file mode 100644 index 000000000000..bcc017b8caab --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java @@ -0,0 +1,31 @@ +package org.apache.maven.caching.checksum; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * DependencyNotResolvedException + */ +public class DependencyNotResolvedException extends RuntimeException +{ + public DependencyNotResolvedException( String message ) + { + super( message ); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java new file mode 100644 index 000000000000..e837da1f8587 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java @@ -0,0 +1,189 @@ +package org.apache.maven.caching.checksum; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.caching.hash.HashChecksum; +import org.apache.maven.caching.jaxb.DigestItemType; +import org.mozilla.universalchardet.UniversalDetector; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.commons.lang3.StringUtils.containsAny; +import static org.apache.commons.lang3.StringUtils.equalsAny; +import static org.apache.commons.lang3.StringUtils.startsWith; +import static org.apache.commons.lang3.StringUtils.startsWithAny; + +/** + * DigestUtils + */ +public class DigestUtils +{ + + private static final ThreadLocal ENCODING_DETECTOR = new ThreadLocal() + { + @Override + protected UniversalDetector initialValue() + { + return new UniversalDetector( null ); + } + }; + + + public static DigestItemType pom( HashChecksum checksum, String effectivePom ) + { + return item( "pom", effectivePom, checksum.update( effectivePom.getBytes( UTF_8 ) ) ); + } + + public static DigestItemType file( HashChecksum checksum, Path basedir, Path file ) throws IOException + { + byte[] content = Files.readAllBytes( file ); + DigestItemType item = item( "file", normalize( basedir, file ), checksum.update( content ) ); + try + { + populateContentDetails( file, content, item ); + } + catch ( IOException ignore ) + { + System.out.println( "hello" ); + } + return item; + } + + private static void populateContentDetails( Path file, byte[] content, DigestItemType item ) throws IOException + { + String contentType = Files.probeContentType( file ); + if ( contentType != null ) + { + item.setContent( contentType ); + } + final boolean binary = isBinary( contentType ); + item.setIsText( isText( contentType ) ? "yes" : binary ? "no" : "unknown" ); + if ( !binary ) + { // probing application/ files as well though might be binary + UniversalDetector detector = ENCODING_DETECTOR.get(); + detector.reset(); + detector.handleData( content, 0, Math.min( content.length, 16 * 1024 ) ); + detector.dataEnd(); + String detectedCharset = detector.getDetectedCharset(); + Charset charset = UTF_8; + if ( detectedCharset != null ) + { + item.setCharset( detectedCharset ); + charset = Charset.forName( detectedCharset ); + } + CharBuffer charBuffer = charset.decode( ByteBuffer.wrap( content ) ); + String lineSeparator = detectLineSeparator( charBuffer ); + item.setEol( StringUtils.defaultString( lineSeparator, "unknown" ) ); + } + } + + // TODO add support for .gitattributes to statically configure file type before falling back to probe based content checks + private static boolean isText( String contentType ) + { + return startsWith( contentType, "text/" ) + || containsAny( contentType, "+json", "+xml" ) // common mime type suffixes + || equalsAny( contentType, // some common text types + "application/json", + "application/rtf", + "application/x-sh", + "application/xml", + "application/javascript", + "application/sql" + ); + } + + private static boolean isBinary( String contentType ) + { + return startsWithAny( contentType, "image/", "audio/", "video/", "font/" ) + || containsAny( contentType, "+zip", "+gzip" ) + || equalsAny( contentType, + "application/octet-stream", + "application/java-archive", + "application/x-bzip", + "application/x-bzip2", + "application/zip", + "application/gzip", + "application/x-tar", + "application/msword", + "application/vnd.ms-excel", + "application/vnd.ms-powerpoint", + "application/pdf" + ); + } + + public static DigestItemType dependency( HashChecksum checksum, String key, String hash ) + { + return item( "dependency", key, checksum.update( hash ) ); + } + + private static String normalize( Path basedirPath, Path file ) + { + return FilenameUtils.separatorsToUnix( relativize( basedirPath, file ).toString() ); + } + + private static Path relativize( Path basedirPath, Path file ) + { + try + { + return basedirPath.relativize( file ); + } + catch ( Exception ignore ) + { + return file; + } + } + + private static DigestItemType item( String type, String reference, String hash ) + { + final DigestItemType item = new DigestItemType(); + item.setType( type ); + item.setValue( reference ); + item.setHash( hash ); + return item; + } + + private DigestUtils() + { + } + + public static String detectLineSeparator( CharSequence text ) + { + // first line break only + int index = StringUtils.indexOfAny( text, "\n\r" ); + if ( index == -1 || index >= text.length() ) + { + return null; + } + char ch = text.charAt( index ); + if ( ch == '\r' ) + { + return index + 1 < text.length() && text.charAt( index + 1 ) == '\n' ? "CRLF" : "CR"; + } + return ch == '\n' ? "LF" : null; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java new file mode 100644 index 000000000000..04d9207cb0dc --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java @@ -0,0 +1,64 @@ +package org.apache.maven.caching.checksum; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.model.Dependency; +import org.apache.maven.project.MavenProject; + +/** + * KeyUtils + */ +public class KeyUtils +{ + + private static final String SEPARATOR = ":"; + + public static String getProjectKey( MavenProject project ) + { + return StringUtils.joinWith( SEPARATOR, project.getGroupId(), project.getArtifactId(), project.getVersion() ); + } + + public static String getVersionlessProjectKey( MavenProject project ) + { + return StringUtils.joinWith( SEPARATOR, project.getGroupId(), project.getArtifactId() ); + } + + public static String getVersionlessDependencyKey( Dependency dependency ) + { + return StringUtils.joinWith( SEPARATOR, dependency.getGroupId(), dependency.getArtifactId() ); + } + + public static String getArtifactKey( ArtifactType artifact ) + { + return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + + ( artifact.getClassifier() != null ? ":" + artifact.getClassifier() : "" ) + + ":" + artifact.getVersion(); + } + + public static String getArtifactKey( Artifact artifact ) + { + return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + + ( artifact.getClassifier() != null ? ":" + artifact.getClassifier() : "" ) + + ":" + artifact.getVersion(); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java new file mode 100644 index 000000000000..8e5873ce7dcd --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -0,0 +1,950 @@ +package org.apache.maven.caching.checksum; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.caching.Clock; +import org.apache.maven.caching.LocalArtifactsRepository; +import org.apache.maven.caching.PluginScanConfig; +import org.apache.maven.caching.ProjectUtils; +import org.apache.maven.caching.RemoteArtifactsRepository; +import org.apache.maven.caching.ScanConfigProperties; +import org.apache.maven.caching.hash.HashAlgorithm; +import org.apache.maven.caching.hash.HashChecksum; +import org.apache.maven.caching.hash.HashFactory; +import org.apache.maven.caching.jaxb.DigestItemType; +import org.apache.maven.caching.jaxb.ProjectsInputInfoType; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.DtoUtils; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.internal.ProjectIndex; +import org.apache.maven.model.Build; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.model.PluginManagement; +import org.apache.maven.model.Resource; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.project.MavenProject; +import org.apache.maven.repository.RepositorySystem; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.WriterFactory; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +import javax.annotation.Nonnull; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.nio.file.DirectoryStream; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.concurrent.ConcurrentMap; + +import static org.apache.commons.lang3.StringUtils.contains; +import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; +import static org.apache.commons.lang3.StringUtils.equalsAnyIgnoreCase; +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.replaceEachRepeatedly; +import static org.apache.commons.lang3.StringUtils.startsWithAny; +import static org.apache.commons.lang3.StringUtils.stripToEmpty; +import static org.apache.maven.caching.ProjectUtils.isBuilding; +import static org.apache.maven.caching.ProjectUtils.isSnapshot; +import static org.apache.maven.caching.jaxb.PathSetType.Include; + +/** + * MavenProjectInput + */ +public class MavenProjectInput +{ + + /** + * Version ov hashing algorithm implementation. It is recommended to change to simplify remote cache maintenance + */ + public static final String CACHE_IMPLMENTATION_VERSION = "v10"; + + /** + * property name to pass glob value. The glob to be used to list directory files in plugins scanning + */ + private static final String CACHE_INPUT_GLOB_NAME = "remote.cache.input.glob"; + /** + * default glob, bbsdk/abfx specific + */ + public static final String DEFAULT_GLOB = "{*.java,*.groovy,*.yaml,*.svcd,*.proto,*assembly.xml,assembly" + + "*.xml,*logback.xml,*.vm,*.ini,*.jks,*.properties,*.sh,*.bat}"; + /** + * property name prefix to pass input files with project properties. smth like remote.cache.input.1 will be + * accepted + */ + private static final String CACHE_INPUT_NAME = "remote.cache.input"; + /** + * property name prefix to exclude files from input. smth like remote.cache.exclude.1 should be set in project + * props + */ + private static final String CACHE_EXCLUDE_NAME = "remote.cache.exclude"; + /** + * Flag to control if we should check values from plugin configs as file system objects + */ + private static final String CACHE_PROCESS_PLUGINS = "remote.cache.processPlugins"; + private final Logger logger; + private final MavenProject project; + private final MavenSession session; + private final LocalArtifactsRepository localCache; + private final RemoteArtifactsRepository remoteCache; + private final RepositorySystem repoSystem; + private final ArtifactHandlerManager artifactHandlerManager; + private final CacheConfig config; + private final ConcurrentMap projectArtifactsByKey; + private final PathIgnoringCaseComparator fileComparator; + private final DependencyComparator dependencyComparator; + private final List filteredOutPaths; + private final Path baseDirPath; + private final String dirGlob; + private final boolean processPlugins; + private final ProjectIndex projectIndex; + + @SuppressWarnings( "checkstyle:parameternumber" ) + public MavenProjectInput( MavenProject project, + MavenSession session, + CacheConfig config, + ProjectIndex projectIndex, + ConcurrentMap artifactsByKey, + RepositorySystem repoSystem, + ArtifactHandlerManager artifactHandlerManager, + Logger logger, + LocalArtifactsRepository localCache, + RemoteArtifactsRepository remoteCache ) + { + this.project = project; + this.session = session; + this.config = config; + this.projectIndex = projectIndex; + this.projectArtifactsByKey = artifactsByKey; + this.baseDirPath = project.getBasedir().toPath().toAbsolutePath(); + this.repoSystem = repoSystem; + this.artifactHandlerManager = artifactHandlerManager; + this.logger = logger; + this.localCache = localCache; + this.remoteCache = remoteCache; + Properties properties = project.getProperties(); + this.dirGlob = properties.getProperty( CACHE_INPUT_GLOB_NAME, config.getDefaultGlob() ); + this.processPlugins = Boolean.parseBoolean( + properties.getProperty( CACHE_PROCESS_PLUGINS, config.isProcessPlugins() ) ); + + Build build = project.getBuild(); + filteredOutPaths = new ArrayList<>( Arrays.asList( normalizedPath( build.getDirectory() ), // target by default + normalizedPath( build.getOutputDirectory() ), normalizedPath( build.getTestOutputDirectory() ) ) ); + + for ( String excludePath : config.getGlobalExcludePaths() ) + { + filteredOutPaths.add( Paths.get( excludePath ) ); + } + + for ( String propertyName : properties.stringPropertyNames() ) + { + if ( propertyName.startsWith( CACHE_EXCLUDE_NAME ) ) + { + filteredOutPaths.add( Paths.get( properties.getProperty( propertyName ) ) ); + } + } + + this.fileComparator = new PathIgnoringCaseComparator(); + this.dependencyComparator = new DependencyComparator(); + } + + public ProjectsInputInfoType calculateChecksum( HashFactory hashFactory ) throws IOException + { + long time = Clock.time(); + + final String effectivePom = getEffectivePom( project.getOriginalEffectiveModel() ); + final SortedSet inputFiles = getInputFiles(); + final SortedMap dependenciesChecksum = getMutableDependencies(); + + final long inputTime = Clock.elapsed( time ); + time = Clock.time(); + + // hash items: effective pom + input files + dependencies + final int count = 1 + inputFiles.size() + dependenciesChecksum.size(); + final List items = new ArrayList<>( count ); + final HashChecksum checksum = hashFactory.createChecksum( count ); + + Optional baselineHolder = Optional.absent(); + if ( config.isBaselineDiffEnabled() ) + { + baselineHolder = + remoteCache.findBaselineBuild( project ).transform( b -> b.getDto().getProjectsInputInfo() ); + } + + DigestItemType effectivePomChecksum = DigestUtils.pom( checksum, effectivePom ); + items.add( effectivePomChecksum ); + final boolean compareWithBaseline = config.isBaselineDiffEnabled() && baselineHolder.isPresent(); + if ( compareWithBaseline ) + { + checkEffectivePomMatch( baselineHolder.get(), effectivePomChecksum ); + } + + boolean sourcesMatched = true; + for ( Path file : inputFiles ) + { + DigestItemType fileDigest = DigestUtils.file( checksum, baseDirPath, file ); + items.add( fileDigest ); + if ( compareWithBaseline ) + { + sourcesMatched &= checkItemMatchesBaseline( baselineHolder.get(), fileDigest ); + } + } + if ( compareWithBaseline ) + { + logInfo( "Source code: " + ( sourcesMatched ? "MATCHED" : "OUT OF DATE" ) ); + } + + boolean dependenciesMatched = true; + for ( Map.Entry entry : dependenciesChecksum.entrySet() ) + { + DigestItemType dependencyDigest = + DigestUtils.dependency( checksum, entry.getKey(), entry.getValue().getHash() ); + items.add( dependencyDigest ); + if ( compareWithBaseline ) + { + dependenciesMatched &= checkItemMatchesBaseline( baselineHolder.get(), dependencyDigest ); + } + } + + if ( compareWithBaseline ) + { + logInfo( "Dependencies: " + ( dependenciesMatched ? "MATCHED" : "OUT OF DATE" ) ); + } + + final ProjectsInputInfoType projectsInputInfoType = new ProjectsInputInfoType(); + projectsInputInfoType.setChecksum( checksum.digest() ); + projectsInputInfoType.getItem().addAll( items ); + + final long checksumTime = Clock.elapsed( time ); + + if ( logger.isDebugEnabled() ) + { + for ( DigestItemType item : projectsInputInfoType.getItem() ) + { + logger.debug( "Hash calculated, item: " + item.getType() + ", hash: " + item.getHash() ); + } + } + logInfo( + "Project inputs calculated in " + inputTime + " ms. " + hashFactory.getAlgorithm() + + " checksum [" + projectsInputInfoType.getChecksum() + "] calculated in " + + checksumTime + " ms." ); + return projectsInputInfoType; + } + + private void checkEffectivePomMatch( ProjectsInputInfoType baselineBuild, DigestItemType effectivePomChecksum ) + { + Optional pomHolder = Optional.absent(); + for ( DigestItemType it : baselineBuild.getItem() ) + { + if ( it.getType().equals( "pom" ) ) + { + pomHolder = Optional.of( it ); + break; + } + } + + if ( pomHolder.isPresent() ) + { + DigestItemType pomItem = pomHolder.get(); + final boolean matches = StringUtils.equals( pomItem.getHash(), effectivePomChecksum.getHash() ); + if ( !matches ) + { + logInfo( + "Mismatch in effective poms. Current: " + effectivePomChecksum.getHash() + ", remote: " + + pomItem.getHash() ); + } + logInfo( "Effective pom: " + ( matches ? "MATCHED" : "OUT OF DATE" ) ); + } + } + + private boolean checkItemMatchesBaseline( ProjectsInputInfoType baselineBuild, DigestItemType fileDigest ) + { + Optional baselineFileDigest = Optional.absent(); + for ( DigestItemType it : baselineBuild.getItem() ) + { + if ( it.getType().equals( fileDigest.getType() ) + && fileDigest.getValue().equals( it.getValue().trim() ) ) + { + baselineFileDigest = Optional.of( it ); + break; + } + } + + boolean matched = false; + if ( baselineFileDigest.isPresent() ) + { + String hash = baselineFileDigest.get().getHash(); + matched = StringUtils.equals( hash, fileDigest.getHash() ); + if ( !matched ) + { + logInfo( + "Mismatch in " + fileDigest.getType() + ": " + fileDigest.getValue() + ". Local hash: " + + fileDigest.getHash() + ", remote: " + hash ); + } + } + else + { + logInfo( + "Mismatch in " + fileDigest.getType() + ": " + fileDigest.getValue() + + ". Not found in remote cache" ); + } + return matched; + } + + /** + * @param prototype effective model fully resolved by maven build. Do not pass here just parsed Model. + */ + private String getEffectivePom( Model prototype ) throws IOException + { + // TODO validate status of the model - it should be in resolved state + Model toHash = new Model(); + + toHash.setGroupId( prototype.getGroupId() ); + toHash.setArtifactId( prototype.getArtifactId() ); + toHash.setVersion( prototype.getVersion() ); + toHash.setModules( prototype.getModules() ); + + Collections.sort( prototype.getDependencies(), dependencyComparator ); + toHash.setDependencies( prototype.getDependencies() ); + + PluginManagement pluginManagement = prototype.getBuild().getPluginManagement(); + pluginManagement.setPlugins( normalizePlugins( prototype.getBuild().getPluginManagement().getPlugins() ) ); + + List plugins = normalizePlugins( prototype.getBuild().getPlugins() ); + + Build build = new Build(); + build.setPluginManagement( pluginManagement ); + build.setPlugins( plugins ); + + toHash.setBuild( build ); + + ByteArrayOutputStream output = new ByteArrayOutputStream(); + + Writer writer = null; + try + { + writer = WriterFactory.newXmlWriter( output ); + new MavenXpp3Writer().write( writer, toHash ); + + //normalize env specifics + final String[] searchList = {baseDirPath.toString(), "\\", "windows", "linux"}; + final String[] replacementList = {"", "/", "os.classifier", "os.classifier"}; + + return replaceEachRepeatedly( output.toString(), searchList, replacementList ); + + } + finally + { + IOUtil.close( writer ); + } + } + + private SortedSet getInputFiles() + { + long start = System.currentTimeMillis(); + HashSet visitedDirs = new HashSet<>(); + ArrayList collectedFiles = new ArrayList<>(); + + Build build = project.getBuild(); + + final boolean recursive = true; + startWalk( Paths.get( build.getSourceDirectory() ), dirGlob, recursive, collectedFiles, visitedDirs ); + for ( Resource resource : build.getResources() ) + { + startWalk( Paths.get( resource.getDirectory() ), dirGlob, recursive, collectedFiles, visitedDirs ); + } + + startWalk( Paths.get( build.getTestSourceDirectory() ), dirGlob, recursive, collectedFiles, visitedDirs ); + for ( Resource testResource : build.getTestResources() ) + { + startWalk( Paths.get( testResource.getDirectory() ), dirGlob, recursive, collectedFiles, visitedDirs ); + } + + Properties properties = project.getProperties(); + for ( String name : properties.stringPropertyNames() ) + { + if ( name.startsWith( CACHE_INPUT_NAME ) ) + { + String path = properties.getProperty( name ); + startWalk( Paths.get( path ), dirGlob, recursive, collectedFiles, visitedDirs ); + } + } + + List includes = config.getGlobalIncludePaths(); + for ( Include include : includes ) + { + final String path = include.getValue(); + final String glob = defaultIfEmpty( include.getGlob(), dirGlob ); + startWalk( Paths.get( path ), glob, include.isRecursive(), collectedFiles, visitedDirs ); + } + + long walkKnownPathsFinished = System.currentTimeMillis() - start; + + String message = processPlugins ? "enabled, values will be checked for presence in file system" : "disabled, " + + "only tags with attribute " + CACHE_INPUT_NAME + "=\"true\" will be added"; + logInfo( "Scanning plugins configurations to find input files. Probing is " + message ); + + if ( processPlugins ) + { + collectFromPlugins( collectedFiles, visitedDirs ); + } + else + { + logInfo( "Skipping check plugins scan (probing is disabled by config)" ); + } + + long pluginsFinished = System.currentTimeMillis() - start - walkKnownPathsFinished; + + TreeSet sorted = new TreeSet<>( fileComparator ); + for ( Path collectedFile : collectedFiles ) + { + sorted.add( collectedFile.normalize().toAbsolutePath() ); + } + + logInfo( + "Found " + sorted.size() + " input files. Project dir processing: " + walkKnownPathsFinished + + ", plugins: " + pluginsFinished + " millis" ); + if ( logger.isDebugEnabled() ) + { + logDebug( "Src input: " + sorted ); + } + + return sorted; + } + + /** + * entry point for directory walk + */ + private void startWalk( Path candidate, + String glob, + boolean recursive, + List collectedFiles, + Set visitedDirs ) + { + + Path normalized = candidate.isAbsolute() ? candidate : baseDirPath.resolve( candidate ); + normalized = normalized.toAbsolutePath().normalize(); + WalkKey key = new WalkKey( normalized, glob, recursive ); + if ( visitedDirs.contains( key ) || !Files.exists( normalized ) ) + { + return; + } + + if ( Files.isDirectory( normalized ) ) + { + if ( baseDirPath.startsWith( normalized ) ) + { // requested to walk parent, can do only non recursive + key = new WalkKey( normalized, glob, false ); + } + try + { + walkDir( key, collectedFiles, visitedDirs ); + visitedDirs.add( key ); + } + catch ( IOException e ) + { + throw new RuntimeException( e ); + } + } + else + { + if ( !isFilteredOutSubpath( normalized ) ) + { + if ( logger.isDebugEnabled() ) + { + logDebug( "Adding: " + normalized ); + } + collectedFiles.add( normalized ); + } + } + } + + private Path normalizedPath( String directory ) + { + return Paths.get( directory ).normalize(); + } + + private void collectFromPlugins( List files, HashSet visitedDirs ) + { + + List plugins = project.getBuild().getPlugins(); + for ( Plugin plugin : plugins ) + { + + PluginScanConfig scanConfig = config.getPluginDirScanConfig( plugin ); + + if ( scanConfig.isSkip() ) + { + logDebug( "Skipping plugin config scan (skip by config): " + plugin.getArtifactId() ); + continue; + } + + Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); + logDebug( "Processing plugin config: " + plugin.getArtifactId() ); + if ( configuration != null ) + { + addInputsFromPluginConfigs( configuration.getChildren(), scanConfig, files, visitedDirs ); + } + + for ( PluginExecution exec : plugin.getExecutions() ) + { + + final PluginScanConfig executionScanConfig = config.getExecutionDirScanConfig( plugin, exec ); + PluginScanConfig mergedConfig = scanConfig.mergeWith( executionScanConfig ); + + if ( mergedConfig.isSkip() ) + { + logDebug( + "Skipping plugin execution config scan (skip by config): " + + plugin.getArtifactId() + ", execId: " + exec.getId() ); + continue; + } + + Xpp3Dom execConfiguration = (Xpp3Dom) exec.getConfiguration(); + logDebug( "Processing plugin: " + plugin.getArtifactId() + ", execution: " + exec.getId() ); + + if ( execConfiguration != null ) + { + addInputsFromPluginConfigs( execConfiguration.getChildren(), mergedConfig, files, visitedDirs ); + } + } + } + } + + private Path walkDir( final WalkKey key, + final List collectedFiles, + final Set visitedDirs ) throws IOException + { + return Files.walkFileTree( key.getPath(), new SimpleFileVisitor() + { + @Override + public FileVisitResult preVisitDirectory( Path path, + BasicFileAttributes basicFileAttributes ) throws IOException + { + WalkKey currentDirKey = new WalkKey( path.toAbsolutePath().normalize(), key.getGlob(), + key.isRecursive() ); + if ( isHidden( path ) ) + { + if ( logger.isDebugEnabled() ) + { + logDebug( "Skipping subtree (hidden): " + path ); + } + return FileVisitResult.SKIP_SUBTREE; + } + else if ( isFilteredOutSubpath( path ) ) + { + if ( logger.isDebugEnabled() ) + { + logDebug( "Skipping subtree (blacklisted): " + path ); + } + return FileVisitResult.SKIP_SUBTREE; + } + else if ( visitedDirs.contains( currentDirKey ) ) + { + if ( logger.isDebugEnabled() ) + { + logDebug( "Skipping subtree (visited): " + path ); + } + return FileVisitResult.SKIP_SUBTREE; + } + + walkDirectoryFiles( path, collectedFiles, key.getGlob() ); + + if ( !key.isRecursive() ) + { + if ( logger.isDebugEnabled() ) + { + logDebug( "Skipping subtree (non recursive): " + path ); + } + return FileVisitResult.SKIP_SUBTREE; + } + + if ( logger.isDebugEnabled() ) + { + logDebug( "Visiting subtree: " + path ); + } + return FileVisitResult.CONTINUE; + } + } ); + } + + private void addInputsFromPluginConfigs( Xpp3Dom[] configurationChildren, + PluginScanConfig scanConfig, + List files, HashSet visitedDirs ) + { + + if ( configurationChildren == null ) + { + return; + } + + for ( Xpp3Dom configChild : configurationChildren ) + { + + String tagValue = configChild.getValue(); + String tagName = configChild.getName(); + + if ( !scanConfig.accept( tagName ) ) + { + logDebug( "Skipping property (scan config)): " + tagName + ", value: " + stripToEmpty( tagValue ) ); + continue; + } + + logDebug( "Checking xml tag. Tag: " + tagName + ", value: " + stripToEmpty( tagValue ) ); + + addInputsFromPluginConfigs( configChild.getChildren(), scanConfig, files, visitedDirs ); + + final ScanConfigProperties propertyConfig = scanConfig.getTagScanProperties( tagName ); + final String glob = defaultIfEmpty( propertyConfig.getGlob(), dirGlob ); + if ( "true".equals( configChild.getAttribute( CACHE_INPUT_NAME ) ) ) + { + logInfo( + "Found tag marked with " + CACHE_INPUT_NAME + " attribute. Tag: " + tagName + + ", value: " + tagValue ); + startWalk( Paths.get( tagValue ), glob, propertyConfig.isRecursive(), files, visitedDirs ); + } + else + { + final Path candidate = getPathOrNull( tagValue ); + if ( candidate != null ) + { + startWalk( candidate, glob, propertyConfig.isRecursive(), files, visitedDirs ); + if ( "descriptorRef".equals( tagName ) ) + { // hardcoded logic for assembly plugin which could reference files omitting .xml suffix + startWalk( Paths.get( tagValue + ".xml" ), glob, propertyConfig.isRecursive(), files, + visitedDirs ); + } + } + } + } + } + + private Path getPathOrNull( String text ) + { + // small optimization to not probe not-paths + boolean blacklisted = isBlank( text ) + || equalsAnyIgnoreCase( text, "true", "false", "utf-8", "null", "\\" ) // common values + || contains( text, "*" ) // tag value is a glob or regex - unclear how to process + || ( contains( text, ":" ) && !contains( text, ":\\" ) )// artifactId + || startsWithAny( text, "com.", "org.", "io.", "java.", "javax." ) // java packages + || startsWithAny( text, "${env." ) // env variables in maven notation + || startsWithAny( text, "http:", "https:", "scm:", "ssh:", "git:", "svn:", "cp:", + "classpath:" ); // urls identified by common protocols + if ( !blacklisted ) + { + try + { + return Paths.get( text ); + } + catch ( Exception ignore ) + { + } + } + if ( logger.isDebugEnabled() ) + { + logDebug( text + ( blacklisted ? ": skipped(blacklisted literal)" : ": invalid path" ) ); + } + return null; + } + + private void logDebug( String message ) + { + if ( logger.isDebugEnabled() ) + { + logger.debug( "[CACHE][" + project.getArtifactId() + "] " + message ); + } + } + + private void logInfo( String message ) + { + if ( logger.isInfoEnabled() ) + { + logger.info( "[CACHE][" + project.getArtifactId() + "] " + message ); + } + } + + static void walkDirectoryFiles( Path dir, List collectedFiles, String glob ) + { + if ( !Files.isDirectory( dir ) ) + { + return; + } + + try + { + try ( DirectoryStream stream = Files.newDirectoryStream( dir, glob ) ) + { + for ( Path entry : stream ) + { + File file = entry.toFile(); + if ( file.isFile() && !isHidden( entry ) ) + { + collectedFiles.add( entry ); + } + } + } + } + catch ( IOException e ) + { + throw new RuntimeException( "Cannot process directory: " + dir, e ); + } + } + + private static boolean isHidden( Path entry ) throws IOException + { + return Files.isHidden( entry ) || entry.toFile().getName().startsWith( "." ); + } + + private boolean isFilteredOutSubpath( Path path ) + { + Path normalized = path.normalize(); + for ( Path filteredOutDir : filteredOutPaths ) + { + if ( normalized.startsWith( filteredOutDir ) ) + { + return true; + } + } + return false; + } + + private SortedMap getMutableDependencies() throws IOException + { + MultimoduleDiscoveryStrategy strategy = config.getMultimoduleDiscoveryStrategy(); + SortedMap result = new TreeMap<>(); + + for ( Dependency dependency : project.getDependencies() ) + { + // saved to index by the end of dependency build + final boolean currentlyBuilding = isBuilding( dependency, projectIndex ); + final boolean partOfMultiModule = strategy.isPartOfMultiModule( dependency ); + if ( !currentlyBuilding && !partOfMultiModule && !isSnapshot( dependency.getVersion() ) ) + { + // external immutable dependency, should skip + continue; + } + + if ( ProjectUtils.isPom( dependency ) ) + { + // POM dependency will be resolved by maven system to actual dependencies + // and will contribute to effective pom. + // Effective result will be recorded by #getNormalizedPom + // so pom dependencies must be skipped as meaningless by themselves + continue; + } + + final Artifact dependencyArtifact = repoSystem.createDependencyArtifact( dependency ); + final String artifactKey = KeyUtils.getArtifactKey( dependencyArtifact ); + DigestItemType resolved = null; + if ( currentlyBuilding ) + { + resolved = projectArtifactsByKey.get( artifactKey ); + if ( resolved == null ) + { + throw new DependencyNotResolvedException( "Expected dependency not resolved: " + dependency ); + } + } + else + { + if ( partOfMultiModule ) + { + // TODO lookup in remote cache is not necessary for abfx, for versioned projects - make sense + final Optional bestMatchResult = localCache.findBestMatchingBuild( session, dependency ); + if ( bestMatchResult.isPresent() ) + { + final BuildInfo bestMatched = bestMatchResult.get(); + resolved = bestMatched.findArtifact( dependency ); + } + } + if ( resolved == null && !ProjectUtils.isPom( dependency ) ) + { + try + { + resolved = resolveArtifact( dependencyArtifact, strategy ); + } + catch ( Exception e ) + { + throw new RuntimeException( "Cannot resolve dependency " + dependency, e ); + } + } + } + result.put( artifactKey, resolved ); + } + return result; + } + + @Nonnull + private DigestItemType resolveArtifact( final Artifact dependencyArtifact, + MultimoduleDiscoveryStrategy strategy ) throws IOException + { + + ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( + dependencyArtifact ).setResolveRoot( true ).setResolveTransitively( false ).setLocalRepository( + session.getLocalRepository() ).setRemoteRepositories( + project.getRemoteArtifactRepositories() ).setOffline( + session.isOffline() || !strategy.isLookupRemoteMavenRepo( dependencyArtifact ) ).setForceUpdate( + session.getRequest().isUpdateSnapshots() ).setServers( session.getRequest().getServers() ).setMirrors( + session.getRequest().getMirrors() ).setProxies( session.getRequest().getProxies() ); + + final ArtifactResolutionResult result = repoSystem.resolve( request ); + + if ( !result.isSuccess() ) + { + throw new DependencyNotResolvedException( "Cannot resolve in-project dependency: " + dependencyArtifact ); + } + + if ( !result.getMissingArtifacts().isEmpty() ) + { + throw new DependencyNotResolvedException( + "Cannot resolve artifact: " + dependencyArtifact + ", missing: " + result.getMissingArtifacts() ); + } + + if ( result.getArtifacts().size() > 1 ) + { + throw new IllegalStateException( + "Unexpected number of artifacts returned. Requested: " + dependencyArtifact + + ", expected: 1, actual: " + result.getArtifacts() ); + } + + final Artifact resolved = Iterables.getOnlyElement( result.getArtifacts() ); + + final HashAlgorithm algorithm = config.getHashFactory().createAlgorithm(); + final String hash = algorithm.hash( resolved.getFile().toPath() ); + return DtoUtils.createDigestedFile( resolved, hash ); + } + + /** + * PathIgnoringCaseComparator + */ + public static class PathIgnoringCaseComparator implements Comparator + { + @Override + public int compare( Path f1, Path f2 ) + { + String s1 = f1.toAbsolutePath().toString(); + String s2 = f2.toAbsolutePath().toString(); + if ( File.separator.equals( "\\" ) ) + { + s1 = s1.replaceAll( "\\\\", "/" ); + s2 = s2.replaceAll( "\\\\", "/" ); + } + return s1.compareToIgnoreCase( s2 ); + } + } + + /** + * DependencyComparator + */ + public static class DependencyComparator implements Comparator + { + @Override + public int compare( Dependency d1, Dependency d2 ) + { + return d1.getArtifactId().compareTo( d2.getArtifactId() ); + } + } + + private List normalizePlugins( List plugins ) + { + for ( Plugin plugin : plugins ) + { + List excludeProperties = config.getEffectivePomExcludeProperties( plugin ); + removeBlacklistedAttributes( (Xpp3Dom) plugin.getConfiguration(), excludeProperties ); + for ( PluginExecution execution : plugin.getExecutions() ) + { + Xpp3Dom config = (Xpp3Dom) execution.getConfiguration(); + removeBlacklistedAttributes( config, excludeProperties ); + } + Collections.sort( plugin.getDependencies(), dependencyComparator ); + } + return plugins; + } + + private void removeBlacklistedAttributes( Xpp3Dom node, List excludeProperties ) + { + if ( node == null ) + { + return; + } + + Xpp3Dom[] children = node.getChildren(); + for ( int i = 0; i < children.length; i++ ) + { + Xpp3Dom child = children[i]; + if ( excludeProperties.contains( child.getName() ) ) + { + node.removeChild( i ); + continue; + } + removeBlacklistedAttributes( child, excludeProperties ); + } + } + + public Logger getLogger() + { + return logger; + } + + public CacheConfig getConfig() + { + return config; + } + + public MavenSession getSession() + { + return session; + } + + public MavenProject getProject() + { + return project; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java new file mode 100644 index 000000000000..b968f7764dca --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java @@ -0,0 +1,33 @@ +package org.apache.maven.caching.checksum; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; + +/** + * MultimoduleDiscoveryStrategy + */ +public interface MultimoduleDiscoveryStrategy +{ + boolean isPartOfMultiModule( Dependency dependency ); + + boolean isLookupRemoteMavenRepo( Artifact dependency ); +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/WalkKey.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/WalkKey.java new file mode 100644 index 000000000000..0d6f274df5b6 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/WalkKey.java @@ -0,0 +1,95 @@ +package org.apache.maven.caching.checksum; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.nio.file.Path; + +/** + * WalkKey + */ +public class WalkKey +{ + private final Path normalized; + private final String glob; + private final boolean recursive; + + public WalkKey( Path normalized, String glob, boolean recursive ) + { + + this.normalized = normalized; + this.glob = glob; + this.recursive = recursive; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + WalkKey key = (WalkKey) o; + + if ( recursive != key.recursive ) + { + return false; + } + if ( !normalized.equals( key.normalized ) ) + { + return false; + } + return glob.equals( key.glob ); + } + + @Override + public int hashCode() + { + int result = normalized.hashCode(); + result = 31 * result + glob.hashCode(); + result = 31 * result + ( recursive ? 1 : 0 ); + return result; + } + + public Path getPath() + { + return normalized; + } + + public String getGlob() + { + return glob; + } + + public boolean isRecursive() + { + return recursive; + } + + @Override + public String toString() + { + return "WalkKey{" + "normalized=" + normalized + ", glob='" + glob + '\'' + ", recursive=" + recursive + '}'; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java b/maven-core/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java new file mode 100644 index 000000000000..0fec3646ffa4 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java @@ -0,0 +1,185 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.IOException; +import java.lang.reflect.Method; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileChannel.MapMode; +import java.security.PrivilegedAction; + +import static java.security.AccessController.doPrivileged; +import static org.apache.maven.caching.hash.ReflectionUtils.getField; +import static org.apache.maven.caching.hash.ReflectionUtils.getMethod; + +/** + * CloseableBuffer https://stackoverflow.com/a/54046774 + */ +public class CloseableBuffer implements AutoCloseable +{ + /* Java 8 + private static final Cleaner CLEANER = doPrivileged((PrivilegedAction) () -> { + final boolean isOldJava = System.getProperty("java.specification.version", "9").startsWith("1."); + if (isOldJava) { + return DirectCleaner.isSupported() ? new DirectCleaner() : new NoopCleaner(); + } else { + return UnsafeCleaner.isSupported() ? new UnsafeCleaner() : new NoopCleaner(); + } + }); + */ + private static final Cleaner CLEANER = doPrivileged( new PrivilegedAction() + { + @Override + public Cleaner run() + { + return DirectCleaner.isSupported() ? new DirectCleaner() : new NoopCleaner(); + } + } ); + + public static CloseableBuffer directBuffer( int capacity ) + { + return new CloseableBuffer( ByteBuffer.allocateDirect( capacity ) ); + } + + public static CloseableBuffer mappedBuffer( FileChannel channel, MapMode mode ) throws IOException + { + return new CloseableBuffer( channel.map( mode, 0, channel.size() ) ); + } + + private ByteBuffer buffer; + + /** + * Unmap only DirectByteBuffer and MappedByteBuffer + */ + private CloseableBuffer( ByteBuffer buffer ) + { + // Java 8: buffer.isDirect() + this.buffer = buffer; + } + + /** + * Do not use buffer after close + */ + public ByteBuffer getBuffer() + { + return buffer; + } + + @Override + public void close() + { + // Java 8: () -> CLEANER.clean(buffer) + boolean done = doPrivileged( new PrivilegedAction() + { + @Override + public Boolean run() + { + return CLEANER.clean( buffer ); + } + } ); + if ( done ) + { + buffer = null; + } + } + + // Java 8: @FunctionalInterface + private interface Cleaner + { + boolean clean( ByteBuffer buffer ); + } + + private static class NoopCleaner implements Cleaner + { + @Override + public boolean clean( ByteBuffer buffer ) + { + return false; + } + } + + private static class DirectCleaner implements Cleaner + { + private static final Method ATTACHMENT = getMethod( "sun.nio.ch.DirectBuffer", + "attachment" ); + private static final Method CLEANER = getMethod( "sun.nio.ch.DirectBuffer", "cleaner" ); + private static final Method CLEAN = getMethod( "sun.misc.Cleaner", "clean" ); + + public static boolean isSupported() + { + return ATTACHMENT != null && CLEAN != null && CLEANER != null; + } + + /** + * Make sure duplicates and slices are not cleaned, since this can result in duplicate attempts to clean the + * same buffer, which trigger a crash with: "A fatal error has been detected by the Java Runtime Environment: + * EXCEPTION_ACCESS_VIOLATION" See: https://stackoverflow.com/a/31592947/3950982 + */ + @Override + public boolean clean( ByteBuffer buffer ) + { + try + { + if ( ATTACHMENT.invoke( buffer ) == null ) + { + CLEAN.invoke( CLEANER.invoke( buffer ) ); + return true; + } + } + catch ( Exception ignore ) + { + } + return false; + } + } + + private static class UnsafeCleaner implements Cleaner + { + // Java 9: getMethod("jdk.internal.misc.Unsafe", "invokeCleaner", ByteBuffer.class); + private static final Method INVOKE_CLEANER = getMethod( "sun.misc.Unsafe", "invokeCleaner", ByteBuffer.class ); + private static final Object UNSAFE = getField( "sun.misc.Unsafe", "theUnsafe" ); + + public static boolean isSupported() + { + return UNSAFE != null && INVOKE_CLEANER != null; + } + + /** + * Calling the above code in JDK9+ gives a reflection warning on stderr, + * Unsafe.theUnsafe.invokeCleaner(byteBuffer) + * makes the same call, but does not print the reflection warning + */ + @Override + public boolean clean( ByteBuffer buffer ) + { + try + { + // throws IllegalArgumentException if buffer is a duplicate or slice + INVOKE_CLEANER.invoke( UNSAFE, buffer ); + return true; + } + catch ( Exception ignore ) + { + } + return false; + } + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/Hash.java b/maven-core/src/main/java/org/apache/maven/caching/hash/Hash.java new file mode 100644 index 000000000000..82220634cc6b --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/Hash.java @@ -0,0 +1,61 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.IOException; +import java.nio.file.Path; + +/** + * Hash + */ +public class Hash +{ + /** + * Algorithm + */ + public interface Algorithm + { + byte[] hash( byte[] array ); + + byte[] hash( Path path ) throws IOException; + } + + /** + * accumulates states and should be completed by {@link #digest()} + */ + public interface Checksum + { + void update( byte[] hash ); + + byte[] digest(); + } + + /** + * Factory + */ + public interface Factory + { + String getAlgorithm(); + + Algorithm algorithm(); + + Checksum checksum( int count ); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java b/maven-core/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java new file mode 100644 index 000000000000..ec6ad68a053d --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java @@ -0,0 +1,46 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.IOException; +import java.nio.file.Path; + +/** + * HashAlgorithm + */ +public class HashAlgorithm +{ + private final Hash.Algorithm algorithm; + + HashAlgorithm( Hash.Algorithm algorithm ) + { + this.algorithm = algorithm; + } + + public String hash( Path path ) throws IOException + { + return HexUtils.encode( algorithm.hash( path ) ); + } + + public String hash( byte[] bytes ) + { + return HexUtils.encode( algorithm.hash( bytes ) ); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/HashChecksum.java b/maven-core/src/main/java/org/apache/maven/caching/hash/HashChecksum.java new file mode 100644 index 000000000000..904077a6abae --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/HashChecksum.java @@ -0,0 +1,67 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.IOException; +import java.nio.file.Path; + +/** + * HashChecksum + */ +public class HashChecksum +{ + private final Hash.Algorithm algorithm; + private final Hash.Checksum checksum; + + HashChecksum( Hash.Algorithm algorithm, Hash.Checksum checksum ) + { + this.algorithm = algorithm; + this.checksum = checksum; + } + + public String update( Path path ) throws IOException + { + return updateAndEncode( algorithm.hash( path ) ); + } + + public String update( byte[] bytes ) + { + return updateAndEncode( algorithm.hash( bytes ) ); + } + + /** + * @param hexHash hash value in hex format. This method doesn't accept generic text - could result in error + */ + public String update( String hexHash ) + { + return updateAndEncode( HexUtils.decode( hexHash ) ); + } + + private String updateAndEncode( byte[] hash ) + { + checksum.update( hash ); + return HexUtils.encode( hash ); + } + + public String digest() + { + return HexUtils.encode( checksum.digest() ); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/HashFactory.java b/maven-core/src/main/java/org/apache/maven/caching/hash/HashFactory.java new file mode 100644 index 000000000000..d610fceab924 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/HashFactory.java @@ -0,0 +1,79 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.Map; + +/** + * HashFactory + */ +public enum HashFactory +{ + SHA1( new SHA( "SHA-1" ) ), + SHA256( new SHA( "SHA-256" ) ), + SHA384( new SHA( "SHA-384" ) ), + SHA512( new SHA( "SHA-512" ) ), + XX( new XX() ), + XXMM( new XXMM() ); + + private static final Map LOOKUP = new HashMap<>(); + + static + { + for ( HashFactory factory : HashFactory.values() ) + { + LOOKUP.put( factory.getAlgorithm(), factory ); + } + } + + public static HashFactory of( String algorithm ) throws NoSuchAlgorithmException + { + final HashFactory factory = LOOKUP.get( algorithm ); + if ( factory == null ) + { + throw new NoSuchAlgorithmException( algorithm ); + } + return factory; + } + + private final Hash.Factory factory; + + HashFactory( Hash.Factory factory ) + { + this.factory = factory; + } + + public String getAlgorithm() + { + return factory.getAlgorithm(); + } + + public HashAlgorithm createAlgorithm() + { + return new HashAlgorithm( factory.algorithm() ); + } + + public HashChecksum createChecksum( int count ) + { + return new HashChecksum( factory.algorithm(), factory.checksum( count ) ); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/HexUtils.java b/maven-core/src/main/java/org/apache/maven/caching/hash/HexUtils.java new file mode 100644 index 000000000000..f85d0f9c515c --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/HexUtils.java @@ -0,0 +1,56 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.google.common.base.CharMatcher; +import com.google.common.io.BaseEncoding; + +/** + * HexUtils + */ +public class HexUtils +{ + + private static final BaseEncoding ENCODING = BaseEncoding.base16().lowerCase(); + private static final CharMatcher MATCHER = CharMatcher.is( '0' ); + + public static String encode( byte[] hash ) + { + return trimLeadingZero( ENCODING.encode( hash ) ); + } + + public static byte[] decode( String hex ) + { + return ENCODING.decode( padLeadingZero( hex ) ); + } + + private static String trimLeadingZero( String hex ) + { + String value = MATCHER.trimLeadingFrom( hex ); + return value.isEmpty() ? "0" : value; + } + + private static String padLeadingZero( String hex ) + { + String value = hex.toLowerCase(); + return value.length() % 2 == 0 ? value : "0" + value; + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java b/maven-core/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java new file mode 100644 index 000000000000..259e6f0b7feb --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java @@ -0,0 +1,61 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +/** + * ReflectionUtils + */ +class ReflectionUtils +{ + static Method getMethod( String className, String methodName, Class... parameterTypes ) + { + try + { + final Method method = Class.forName( className ).getMethod( methodName, parameterTypes ); + method.setAccessible( true ); + return method; + } + catch ( Exception ignore ) + { + return null; + } + } + + static Object getField( String className, String fieldName ) + { + try + { + final Field field = Class.forName( className ).getDeclaredField( fieldName ); + field.setAccessible( true ); + return field.get( null ); + } + catch ( Exception ignore ) + { + return null; + } + } + + private ReflectionUtils() + { + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/SHA.java b/maven-core/src/main/java/org/apache/maven/caching/hash/SHA.java new file mode 100644 index 000000000000..e02dfe2f25e2 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/SHA.java @@ -0,0 +1,103 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.MessageDigest; + +/** + * SHA + */ +public class SHA implements Hash.Factory +{ + private static final ThreadLocal ALGORITHM = new ThreadLocal<>(); + private static final ThreadLocal CHECKSUM = new ThreadLocal<>(); + + private final String algorithm; + + SHA( String algorithm ) + { + this.algorithm = algorithm; + } + + @Override + public String getAlgorithm() + { + return algorithm; + } + + @Override + public Hash.Algorithm algorithm() + { + return new SHA.Algorithm( ThreadLocalDigest.get( ALGORITHM, algorithm ) ); + } + + @Override + public Hash.Checksum checksum( int count ) + { + return new SHA.Checksum( ThreadLocalDigest.get( CHECKSUM, algorithm ) ); + } + + private static class Algorithm implements Hash.Algorithm + { + private final MessageDigest digest; + + private Algorithm( MessageDigest digest ) + { + this.digest = digest; + } + + @Override + public byte[] hash( byte[] array ) + { + return digest.digest( array ); + } + + @Override + public byte[] hash( Path path ) throws IOException + { + return hash( Files.readAllBytes( path ) ); + } + } + + private static class Checksum implements Hash.Checksum + { + private final MessageDigest digest; + + private Checksum( MessageDigest digest ) + { + this.digest = digest; + } + + @Override + public void update( byte[] hash ) + { + digest.update( hash ); + } + + @Override + public byte[] digest() + { + return digest.digest(); + } + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java b/maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java new file mode 100644 index 000000000000..6d9f9d6269b7 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java @@ -0,0 +1,86 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.nio.ByteBuffer; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +/** + * ThreadLocalBuffer + */ +public class ThreadLocalBuffer +{ + private static final ConcurrentMap LOCALS = new ConcurrentHashMap<>(); + + public static ByteBuffer get( ThreadLocal local, int capacity ) + { + final CloseableBuffer buffer = local.get(); + if ( buffer == null ) + { + return create( local, capacity ); + } + + if ( capacity( buffer ) < capacity ) + { + close( buffer ); + return create( local, capacity * 2 ); + } + + return clear( buffer ); + } + + @Override + public void finalize() + { + for ( CloseableBuffer buffer : LOCALS.keySet() ) + { + buffer.close(); + } + } + + private static ByteBuffer create( ThreadLocal local, int capacity ) + { + final CloseableBuffer buffer = CloseableBuffer.directBuffer( capacity ); + local.set( buffer ); + LOCALS.put( buffer, false ); + return buffer.getBuffer(); + } + + private static int capacity( CloseableBuffer buffer ) + { + return buffer.getBuffer().capacity(); + } + + private static ByteBuffer clear( CloseableBuffer buffer ) + { + return (ByteBuffer) buffer.getBuffer().clear(); + } + + private static void close( CloseableBuffer buffer ) + { + LOCALS.remove( buffer ); + buffer.close(); + } + + private ThreadLocalBuffer() + { + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java b/maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java new file mode 100644 index 000000000000..2df800e26f7a --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java @@ -0,0 +1,71 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Objects; + +/** + * ThreadLocalDigest + */ +public class ThreadLocalDigest +{ + public static MessageDigest get( ThreadLocal local, String algorithm ) + { + final MessageDigest digest = local.get(); + if ( digest == null ) + { + return create( local, algorithm ); + } + + if ( Objects.equals( digest.getAlgorithm(), algorithm ) ) + { + return reset( digest ); + } + + reset( digest ); + return create( local, algorithm ); + } + + private static MessageDigest create( ThreadLocal local, String algorithm ) + { + try + { + final MessageDigest digest = MessageDigest.getInstance( algorithm ); + local.set( digest ); + return digest; + } + catch ( NoSuchAlgorithmException e ) + { + throw new RuntimeException( "Cannot create message digest with algorithm: " + algorithm, e ); + } + } + + private static MessageDigest reset( MessageDigest digest ) + { + digest.reset(); + return digest; + } + + private ThreadLocalDigest() + { + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/XX.java b/maven-core/src/main/java/org/apache/maven/caching/hash/XX.java new file mode 100644 index 000000000000..24f9f4bff5e7 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/XX.java @@ -0,0 +1,98 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import net.openhft.hashing.LongHashFunction; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.file.Files; +import java.nio.file.Path; + +import static com.google.common.primitives.Longs.toByteArray; + +/** + * XX + */ +public class XX implements Hash.Factory +{ + static final LongHashFunction INSTANCE = LongHashFunction.xx(); + + @Override + public String getAlgorithm() + { + return "XX"; + } + + @Override + public Hash.Algorithm algorithm() + { + return new XX.Algorithm(); + } + + @Override + public Hash.Checksum checksum( int count ) + { + return new XX.Checksum( ByteBuffer.allocate( capacity( count ) ) ); + } + + static int capacity( int count ) + { + // Java 8: Long.BYTES + return count * Long.SIZE / Byte.SIZE; + } + + static class Algorithm implements Hash.Algorithm + { + @Override + public byte[] hash( byte[] array ) + { + return toByteArray( INSTANCE.hashBytes( array ) ); + } + + @Override + public byte[] hash( Path path ) throws IOException + { + return hash( Files.readAllBytes( path ) ); + } + } + + static class Checksum implements Hash.Checksum + { + private final ByteBuffer buffer; + + Checksum( ByteBuffer buffer ) + { + this.buffer = buffer; + } + + @Override + public void update( byte[] hash ) + { + buffer.put( hash ); + } + + @Override + public byte[] digest() + { + return toByteArray( INSTANCE.hashBytes( buffer, 0, buffer.position() ) ); + } + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/XXMM.java b/maven-core/src/main/java/org/apache/maven/caching/hash/XXMM.java new file mode 100644 index 000000000000..8e09299c247e --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/XXMM.java @@ -0,0 +1,67 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.nio.file.Path; + +import static com.google.common.primitives.Longs.toByteArray; +import static java.nio.channels.FileChannel.MapMode.READ_ONLY; +import static java.nio.file.StandardOpenOption.READ; + +/** + * XXMM + */ +public class XXMM implements Hash.Factory +{ + private static final ThreadLocal BUFFER = new ThreadLocal<>(); + + @Override + public String getAlgorithm() + { + return "XXMM"; + } + + @Override + public Hash.Algorithm algorithm() + { + return new Algorithm(); + } + + @Override + public Hash.Checksum checksum( int count ) + { + return new XX.Checksum( ThreadLocalBuffer.get( BUFFER, XX.capacity( count ) ) ); + } + + private static class Algorithm extends XX.Algorithm + { + @Override + public byte[] hash( Path path ) throws IOException + { + try ( FileChannel channel = FileChannel.open( path, + READ ); CloseableBuffer buffer = CloseableBuffer.mappedBuffer( channel, READ_ONLY ) ) + { + return toByteArray( XX.INSTANCE.hashBytes( buffer.getBuffer() ) ); + } + } + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java b/maven-core/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java new file mode 100644 index 000000000000..00c1d4d84ac8 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java @@ -0,0 +1,42 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; +import org.apache.maven.model.Dependency; + +/** + * AllExternalSrategy + */ +public class AllExternalSrategy implements MultimoduleDiscoveryStrategy +{ + @Override + public boolean isPartOfMultiModule( Dependency dependency ) + { + return false; + } + + @Override + public boolean isLookupRemoteMavenRepo( Artifact artifact ) + { + return true; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java b/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java new file mode 100644 index 000000000000..0b61bfd89d74 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java @@ -0,0 +1,273 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.google.common.collect.Iterables; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.caching.ProjectUtils; +import org.apache.maven.caching.checksum.MavenProjectInput; +import org.apache.maven.caching.hash.HashAlgorithm; +import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.caching.jaxb.BuildInfoType; +import org.apache.maven.caching.jaxb.CompletedExecutionType; +import org.apache.maven.caching.jaxb.DigestItemType; +import org.apache.maven.caching.jaxb.ProjectsInputInfoType; +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.MojoExecution; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.util.StringUtils; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.Objects; + +import static org.apache.maven.caching.ProjectUtils.isLaterPhase; +import static org.apache.maven.caching.ProjectUtils.mojoExecutionKey; + +/** + * BuildInfo + */ +public class BuildInfo +{ + + final BuildInfoType dto; + CacheSource source; + + public BuildInfo( List goals, + ArtifactType artifact, + List attachedArtifacts, + ProjectsInputInfoType projectsInputInfo, + List completedExecutions, + String hashAlgorithm ) + { + this.dto = new BuildInfoType(); + this.dto.setCacheImplementationVersion( MavenProjectInput.CACHE_IMPLMENTATION_VERSION ); + try + { + this.dto.setBuildTime( DatatypeFactory.newInstance().newXMLGregorianCalendar( new GregorianCalendar() ) ); + } + catch ( DatatypeConfigurationException ignore ) + { + } + try + { + this.dto.setBuildServer( InetAddress.getLocalHost().getCanonicalHostName() ); + } + catch ( UnknownHostException ignore ) + { + this.dto.setBuildServer( "unknown" ); + } + this.dto.setHashFunction( hashAlgorithm ); + this.dto.setArtifact( artifact ); + this.dto.setGoals( createGoals( goals ) ); + this.dto.setAttachedArtifacts( new BuildInfoType.AttachedArtifacts() ); + this.dto.getAttachedArtifacts().getArtifact().addAll( attachedArtifacts ); + this.dto.setExecutions( createExecutions( completedExecutions ) ); + this.dto.setProjectsInputInfo( projectsInputInfo ); + this.source = CacheSource.BUILD; + } + + public CacheSource getSource() + { + return source; + } + + private BuildInfoType.Executions createExecutions( List completedExecutions ) + { + BuildInfoType.Executions executions = new BuildInfoType.Executions(); + executions.getExecution().addAll( completedExecutions ); + return executions; + } + + public BuildInfo( BuildInfoType buildInfo, CacheSource source ) + { + this.dto = buildInfo; + this.source = source; + } + + public static BuildInfoType.Goals createGoals( List list ) + { + BuildInfoType.Goals goals = new BuildInfoType.Goals(); + goals.getGoal().addAll( list ); + return goals; + } + + public static BuildInfoType.AttachedArtifacts createAttachedArtifacts( List artifacts, + HashAlgorithm algorithm ) throws IOException + { + BuildInfoType.AttachedArtifacts attachedArtifacts = new BuildInfoType.AttachedArtifacts(); + for ( Artifact artifact : artifacts ) + { + final ArtifactType dto = DtoUtils.createDto( artifact ); + if ( artifact.getFile() != null ) + { + dto.setFileHash( algorithm.hash( artifact.getFile().toPath() ) ); + } + attachedArtifacts.getArtifact().add( dto ); + } + return attachedArtifacts; + } + + public boolean isAllExecutionsPresent( List mojos, Logger logger ) + { + for ( MojoExecution mojo : mojos ) + { + // TODO for strict check we might want exact match + if ( !hasCompletedExecution( mojoExecutionKey( mojo ) ) ) + { + logger.error( "Build mojo is not cached: " + mojo ); + return false; + } + } + return true; + } + + private boolean hasCompletedExecution( String mojoExecutionKey ) + { + final List completedExecutions = dto.getExecutions().getExecution(); + for ( CompletedExecutionType completedExecution : completedExecutions ) + { + if ( StringUtils.equals( completedExecution.getExecutionKey(), mojoExecutionKey ) ) + { + return true; + } + } + return false; + } + + @Override + public String toString() + { + return "BuildInfo{" + "dto=" + dto + '}'; + } + + public CompletedExecutionType findMojoExecutionInfo( MojoExecution mojoExecution ) + { + + if ( !dto.isSetExecutions() ) + { + return null; + } + + final List executions = dto.getExecutions().getExecution(); + for ( CompletedExecutionType execution : executions ) + { + if ( StringUtils.equals( execution.getExecutionKey(), mojoExecutionKey( mojoExecution ) ) ) + { + return execution; + } + } + return null; + } + + public String getCacheImplementationVersion() + { + return dto.getCacheImplementationVersion(); + } + + public ArtifactType getArtifact() + { + return dto.getArtifact(); + } + + public List getAttachedArtifacts() + { + if ( dto.isSetAttachedArtifacts() ) + { + return dto.getAttachedArtifacts().getArtifact(); + } + return Collections.emptyList(); + } + + public BuildInfoType getDto() + { + return dto; + } + + public String getHighestCompletedGoal() + { + return Iterables.getLast( dto.getGoals().getGoal() ); + } + + public List getCachedSegment( List mojoExecutions ) + { + List list = new ArrayList<>(); + for ( MojoExecution mojoExecution : mojoExecutions ) + { + if ( !isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) + { + continue; + } + if ( isLaterPhase( mojoExecution.getLifecyclePhase(), getHighestCompletedGoal() ) ) + { + break; + } + list.add( mojoExecution ); + } + return list; + + } + + public List getPostCachedSegment( List mojoExecutions ) + { + List list = new ArrayList<>(); + for ( MojoExecution mojoExecution : mojoExecutions ) + { + if ( isLaterPhase( mojoExecution.getLifecyclePhase(), getHighestCompletedGoal() ) ) + { + list.add( mojoExecution ); + } + } + return list; + } + + public DigestItemType findArtifact( Dependency dependency ) + { + + if ( ProjectUtils.isPom( dependency ) ) + { + throw new IllegalArgumentException( "Pom dependencies should not be treated as artifacts: " + dependency ); + } + List artifacts = new ArrayList<>( getAttachedArtifacts() ); + artifacts.add( getArtifact() ); + for ( ArtifactType artifact : artifacts ) + { + if ( isEquals( dependency, artifact ) ) + { + return DtoUtils.createdDigestedByProjectChecksum( artifact, dto.getProjectsInputInfo().getChecksum() ); + } + } + return null; + } + + private boolean isEquals( Dependency dependency, ArtifactType artifact ) + { + return Objects.equals( dependency.getGroupId(), artifact.getArtifactId() ) && Objects.equals( + dependency.getArtifactId(), artifact.getArtifactId() ) && Objects.equals( dependency.getType(), + artifact.getType() ) && Objects.equals( dependency.getClassifier(), artifact.getClassifier() ); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java new file mode 100644 index 000000000000..2f5137d9a3ea --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java @@ -0,0 +1,108 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.caching.PluginScanConfig; +import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; +import org.apache.maven.caching.hash.HashFactory; +import org.apache.maven.caching.jaxb.PathSetType; +import org.apache.maven.caching.jaxb.PropertyNameType; +import org.apache.maven.caching.jaxb.TrackedPropertyType; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.project.MavenProject; + +import javax.annotation.Nonnull; +import java.util.List; +import java.util.regex.Pattern; + +/** + * CacheConfig + */ +public interface CacheConfig +{ + + CacheState initialize( MavenProject project, MavenSession session ); + + @Nonnull + List getTrackedProperties( MojoExecution mojoExecution ); + + boolean isLogAllProperties( MojoExecution mojoExecution ); + + @Nonnull + List getLoggedProperties( MojoExecution mojoExecution ); + + @Nonnull + List getNologProperties( MojoExecution mojoExecution ); + + @Nonnull + List getEffectivePomExcludeProperties( Plugin plugin ); + + String isProcessPlugins(); + + String getDefaultGlob(); + + @Nonnull + List getGlobalIncludePaths(); + + @Nonnull + List getGlobalExcludePaths(); + + @Nonnull + PluginScanConfig getPluginDirScanConfig( Plugin plugin ); + + @Nonnull + PluginScanConfig getExecutionDirScanConfig( Plugin plugin, PluginExecution exec ); + + @Nonnull + MultimoduleDiscoveryStrategy getMultimoduleDiscoveryStrategy(); + + @Nonnull + HashFactory getHashFactory(); + + boolean isForcedExecution( MojoExecution execution ); + + String getUrl(); + + boolean isEnabled(); + + boolean isRemoteCacheEnabled(); + + boolean isSaveToRemote(); + + boolean isSaveFinal(); + + boolean isFailFast(); + + int getMaxLocalBuildsCached(); + + List getAttachedOutputs(); + + boolean canIgnore( MojoExecution mojoExecution ); + + @Nonnull + List getExcludePatterns(); + + boolean isBaselineDiffEnabled(); + + String getBaselineCacheUrl(); +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java new file mode 100644 index 000000000000..9dd0e85f578f --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -0,0 +1,579 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.caching.DefaultPluginScanConfig; +import org.apache.maven.caching.PluginScanConfig; +import org.apache.maven.caching.PluginScanConfigImpl; +import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; +import org.apache.maven.caching.hash.HashFactory; +import org.apache.maven.caching.jaxb.CacheType; +import org.apache.maven.caching.jaxb.ConfigurationType; +import org.apache.maven.caching.jaxb.CoordinatesBaseType; +import org.apache.maven.caching.jaxb.ExecutablesType; +import org.apache.maven.caching.jaxb.ExecutionConfigurationScanType; +import org.apache.maven.caching.jaxb.ExecutionControlType; +import org.apache.maven.caching.jaxb.ExecutionIdsListType; +import org.apache.maven.caching.jaxb.GoalReconciliationType; +import org.apache.maven.caching.jaxb.GoalsListType; +import org.apache.maven.caching.jaxb.PathSetType; +import org.apache.maven.caching.jaxb.PluginConfigurationScanType; +import org.apache.maven.caching.jaxb.PluginSetType; +import org.apache.maven.caching.jaxb.PropertyNameType; +import org.apache.maven.caching.jaxb.TrackedPropertyType; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.logging.Logger; + +import javax.annotation.Nonnull; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.regex.Pattern; + +import static com.google.common.base.Preconditions.checkState; +import static java.lang.Boolean.TRUE; +import static java.lang.Boolean.parseBoolean; +import static org.apache.maven.caching.ProjectUtils.getMultimoduleRoot; + +/** + * CacheConfigImpl + */ +@Component( role = CacheConfig.class, + instantiationStrategy = "singleton" ) +public class CacheConfigImpl implements CacheConfig +{ + + public static final String CONFIG_PATH_PROPERTY_NAME = "remote.cache.configPath"; + public static final String CACHE_ENABLED_PROPERTY_NAME = "remote.cache.enabled"; + public static final String SAVE_TO_REMOTE_PROPERTY_NAME = "remote.cache.save.enabled"; + public static final String SAVE_NON_OVERRIDEABLE_NAME = "remote.cache.save.final"; + public static final String FAIL_FAST_PROPERTY_NAME = "remote.cache.failFast"; + public static final String BASELINE_BUILD_URL_PROPERTY_NAME = "remote.cache.baselineUrl"; + + @Requirement + private Logger logger; + + @Requirement + private XmlService xmlService; + + private volatile CacheState state = CacheState.NOT_INITIALIZED; + private volatile CacheType cacheConfig; + private volatile HashFactory hashFactory; + + private final Supplier> excludePatterns = Suppliers.memoize( new Supplier>() + { + @Override + public List get() + { + return compileExcludePatterns(); + } + } ); + + + @Override + public synchronized CacheState initialize( MavenProject project, MavenSession session ) + { + + if ( state != CacheState.NOT_INITIALIZED ) + { + return state; + } + + final String enabled = System.getProperty( CACHE_ENABLED_PROPERTY_NAME, "true" ); + if ( !parseBoolean( enabled ) ) + { + logger.info( "Cache disabled by command line flag, project will be built fully and not cached" ); + state = CacheState.DISABLED; + return state; + } + + Path configPath = null; + + String configPathText = System.getProperty( CONFIG_PATH_PROPERTY_NAME ); + if ( StringUtils.isNotBlank( configPathText ) ) + { + configPath = Paths.get( configPathText ); + } + if ( configPath == null ) + { + configPathText = project.getProperties().getProperty( CONFIG_PATH_PROPERTY_NAME ); + if ( StringUtils.isNotBlank( configPathText ) ) + { + configPath = Paths.get( configPathText ); + } + } + + if ( configPath == null ) + { + configPath = Paths.get( getMultimoduleRoot( session ), ".mvn", "maven-cache-config.xml" ); + } + + if ( !Files.exists( configPath ) ) + { + logger.warn( + "Cache configuration is not available at configured path " + configPath + ", cache is disabled" ); + state = CacheState.DISABLED; + return state; + } + + try + { + logger.info( "Loading cache configuration from " + configPath ); + cacheConfig = xmlService.fromFile( CacheType.class, configPath.toFile() ); + } + catch ( Exception e ) + { + throw new IllegalArgumentException( + "Cannot initialize cache because xml config is not valid or not available", e ); + } + + if ( !cacheConfig.getConfiguration().isEnabled() ) + { + state = CacheState.DISABLED; + return state; + } + + String hashAlgorithm = null; + try + { + hashAlgorithm = getConfiguration().getHashAlgorithm(); + hashFactory = HashFactory.of( hashAlgorithm ); + logger.info( "Using " + hashAlgorithm + " hash algorithm for cache" ); + } + catch ( Exception e ) + { + throw new IllegalArgumentException( "Unsupported hashing algorithm: " + hashAlgorithm, e ); + } + + state = CacheState.INITIALIZED; + return state; + } + + @Nonnull + @Override + public List getTrackedProperties( MojoExecution mojoExecution ) + { + checkInitializedState(); + final GoalReconciliationType reconciliationConfig = findReconciliationConfig( mojoExecution ); + if ( reconciliationConfig != null ) + { + return reconciliationConfig.getReconcile(); + } + else + { + return Collections.emptyList(); + } + } + + @Override + public boolean isLogAllProperties( MojoExecution mojoExecution ) + { + final GoalReconciliationType reconciliationConfig = findReconciliationConfig( mojoExecution ); + if ( reconciliationConfig != null && reconciliationConfig.isLogAll() ) + { + return true; + } + return cacheConfig.isSetExecutionControl() && cacheConfig.getExecutionControl().isSetReconcile() + && cacheConfig.getExecutionControl().getReconcile().isLogAllProperties(); + } + + private GoalReconciliationType findReconciliationConfig( MojoExecution mojoExecution ) + { + + if ( !cacheConfig.isSetExecutionControl() ) + { + return null; + } + + final ExecutionControlType executionControl = cacheConfig.getExecutionControl(); + if ( !executionControl.isSetReconcile() ) + { + return null; + } + + final List reconciliation = executionControl.getReconcile().getPlugin(); + + for ( GoalReconciliationType goalReconciliationConfig : reconciliation ) + { + + final String goal = mojoExecution.getGoal(); + + if ( isPluginMatch( mojoExecution.getPlugin(), goalReconciliationConfig ) && StringUtils.equals( goal, + goalReconciliationConfig.getGoal() ) ) + { + return goalReconciliationConfig; + } + } + return null; + } + + @Nonnull + @Override + public List getLoggedProperties( MojoExecution mojoExecution ) + { + checkInitializedState(); + + final GoalReconciliationType reconciliationConfig = findReconciliationConfig( mojoExecution ); + if ( reconciliationConfig != null ) + { + return reconciliationConfig.getLog(); + } + else + { + return Collections.emptyList(); + } + } + + @Nonnull + @Override + public List getNologProperties( MojoExecution mojoExecution ) + { + checkInitializedState(); + final GoalReconciliationType reconciliationConfig = findReconciliationConfig( mojoExecution ); + if ( reconciliationConfig != null ) + { + return reconciliationConfig.getNolog(); + } + else + { + return Collections.emptyList(); + } + } + + @Nonnull + @Override + public List getEffectivePomExcludeProperties( Plugin plugin ) + { + checkInitializedState(); + final PluginConfigurationScanType pluginConfig = findPluginScanConfig( plugin ); + + if ( pluginConfig != null && pluginConfig.isSetEffectivePom() ) + { + return pluginConfig.getEffectivePom().getExcludeProperty(); + } + return Collections.emptyList(); + } + + private PluginConfigurationScanType findPluginScanConfig( Plugin plugin ) + { + + if ( !cacheConfig.isSetInput() ) + { + return null; + } + + final List pluginConfigs = cacheConfig.getInput().getPlugin(); + for ( PluginConfigurationScanType pluginConfig : pluginConfigs ) + { + if ( isPluginMatch( plugin, pluginConfig ) ) + { + return pluginConfig; + } + } + return null; + } + + private boolean isPluginMatch( Plugin plugin, CoordinatesBaseType pluginConfig ) + { + return StringUtils.equals( pluginConfig.getArtifactId(), + plugin.getArtifactId() ) && ( !pluginConfig.isSetGroupId() || StringUtils.equals( + pluginConfig.getGroupId(), plugin.getGroupId() ) ); + } + + + @Nonnull + @Override + public PluginScanConfig getPluginDirScanConfig( Plugin plugin ) + { + checkInitializedState(); + final PluginConfigurationScanType pluginConfig = findPluginScanConfig( plugin ); + if ( pluginConfig == null || !pluginConfig.isSetDirScan() ) + { + return new DefaultPluginScanConfig(); + } + + return new PluginScanConfigImpl( pluginConfig.getDirScan() ); + } + + @Nonnull + @Override + public PluginScanConfig getExecutionDirScanConfig( Plugin plugin, PluginExecution exec ) + { + checkInitializedState(); + final PluginConfigurationScanType pluginScanConfig = findPluginScanConfig( plugin ); + + if ( pluginScanConfig != null ) + { + final ExecutionConfigurationScanType executionScanConfig = findExecutionScanConfig( exec, + pluginScanConfig.getExecution() ); + if ( executionScanConfig != null && executionScanConfig.isSetDirScan() ) + { + return new PluginScanConfigImpl( executionScanConfig.getDirScan() ); + } + } + + return new DefaultPluginScanConfig(); + } + + private ExecutionConfigurationScanType findExecutionScanConfig( PluginExecution execution, + List scanConfigs ) + { + for ( ExecutionConfigurationScanType executionScanConfig : scanConfigs ) + { + if ( executionScanConfig.getExecId().contains( execution.getId() ) ) + { + return executionScanConfig; + } + } + return null; + } + + @Override + public String isProcessPlugins() + { + checkInitializedState(); + return TRUE.toString(); + } + + @Override + public String getDefaultGlob() + { + checkInitializedState(); + return StringUtils.trim( cacheConfig.getInput().getGlobal().getGlob() ); + } + + @Nonnull + @Override + public List getGlobalIncludePaths() + { + checkInitializedState(); + return cacheConfig.getInput().getGlobal().getInclude(); + } + + @Nonnull + @Override + public List getGlobalExcludePaths() + { + checkInitializedState(); + return cacheConfig.getInput().getGlobal().getExclude(); + } + + @Nonnull + @Override + public MultimoduleDiscoveryStrategy getMultimoduleDiscoveryStrategy() + { + checkInitializedState(); + final ConfigurationType.ProjectDiscoveryStrategy projectDiscoveryStrategy = + cacheConfig.getConfiguration().getProjectDiscoveryStrategy(); + if ( projectDiscoveryStrategy.isSetSpecificVersion() ) + { + return new SentinelVersionStartegy( projectDiscoveryStrategy.getSpecificVersion() ); + } + return new AllExternalSrategy(); + } + + @Nonnull + @Override + public HashFactory getHashFactory() + { + checkInitializedState(); + return hashFactory; + } + + @Override + public boolean canIgnore( MojoExecution mojoExecution ) + { + checkInitializedState(); + if ( !cacheConfig.isSetExecutionControl() || !cacheConfig.getExecutionControl().isSetIgnoreMissing() ) + { + return false; + } + + return executionMatches( mojoExecution, cacheConfig.getExecutionControl().getIgnoreMissing() ); + } + + @Override + public boolean isForcedExecution( MojoExecution execution ) + { + checkInitializedState(); + if ( !cacheConfig.isSetExecutionControl() || !cacheConfig.getExecutionControl().isSetRunAlways() ) + { + return false; + } + + return executionMatches( execution, cacheConfig.getExecutionControl().getRunAlways() ); + } + + private boolean executionMatches( MojoExecution execution, ExecutablesType executablesType ) + { + final List pluginConfigs = executablesType.getPlugin(); + for ( PluginSetType pluginConfig : pluginConfigs ) + { + if ( isPluginMatch( execution.getPlugin(), pluginConfig ) ) + { + return true; + } + } + + final List executionIds = executablesType.getExecution(); + for ( ExecutionIdsListType executionConfig : executionIds ) + { + if ( isPluginMatch( execution.getPlugin(), executionConfig ) && executionConfig.getExecId().contains( + execution.getExecutionId() ) ) + { + return true; + } + } + + final List pluginsGoalsList = executablesType.getGoals(); + for ( GoalsListType pluginGoals : pluginsGoalsList ) + { + if ( isPluginMatch( execution.getPlugin(), pluginGoals ) && pluginGoals.getGoal().contains( + execution.getGoal() ) ) + { + return true; + } + } + + return false; + } + + @Override + public boolean isEnabled() + { + return state == CacheState.INITIALIZED; + } + + + @Override + public boolean isRemoteCacheEnabled() + { + checkInitializedState(); + return getRemote().isEnabled(); + } + + @Override + public boolean isSaveToRemote() + { + checkInitializedState(); + return Boolean.getBoolean( SAVE_TO_REMOTE_PROPERTY_NAME ) || getRemote().isSaveToRemote(); + } + + @Override + public boolean isSaveFinal() + { + return Boolean.getBoolean( SAVE_NON_OVERRIDEABLE_NAME ); + } + + @Override + public boolean isFailFast() + { + return Boolean.getBoolean( FAIL_FAST_PROPERTY_NAME ); + } + + @Override + public boolean isBaselineDiffEnabled() + { + return System.getProperties().containsKey( BASELINE_BUILD_URL_PROPERTY_NAME ); + } + + @Override + public String getBaselineCacheUrl() + { + return System.getProperty( BASELINE_BUILD_URL_PROPERTY_NAME ); + } + + @Override + public String getUrl() + { + checkInitializedState(); + return getRemote().getUrl(); + } + + + @Override + public int getMaxLocalBuildsCached() + { + checkInitializedState(); + return getLocal().getMaxBuildsCached().intValue(); + } + + @Override + public List getAttachedOutputs() + { + checkInitializedState(); + final ConfigurationType.AttachedOutputs attachedOutputs = getConfiguration().getAttachedOutputs(); + return attachedOutputs == null ? Collections.emptyList() : attachedOutputs.getDirName(); + } + + @Nonnull + @Override + public List getExcludePatterns() + { + checkInitializedState(); + return excludePatterns.get(); + } + + private List compileExcludePatterns() + { + if ( cacheConfig.isSetOutput() && cacheConfig.getOutput().isSetExclude() ) + { + List patterns = new ArrayList<>(); + for ( String pattern : cacheConfig.getOutput().getExclude().getPattern() ) + { + patterns.add( Pattern.compile( pattern ) ); + } + return patterns; + } + return Collections.emptyList(); + } + + private ConfigurationType.Remote getRemote() + { + return getConfiguration().getRemote(); + } + + private ConfigurationType.Local getLocal() + { + return getConfiguration().getLocal(); + } + + private ConfigurationType getConfiguration() + { + return cacheConfig.getConfiguration(); + } + + private void checkInitializedState() + { + checkState( state == CacheState.INITIALIZED, "Cache is not initialized. Actual state: " + state ); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheSource.java b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheSource.java new file mode 100644 index 000000000000..b21944463632 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheSource.java @@ -0,0 +1,30 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * CacheSource + */ +public enum CacheSource +{ + LOCAL, + REMOTE, + BUILD +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheState.java b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheState.java new file mode 100644 index 000000000000..99267ed01e89 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheState.java @@ -0,0 +1,30 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * CacheState + */ +public enum CacheState +{ + NOT_INITIALIZED, + DISABLED, + INITIALIZED +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java b/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java new file mode 100644 index 000000000000..a2810ab86824 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java @@ -0,0 +1,219 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.caching.ProjectUtils; +import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.caching.jaxb.CompletedExecutionType; +import org.apache.maven.caching.jaxb.DigestItemType; +import org.apache.maven.caching.jaxb.PropertyValueType; +import org.apache.maven.caching.jaxb.TrackedPropertyType; +import org.apache.maven.model.Dependency; + +import javax.annotation.Nonnull; +import java.util.List; + +import static org.apache.maven.caching.checksum.KeyUtils.getArtifactKey; + +/** + * DtoUtils + */ +public class DtoUtils +{ + + public static String findPropertyValue( String propertyName, CompletedExecutionType completedExecution ) + { + final CompletedExecutionType.Configuration configuration = completedExecution.getConfiguration(); + if ( configuration == null ) + { + return null; + } + final List properties = configuration.getProperty(); + for ( PropertyValueType property : properties ) + { + if ( StringUtils.equals( propertyName, property.getName() ) ) + { + return property.getValue(); + } + } + return null; + } + + public static ArtifactType createDto( Artifact artifact ) + { + ArtifactType dto = new ArtifactType(); + dto.setArtifactId( artifact.getArtifactId() ); + dto.setGroupId( artifact.getGroupId() ); + dto.setVersion( artifact.getVersion() ); + dto.setClassifier( artifact.getClassifier() ); + dto.setType( artifact.getType() ); + dto.setScope( artifact.getScope() ); + dto.setFileName( ProjectUtils.normalizedName( artifact ) ); + return dto; + } + + public static DigestItemType createdDigestedByProjectChecksum( ArtifactType artifact, String projectChecksum ) + { + DigestItemType dit = new DigestItemType(); + dit.setType( "module" ); + dit.setHash( projectChecksum ); + dit.setFileChecksum( artifact.getFileHash() ); + dit.setValue( getArtifactKey( artifact ) ); + return dit; + } + + public static DigestItemType createDigestedFile( Artifact artifact, String fileHash ) + { + DigestItemType dit = new DigestItemType(); + dit.setType( "artifact" ); + dit.setHash( fileHash ); + dit.setFileChecksum( fileHash ); + dit.setValue( getArtifactKey( artifact ) ); + return dit; + } + + public static Dependency createDependency( ArtifactType artifact ) + { + final Dependency dependency = new Dependency(); + dependency.setArtifactId( artifact.getArtifactId() ); + dependency.setGroupId( artifact.getGroupId() ); + dependency.setVersion( artifact.getVersion() ); + dependency.setClassifier( artifact.getClassifier() ); + dependency.setType( artifact.getType() ); + dependency.setScope( artifact.getScope() ); + return dependency; + } + + public static Dependency createDependency( Artifact artifact ) + { + final Dependency dependency = new Dependency(); + dependency.setArtifactId( artifact.getArtifactId() ); + dependency.setGroupId( artifact.getGroupId() ); + dependency.setVersion( artifact.getVersion() ); + dependency.setType( artifact.getType() ); + dependency.setScope( artifact.getScope() ); + dependency.setClassifier( artifact.getClassifier() ); + return dependency; + } + + public static void addProperty( CompletedExecutionType execution, + String propertyName, + Object value, + String baseDirPath, + boolean tracked ) + { + if ( execution.getConfiguration() == null ) + { + execution.setConfiguration( new CompletedExecutionType.Configuration() ); + } + final PropertyValueType valueType = new PropertyValueType(); + valueType.setName( propertyName ); + if ( value != null && value.getClass().isArray() ) + { + value = ArrayUtils.toString( value ); + } + final String valueText = String.valueOf( value ); + valueType.setValue( StringUtils.remove( valueText, baseDirPath ) ); + valueType.setTracked( tracked ); + execution.getConfiguration().getProperty().add( valueType ); + } + + public static boolean containsAllProperties( + @Nonnull CompletedExecutionType cachedExecution, List trackedProperties ) + { + + if ( trackedProperties == null || trackedProperties.isEmpty() ) + { + return true; + } + + if ( !cachedExecution.isSetConfiguration() ) + { + return false; + } + + final List executionProperties = cachedExecution.getConfiguration().getProperty(); + for ( TrackedPropertyType trackedProperty : trackedProperties ) + { + if ( !contains( executionProperties, trackedProperty.getPropertyName() ) ) + { + return false; + } + } + return true; + } + + public static boolean contains( List executionProperties, String propertyName ) + { + for ( PropertyValueType executionProperty : executionProperties ) + { + if ( StringUtils.equals( executionProperty.getName(), propertyName ) ) + { + return true; + } + } + return false; + } + + public static ArtifactType copy( ArtifactType artifact ) + { + ArtifactType copy = new ArtifactType(); + if ( artifact.isSetArtifactId() ) + { + copy.setArtifactId( artifact.getArtifactId() ); + } + if ( artifact.isSetGroupId() ) + { + copy.setGroupId( artifact.getGroupId() ); + } + if ( artifact.isSetVersion() ) + { + copy.setVersion( artifact.getVersion() ); + } + if ( artifact.isSetType() ) + { + copy.setType( artifact.getType() ); + } + if ( artifact.isSetClassifier() ) + { + copy.setClassifier( artifact.getClassifier() ); + } + if ( artifact.isSetScope() ) + { + copy.setScope( artifact.getScope() ); + } + if ( artifact.isSetFileName() ) + { + copy.setFileName( artifact.getFileName() ); + } + if ( artifact.isSetFileHash() ) + { + copy.setFileHash( artifact.getFileHash() ); + } + if ( artifact.isSetFileSize() ) + { + copy.setFileSize( artifact.getFileSize() ); + } + return copy; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java b/maven-core/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java new file mode 100644 index 000000000000..6d332308cc07 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java @@ -0,0 +1,51 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; +import org.apache.maven.model.Dependency; +import org.codehaus.plexus.util.StringUtils; + +/** + * SentinelVersionStartegy + */ +public class SentinelVersionStartegy implements MultimoduleDiscoveryStrategy +{ + private final String version; + + public SentinelVersionStartegy( String version ) + { + this.version = version; + } + + @Override + public boolean isPartOfMultiModule( Dependency dependency ) + { + return StringUtils.equals( version, dependency.getVersion() ); + } + + @Override + public boolean isLookupRemoteMavenRepo( Artifact artifact ) + { + // TODO abfx specific - should be config driven + return !StringUtils.equals( version, artifact.getVersion() ); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java b/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java new file mode 100644 index 000000000000..658c9d0dd3b1 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java @@ -0,0 +1,145 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.caching.jaxb.BuildDiffType; +import org.apache.maven.caching.jaxb.BuildInfoType; +import org.apache.maven.caching.jaxb.CacheReportType; +import org.apache.maven.caching.jaxb.ObjectFactory; +import org.codehaus.plexus.component.annotations.Component; +import org.xml.sax.SAXException; + +import javax.xml.XMLConstants; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.InputStream; + +/** + * XmlService + */ +@Component( role = XmlService.class ) +public class XmlService +{ + + private final ObjectFactory objectFactory; + private final JAXBContext jaxbContext; + private final Schema schema; + + public XmlService() throws JAXBException, SAXException + { + objectFactory = new ObjectFactory(); + jaxbContext = JAXBContext.newInstance( "org.apache.maven.caching.jaxb", XmlService.class.getClassLoader() ); + + SchemaFactory sf = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI ); + final InputStream domainSchemaStream = getResourceAsStream( "cache-domain.xsd" ); + final Source domainSchema = new StreamSource( domainSchemaStream ); + final InputStream configSchemaStream = getResourceAsStream( "cache-config.xsd" ); + final Source configSchema = new StreamSource( configSchemaStream ); + schema = sf.newSchema( new Source[] {domainSchema, configSchema} ); + } + + public byte[] toBytes( BuildInfoType buildInfo ) + { + return serializeXml( objectFactory.createBuild( buildInfo ) ); + } + + public byte[] toBytes( BuildDiffType diff ) + { + return serializeXml( objectFactory.createDiff( diff ) ); + } + + public byte[] toBytes( CacheReportType cacheReportType ) + { + + return serializeXml( objectFactory.createReport( cacheReportType ) ); + } + + private byte[] serializeXml( JAXBElement element ) + { + try + { + Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); + jaxbMarshaller.setSchema( schema ); + // output pretty printed + jaxbMarshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true ); + jaxbMarshaller.setProperty( Marshaller.JAXB_ENCODING, "UTF-8" ); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + jaxbMarshaller.marshal( element, baos ); + return baos.toByteArray(); + } + catch ( Exception e ) + { + throw new RuntimeException( "Errors in jaxb serialization: " + e.toString(), e ); + } + } + + public T fromFile( Class clazz, File file ) + { + + try + { + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + unmarshaller.setSchema( schema ); + JAXBElement result = (JAXBElement) unmarshaller.unmarshal( file ); + return result.getValue(); + } + catch ( Exception e ) + { + throw new RuntimeException( "Errors in jaxb serialization: " + e.toString(), e ); + } + } + + public static InputStream getResourceAsStream( String name ) + { + ClassLoader cl = XmlService.class.getClassLoader(); + if ( cl == null ) + { + // A system class. + return ClassLoader.getSystemResourceAsStream( name ); + } + return cl.getResourceAsStream( name ); + } + + public T fromBytes( Class clazz, byte[] bytes ) + { + try + { + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + unmarshaller.setSchema( schema ); + JAXBElement result = (JAXBElement) unmarshaller.unmarshal( new ByteArrayInputStream( bytes ) ); + return result.getValue(); + + } + catch ( Exception e ) + { + throw new RuntimeException( "Errors in jaxb serialization: " + e.toString(), e ); + } + } +} diff --git a/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java b/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java index fb7a9f45064d..5a7db543f80b 100644 --- a/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java @@ -34,9 +34,11 @@ import org.apache.maven.MavenExecutionException; import org.apache.maven.ProjectCycleException; import org.apache.maven.artifact.ArtifactUtils; +import org.apache.maven.caching.checksum.KeyUtils; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ProjectDependencyGraph; +import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.model.building.DefaultModelProblem; import org.apache.maven.model.building.ModelProblem; @@ -56,6 +58,8 @@ import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.dag.CycleDetectedException; +import static org.apache.maven.artifact.versioning.VersionRange.createFromVersion; + /** * Builds the {@link ProjectDependencyGraph inter-dependencies graph} between projects in the reactor. */ @@ -64,6 +68,8 @@ public class DefaultGraphBuilder implements GraphBuilder { + public static final String PROJECT_VERSION_PROP_NAME = "org.maven.project.version"; + @Requirement private Logger logger; @@ -81,6 +87,11 @@ public Result build( MavenSession session ) { final List projects = getProjectsForMavenReactor( session ); validateProjects( projects ); + + if ( System.getProperties().containsKey( PROJECT_VERSION_PROP_NAME ) ) + { + overrideReactorVersions( projects, session ); + } result = reactorDependencyGraph( session, projects ); } @@ -100,6 +111,68 @@ public Result build( MavenSession session ) } } + private void overrideReactorVersions( List projects, MavenSession session ) + { + String injectedVersion = System.getProperty( PROJECT_VERSION_PROP_NAME ); + logger.info( "Overriding reactor projects version to " + injectedVersion ); + + Map reactorProjects = new HashMap<>( projects.size() ); + + for ( MavenProject project : projects ) + { + String projectKey = KeyUtils.getVersionlessProjectKey( project ); + logger.debug( + "[" + projectKey + "] Overriding version from " + project.getVersion() + " to " + injectedVersion ); + reactorProjects.put( projectKey, project.getVersion() ); + project.setVersion( injectedVersion ); + project.getArtifact().setVersionRange( createFromVersion( injectedVersion ) ); + project.getArtifact().updateVersion( injectedVersion, session.getLocalRepository() ); + } + + for ( MavenProject project : projects ) + { + String projectKey = KeyUtils.getVersionlessProjectKey( project ); + MavenProject parent = project.getParent(); + String parentKey = KeyUtils.getVersionlessProjectKey( parent ); + String overriddenParentVersion = reactorProjects.get( parentKey ); + if ( overriddenParentVersion != null && overriddenParentVersion.equals( + project.getParentArtifact().getVersion() ) ) + { + logger.debug( + "[" + projectKey + "] Parent " + parentKey + " overriding artefact version from " + + parent.getVersion() + " to " + injectedVersion ); + project.getParentArtifact().setVersionRange( createFromVersion( injectedVersion ) ); + project.getParentArtifact().updateVersion( injectedVersion, session.getLocalRepository() ); + } + + for ( Dependency dependency : project.getDependencies() ) + { + String dependencyKey = KeyUtils.getVersionlessDependencyKey( dependency ); + String overriddenReactorVersion = reactorProjects.get( dependencyKey ); + if ( overriddenReactorVersion != null && overriddenReactorVersion.equals( dependency.getVersion() ) ) + { + logger.debug( + "[" + projectKey + "] Dependency " + dependencyKey + " overriding version from " + + dependency.getVersion() + " to " + injectedVersion ); + dependency.setVersion( injectedVersion ); + } + } + + for ( Dependency dependency : project.getDependencyManagement().getDependencies() ) + { + String dependencyKey = KeyUtils.getVersionlessDependencyKey( dependency ); + String overriddenReactorVersion = reactorProjects.get( dependencyKey ); + if ( overriddenReactorVersion != null && overriddenReactorVersion.equals( dependency.getVersion() ) ) + { + logger.debug( + "[" + projectKey + "] Dependency management " + dependencyKey + + " overriding version from " + dependency.getVersion() + " to " + injectedVersion ); + dependency.setVersion( injectedVersion ); + } + } + } + } + private Result sessionDependencyGraph( final MavenSession session ) throws CycleDetectedException, DuplicateProjectException { diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DependencyContext.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DependencyContext.java index 7ee499f4b1a0..41004bdb118c 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DependencyContext.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DependencyContext.java @@ -31,13 +31,13 @@ * Context of dependency artifacts for a particular project. *

    * NOTE: This class is not part of any public api and can be changed or deleted without prior notice. - * + * * @since 3.0 * @author Benjamin Bentmann * @author Kristian Rosenvold (class extract only) */ // TODO From a concurrency perspective, this class is not good. The combination of mutable/immutable state is not nice -public class DependencyContext +public class DependencyContext implements IDependencyContext { private static final Collection UNRESOLVED = Arrays.asList(); @@ -66,46 +66,53 @@ public DependencyContext( MavenProject project, Collection scopesToColle scopesToResolveForAggregatedProjects = Collections.synchronizedSet( new TreeSet() ); } + @Override public MavenProject getProject() { return project; } + @Override public Collection getScopesToCollectForCurrentProject() { return scopesToCollectForCurrentProject; } + @Override public Collection getScopesToResolveForCurrentProject() { return scopesToResolveForCurrentProject; } + @Override public Collection getScopesToCollectForAggregatedProjects() { return scopesToCollectForAggregatedProjects; } + @Override public Collection getScopesToResolveForAggregatedProjects() { return scopesToResolveForAggregatedProjects; } + @Override public boolean isResolutionRequiredForCurrentProject() { - return lastDependencyArtifacts != project.getDependencyArtifacts() || ( lastDependencyArtifacts != null - && lastDependencyArtifactCount != lastDependencyArtifacts.size() ); + return lastDependencyArtifacts != project.getDependencyArtifacts() + || ( lastDependencyArtifacts != null && lastDependencyArtifactCount != lastDependencyArtifacts.size() ); } + @Override public boolean isResolutionRequiredForAggregatedProjects( Collection scopesToCollect, Collection scopesToResolve ) { - boolean required = - scopesToCollectForAggregatedProjects.addAll( scopesToCollect ) - || scopesToResolveForAggregatedProjects.addAll( scopesToResolve ); + boolean required = scopesToCollectForAggregatedProjects.addAll( + scopesToCollect ) || scopesToResolveForAggregatedProjects.addAll( scopesToResolve ); return required; } + @Override public void synchronizeWithProjectState() { lastDependencyArtifacts = project.getDependencyArtifacts(); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/IDependencyContext.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/IDependencyContext.java new file mode 100644 index 000000000000..1f81561b1c7f --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/IDependencyContext.java @@ -0,0 +1,47 @@ +package org.apache.maven.lifecycle.internal; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.project.MavenProject; + +import java.util.Collection; + +/** + * IDependencyContext + */ +public interface IDependencyContext +{ + MavenProject getProject(); + + Collection getScopesToCollectForCurrentProject(); + + Collection getScopesToResolveForCurrentProject(); + + Collection getScopesToCollectForAggregatedProjects(); + + Collection getScopesToResolveForAggregatedProjects(); + + boolean isResolutionRequiredForCurrentProject(); + + boolean isResolutionRequiredForAggregatedProjects( Collection scopesToCollect, + Collection scopesToResolve ); + + void synchronizeWithProjectState(); +} diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java index b78f54dc42f3..59f384983d9e 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java @@ -22,13 +22,23 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter; +import org.apache.maven.caching.CacheController; +import org.apache.maven.caching.CacheResult; +import org.apache.maven.caching.MojoExecutionManager; +import org.apache.maven.caching.MojoParametersListener; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.CacheState; import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.MojoExecutionEvent; +import org.apache.maven.execution.MojoExecutionListener; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.MissingProjectException; import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MavenPluginManager; import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.MojoExecution.Source; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.PluginConfigurationException; @@ -38,6 +48,7 @@ import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; import java.util.ArrayList; @@ -48,6 +59,13 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.apache.maven.caching.ProjectUtils.isLaterPhase; +import static org.apache.maven.caching.checksum.KeyUtils.getVersionlessProjectKey; +import static org.apache.maven.caching.xml.CacheState.DISABLED; +import static org.apache.maven.caching.xml.CacheState.INITIALIZED; + /** *

    @@ -64,6 +82,9 @@ public class MojoExecutor { + @Requirement + private Logger logger; + @Requirement private BuildPluginManager pluginManager; @@ -76,6 +97,15 @@ public class MojoExecutor @Requirement private ExecutionEventCatapult eventCatapult; + @Requirement + private CacheController cacheController; + + @Requirement + private CacheConfig cacheConfig; + + @Requirement( role = MojoExecutionListener.class, hint = "MojoParametersListener" ) + private MojoParametersListener mojoListener; + public MojoExecutor() { } @@ -120,7 +150,7 @@ else if ( Artifact.SCOPE_RUNTIME.equals( classpath ) ) else if ( Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals( classpath ) ) { scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED, - Artifact.SCOPE_RUNTIME ); + Artifact.SCOPE_RUNTIME ); } else if ( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals( classpath ) ) { @@ -129,37 +159,215 @@ else if ( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals( classpath ) ) else if ( Artifact.SCOPE_TEST.equals( classpath ) ) { scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED, - Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST ); + Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST ); } } return Collections.unmodifiableCollection( scopes ); } public void execute( MavenSession session, List mojoExecutions, ProjectIndex projectIndex ) - throws LifecycleExecutionException - + throws LifecycleExecutionException { DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); + final MavenProject project = session.getCurrentProject(); + final Source source = getSource( mojoExecutions ); + + // execute clean bound goals before restoring to not interfere/slowdown clean + CacheState cacheState = DISABLED; + CacheResult result = CacheResult.empty(); + if ( source == Source.LIFECYCLE ) + { + List cleanPhase = getCleanPhase( mojoExecutions ); + for ( MojoExecution mojoExecution : cleanPhase ) + { + execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); + } + cacheState = cacheConfig.initialize( project, session ); + if ( cacheState == INITIALIZED ) + { + result = cacheController.findCachedBuild( session, project, projectIndex, mojoExecutions ); + } + } + + boolean restorable = result.isSuccess() || result.isPartialSuccess(); + boolean restored = result.isSuccess(); // if partially restored need to save increment + if ( restorable ) + { + restored &= restoreProject( result, mojoExecutions, projectIndex, dependencyContext, phaseRecorder ); + } + else + { + for ( MojoExecution mojoExecution : mojoExecutions ) + { + if ( source == Source.CLI || isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) + { + execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); + } + } + } + + if ( cacheState == INITIALIZED && ( !restorable || !restored ) ) + { + final Map executionEvents = mojoListener.getProjectExecutions( project ); + cacheController.save( result, mojoExecutions, executionEvents ); + } + + if ( cacheConfig.isFailFast() && !result.isSuccess() ) + { + throw new LifecycleExecutionException( + "Failed to restore project[" + getVersionlessProjectKey( project ) + "] from cache, failing build.", + project ); + } + } + + private Source getSource( List mojoExecutions ) + { + if ( mojoExecutions == null || mojoExecutions.isEmpty() ) + { + return null; + } for ( MojoExecution mojoExecution : mojoExecutions ) + { + if ( mojoExecution.getSource() == Source.CLI ) + { + return Source.CLI; + } + } + return Source.LIFECYCLE; + } + + private boolean restoreProject( CacheResult cacheResult, + List mojoExecutions, + ProjectIndex projectIndex, + DependencyContext dependencyContext, + PhaseRecorder phaseRecorder ) throws LifecycleExecutionException + { + + final BuildInfo buildInfo = cacheResult.getBuildInfo(); + final MavenProject project = cacheResult.getContext().getProject(); + final MavenSession session = cacheResult.getContext().getSession(); + final List cachedSegment = buildInfo.getCachedSegment( mojoExecutions ); + + boolean restored = cacheController.restoreProjectArtifacts( cacheResult ); + if ( !restored ) + { + logger.info( + "[CACHE][" + project.getArtifactId() + + "] Cannot restore project artifacts, continuing with non cached build" ); + return false; + } + + for ( MojoExecution cacheCandidate : cachedSegment ) + { + + if ( cacheController.isForcedExecution( project, cacheCandidate ) ) + { + logger.info( + "[CACHE][" + project.getArtifactId() + "] Mojo execution is forced by project property: " + + cacheCandidate.getMojoDescriptor().getFullGoalName() ); + execute( session, cacheCandidate, projectIndex, dependencyContext, phaseRecorder ); + } + else + { + restored = verifyCacheConsistency( cacheCandidate, buildInfo, project, session, projectIndex, + dependencyContext, phaseRecorder ); + if ( !restored ) + { + break; + } + } + } + + if ( !restored ) + { + // cleanup partial state + project.getArtifact().setFile( null ); + project.getArtifact().setResolved( false ); + project.getAttachedArtifacts().clear(); + mojoListener.remove( project ); + // build as usual + for ( MojoExecution mojoExecution : cachedSegment ) + { + execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); + } + } + + for ( MojoExecution mojoExecution : buildInfo.getPostCachedSegment( mojoExecutions ) ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } + return restored; + } + + private boolean verifyCacheConsistency( MojoExecution cacheCandidate, + BuildInfo cachedBuildInfo, + MavenProject project, + MavenSession session, + ProjectIndex projectIndex, + DependencyContext dependencyContext, + PhaseRecorder phaseRecorder ) throws LifecycleExecutionException + { + + AtomicBoolean consistent = new AtomicBoolean( true ); + final MojoExecutionManager mojoChecker = new MojoExecutionManager( project, cacheController, cachedBuildInfo, + consistent, logger, cacheConfig ); + + if ( mojoChecker.needCheck( cacheCandidate, session ) ) + { + try + { + // actual execution will not happen (if not forced). decision delayed to execution time + // then all properties are resolved. + cacheCandidate.setMojoExecutionManager( mojoChecker ); + IDependencyContext nop = new NoResolutionContext( dependencyContext ); + execute( session, cacheCandidate, projectIndex, nop, phaseRecorder ); + } + finally + { + cacheCandidate.setMojoExecutionManager( null ); + } + } + else + { + logger.info( + "[CACHE][" + project.getArtifactId() + "] Skipping plugin execution (cached): " + + cacheCandidate.getMojoDescriptor().getFullGoalName() ); + } + + return consistent.get(); + } + + private List getCleanPhase( List mojoExecutions ) + { + List list = new ArrayList<>(); + for ( MojoExecution mojoExecution : mojoExecutions ) + { + if ( isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) + { + break; + } + list.add( mojoExecution ); + } + return list; } - public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, - DependencyContext dependencyContext, PhaseRecorder phaseRecorder ) - throws LifecycleExecutionException + public void execute( MavenSession session, + MojoExecution mojoExecution, + ProjectIndex projectIndex, + IDependencyContext dependencyContext, + PhaseRecorder phaseRecorder ) throws LifecycleExecutionException { execute( session, mojoExecution, projectIndex, dependencyContext ); phaseRecorder.observeExecution( mojoExecution ); } - private void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, - DependencyContext dependencyContext ) - throws LifecycleExecutionException + private void execute( MavenSession session, + MojoExecution mojoExecution, + ProjectIndex projectIndex, + IDependencyContext dependencyContext ) throws LifecycleExecutionException { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); @@ -175,18 +383,18 @@ private void execute( MavenSession session, MojoExecution mojoExecution, Project if ( mojoDescriptor.isProjectRequired() && !session.getRequest().isProjectPresent() ) { Throwable cause = new MissingProjectException( - "Goal requires a project to execute" + " but there is no POM in this directory (" - + session.getExecutionRootDirectory() + ")." - + " Please verify you invoked Maven from the correct directory." ); + "Goal requires a project to execute" + " but there is no POM in this directory (" + + session.getExecutionRootDirectory() + ")." + + " Please verify you invoked Maven from the correct directory." ); throw new LifecycleExecutionException( mojoExecution, null, cause ); } if ( mojoDescriptor.isOnlineRequired() && session.isOffline() ) { - if ( MojoExecution.Source.CLI.equals( mojoExecution.getSource() ) ) + if ( Source.CLI.equals( mojoExecution.getSource() ) ) { Throwable cause = new IllegalStateException( - "Goal requires online mode for execution" + " but Maven is currently offline." ); + "Goal requires online mode for execution" + " but Maven is currently offline." ); throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), cause ); } else @@ -209,8 +417,10 @@ private void execute( MavenSession session, MojoExecution mojoExecution, Project { pluginManager.executeMojo( session, mojoExecution ); } - catch ( MojoFailureException | PluginManagerException | PluginConfigurationException - | MojoExecutionException e ) + catch ( MojoFailureException + | PluginManagerException + | PluginConfigurationException + | MojoExecutionException e ) { throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), e ); } @@ -232,9 +442,9 @@ private void execute( MavenSession session, MojoExecution mojoExecution, Project } } - public void ensureDependenciesAreResolved( MojoDescriptor mojoDescriptor, MavenSession session, - DependencyContext dependencyContext ) - throws LifecycleExecutionException + public void ensureDependenciesAreResolved( MojoDescriptor mojoDescriptor, + MavenSession session, + IDependencyContext dependencyContext ) throws LifecycleExecutionException { MavenProject project = dependencyContext.getProject(); @@ -246,7 +456,7 @@ public void ensureDependenciesAreResolved( MojoDescriptor mojoDescriptor, MavenS Collection scopesToResolve = dependencyContext.getScopesToResolveForCurrentProject(); lifeCycleDependencyResolver.resolveProjectDependencies( project, scopesToCollect, scopesToResolve, session, - aggregating, Collections.emptySet() ); + aggregating, Collections.emptySet() ); dependencyContext.synchronizeWithProjectState(); } @@ -263,17 +473,15 @@ public void ensureDependenciesAreResolved( MojoDescriptor mojoDescriptor, MavenS if ( aggregatedProject != project ) { lifeCycleDependencyResolver.resolveProjectDependencies( aggregatedProject, scopesToCollect, - scopesToResolve, session, aggregating, - Collections.emptySet() ); + scopesToResolve, session, aggregating, Collections.emptySet() ); } } } } ArtifactFilter artifactFilter = getArtifactFilter( mojoDescriptor ); - List projectsToResolve = - LifecycleDependencyResolver.getProjects( session.getCurrentProject(), session, - mojoDescriptor.isAggregator() ); + List projectsToResolve = LifecycleDependencyResolver.getProjects( session.getCurrentProject(), + session, mojoDescriptor.isAggregator() ); for ( MavenProject projectToResolve : projectsToResolve ) { projectToResolve.setArtifactFilter( artifactFilter ); @@ -305,9 +513,9 @@ private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor ) } } - public List executeForkedExecutions( MojoExecution mojoExecution, MavenSession session, - ProjectIndex projectIndex ) - throws LifecycleExecutionException + public List executeForkedExecutions( MojoExecution mojoExecution, + MavenSession session, + ProjectIndex projectIndex ) throws LifecycleExecutionException { List forkedProjects = Collections.emptyList(); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/NoResolutionContext.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/NoResolutionContext.java new file mode 100644 index 000000000000..e5ba54545ab0 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/NoResolutionContext.java @@ -0,0 +1,88 @@ +package org.apache.maven.lifecycle.internal; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +import org.apache.maven.project.MavenProject; + +import java.util.Collection; + +/** + * NoResolutionContext + */ +public class NoResolutionContext implements IDependencyContext +{ + private final DependencyContext delegate; + + public NoResolutionContext( DependencyContext delegate ) + { + this.delegate = delegate; + } + + @Override + public MavenProject getProject() + { + return delegate.getProject(); + } + + @Override + public Collection getScopesToCollectForCurrentProject() + { + return delegate.getScopesToCollectForCurrentProject(); + } + + @Override + public Collection getScopesToResolveForCurrentProject() + { + + return delegate.getScopesToResolveForCurrentProject(); + } + + @Override + public Collection getScopesToCollectForAggregatedProjects() + { + return delegate.getScopesToCollectForAggregatedProjects(); + } + + @Override + public Collection getScopesToResolveForAggregatedProjects() + { + return delegate.getScopesToCollectForAggregatedProjects(); + } + + @Override + public boolean isResolutionRequiredForCurrentProject() + { + return false; + } + + @Override + public boolean isResolutionRequiredForAggregatedProjects( Collection scopesToCollect, + Collection scopesToResolve ) + { + return false; + } + + @Override + public void synchronizeWithProjectState() + { + delegate.synchronizeWithProjectState(); + } +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java index 1a007424e760..e3b35ccf7182 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java @@ -44,8 +44,7 @@ * DefaultBuildPluginManager */ @Component( role = BuildPluginManager.class ) -public class DefaultBuildPluginManager - implements BuildPluginManager +public class DefaultBuildPluginManager implements BuildPluginManager { @Requirement @@ -74,8 +73,8 @@ public void setMojoExecutionListeners( final List listene * @param repositories * @param session * @return PluginDescriptor The component descriptor for the Maven plugin. - * @throws PluginNotFoundException The plugin could not be found in any repositories. - * @throws PluginResolutionException The plugin could be found but could not be resolved. + * @throws PluginNotFoundException The plugin could not be found in any repositories. + * @throws PluginResolutionException The plugin could be found but could not be resolved. * @throws InvalidPluginDescriptorException */ public PluginDescriptor loadPlugin( Plugin plugin, List repositories, @@ -134,7 +133,10 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) mojoExecutionListener.beforeMojoExecution( mojoExecutionEvent ); - mojo.execute(); + if ( mojoExecution.canRun( mojo, session ) ) + { + mojo.execute(); + } mojoExecutionListener.afterMojoExecutionSuccess( mojoExecutionEvent ); } @@ -150,20 +152,20 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) } catch ( PluginContainerException e ) { - mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo, - e ) ); + mojoExecutionListener.afterExecutionFailure( + new MojoExecutionEvent( session, project, mojoExecution, mojo, e ) ); throw new PluginExecutionException( mojoExecution, project, e ); } catch ( NoClassDefFoundError e ) { - mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo, - e ) ); + mojoExecutionListener.afterExecutionFailure( + new MojoExecutionEvent( session, project, mojoExecution, mojo, e ) ); ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); PrintStream ps = new PrintStream( os ); - ps.println( "A required class was missing while executing " + mojoDescriptor.getId() + ": " - + e.getMessage() ); + ps.println( + "A required class was missing while executing " + mojoDescriptor.getId() + ": " + e.getMessage() ); pluginRealm.display( ps ); Exception wrapper = new PluginContainerException( mojoDescriptor, pluginRealm, os.toString(), e ); @@ -172,8 +174,8 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) } catch ( LinkageError e ) { - mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo, - e ) ); + mojoExecutionListener.afterExecutionFailure( + new MojoExecutionEvent( session, project, mojoExecution, mojo, e ) ); ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); PrintStream ps = new PrintStream( os ); @@ -187,8 +189,8 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) } catch ( ClassCastException e ) { - mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo, - e ) ); + mojoExecutionListener.afterExecutionFailure( + new MojoExecutionEvent( session, project, mojoExecution, mojo, e ) ); ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); PrintStream ps = new PrintStream( os ); @@ -200,8 +202,8 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) } catch ( RuntimeException e ) { - mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo, - e ) ); + mojoExecutionListener.afterExecutionFailure( + new MojoExecutionEvent( session, project, mojoExecution, mojo, e ) ); throw e; } @@ -218,8 +220,8 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) } /** - * TODO pluginDescriptor classRealm and artifacts are set as a side effect of this - * call, which is not nice. + * TODO pluginDescriptor classRealm and artifacts are set as a side effect of this call, which is not nice. + * * @throws PluginResolutionException */ public ClassRealm getPluginRealm( MavenSession session, PluginDescriptor pluginDescriptor ) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MojoCheker.java b/maven-core/src/main/java/org/apache/maven/plugin/MojoCheker.java new file mode 100644 index 000000000000..c82064b78bbf --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/MojoCheker.java @@ -0,0 +1,38 @@ +package org.apache.maven.plugin; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.execution.MavenSession; + +/** + * MojoCheker + */ +public interface MojoCheker +{ + /** + * @return true if this execution needs to be checked + */ + boolean needCheck( MojoExecution mojoExecution, MavenSession session ); + + /** + * @return true if check passed and mojo could be run + */ + boolean check( MojoExecution mojoExecution, Mojo mojo, MavenSession session ); +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java index fa72c1866e4c..0cac2a7fba9e 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java @@ -19,14 +19,15 @@ * under the License. */ -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - +import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.codehaus.plexus.util.xml.Xpp3Dom; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + /** * MojoExecution */ @@ -41,8 +42,15 @@ public class MojoExecution private MojoDescriptor mojoDescriptor; + private MojoCheker mojoCheker; + private Xpp3Dom configuration; + public boolean canRun( Mojo mojo, MavenSession session ) + { + return mojoCheker == null || mojoCheker.check( this, mojo, session ); + } + /** * Describes the source of an execution. */ @@ -63,8 +71,8 @@ public enum Source private Source source = Source.LIFECYCLE; /** - * The phase may or may not have been bound to a phase but once the plan has been calculated we know what phase - * this mojo execution is going to run in. + * The phase may or may not have been bound to a phase but once the plan has been calculated we know what phase this + * mojo execution is going to run in. */ private String lifecyclePhase; @@ -237,4 +245,8 @@ public void setForkedExecutions( String projectKey, List forkedEx this.forkedExecutions.put( projectKey, forkedExecutions ); } + public void setMojoExecutionManager( MojoCheker mojoCheker ) + { + this.mojoCheker = mojoCheker; + } } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 7e18f1ef3ce2..b611758bf565 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -19,20 +19,6 @@ * under the License. */ -import java.io.File; -import java.io.IOException; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.InvalidArtifactRTException; @@ -76,6 +62,20 @@ import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResult; +import java.io.File; +import java.io.IOException; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + /** * DefaultProjectBuilder */ @@ -675,6 +675,7 @@ private void initProject( MavenProject project, Map projec project.setModel( model ); project.setOriginalModel( result.getRawModel() ); + project.setOriginalEffectiveModel( model.clone() ); project.setFile( model.getPomFile() ); initParent( project, projects, buildParentIfNotExisting, result, projectBuildingRequest ); @@ -791,7 +792,7 @@ private void initProject( MavenProject project, Map projec HashMap delegate; @Override - public Set> entrySet() + public Set> entrySet() { return Collections.unmodifiableSet( compute().entrySet() ); } diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index db0f4a90116f..ea15bda90a09 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -156,6 +156,8 @@ public class MavenProject private Model originalModel; + private Model originalEffectiveModel; + private Map pluginArtifactMap; private Set reportArtifacts; @@ -1048,6 +1050,16 @@ public Model getOriginalModel() return originalModel; } + public Model getOriginalEffectiveModel() + { + return originalEffectiveModel; + } + + public void setOriginalEffectiveModel( Model originalEffectiveModel ) + { + this.originalEffectiveModel = originalEffectiveModel; + } + public void setManagedVersionMap( Map map ) { managedVersionMap = map; diff --git a/maven-core/src/main/resources/cache-config-instance.xml b/maven-core/src/main/resources/cache-config-instance.xml new file mode 100644 index 000000000000..79f7422c24c4 --- /dev/null +++ b/maven-core/src/main/resources/cache-config-instance.xml @@ -0,0 +1,92 @@ + + + + + true + SHA-256 + true + + http://host:port + + + 3 + + + + + + + {*.java,*.groovy,*.yaml,*.svcd,*.proto,*assembly.xml,assembly*.xml,*logback.xml,*.vm,*.ini,*.jks,*.properties,*.sh,*.bat} + + src/ + pom.xml + + + + 111 + + + + + + + + 1 + 2 + + + + + + + + + .*-processes.*\.zip + + + + + + + aaa + + + install + + + deploy + + + deploy-local + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-core/src/main/resources/cache-config.xsd b/maven-core/src/main/resources/cache-config.xsd new file mode 100644 index 000000000000..1f5eb4eb9be6 --- /dev/null +++ b/maven-core/src/main/resources/cache-config.xsd @@ -0,0 +1,620 @@ + + + + + + + + + + + + + + + + Cached build metadata + + + + + + + + + + Configuration of major cache properties + + + + + + + Configuration for source code input files participating in checksum calculation + + + + + + + Configuration for output artifacts, it's needed if you want to explicitly include/exclude something from caching + + + + + + + Execution rules for plugins in cached mode. Defines which plugins should run always + + + + + + + + + + + + + + + + 64 bit XX family hashing. Fast, but higher probability of collisions + + + + + + + 64 bit XX family hashing, with usage of Memory Mapped Buffer + + + + + + + + + + + + + + Validate cache config and builds metadata against xsd. + + + + + + + Specifies how to identify belonging to a cached project then submodule is being build. + + + + + + + + Any project dependency this this version will be considered cache eligible and will + be processed cache aware + + + + + + + + + + + + + address of remote cache + + + + + + + + + Save output to remote cache. Recommended to enable on CI agents only. + + + + + + + + + + + + Directory name in build output directory to attach to cached artifacts + + + + + + + + + + + + + Maximum number of cached build per artifact in local cache. First created cache (the + oldest) is + evicted if breached. + + + + + + + + + + + + + Causes file hash is saved in build metadata + + + + + + + Causes effective pom info is saved in build metadata + + + + + + + + + + + + + + + Global input calculation rules applicable to all projects and plugins in the build + + + + + + + Plugin specific input calculation rules + + + + + + + + + + + + + + Effective pom calculation rules + + + + + + + + Plugin configuration property should be excluded from effective pom + calculation + + + + + + + + + + Specifies plugin level rules of configuration processing in search of referenced source + files + + + + + + + Specifies execution specific configuration processing in search of referenced source + files + + + + + + + + + + + + + + + Specifies rules of configuration processing in search of referenced source files + + + + + + + + ignore parent config or inherit/merge + + + + + + + + + Common attributes for scanning paths + + + + + + Should walk directory specified in property recursively or not + + + + + + + Glob to apply when scanning dir denoted by this property + + + + + + + + + + + + + + + + + + + Forces cache to treat property value as input and include in calculation. If set, only included + properties will be takein in calculation (whitelist) + + + + + + + + Tag to exclude when scanning plugin configuration for input files (blacklist) + + + + + + + Additional processing rules for non-blacklisted tags + + + + + + + + + + Ignore parent settings or inherit and merge + + + + + + + + + + + Scan directory accordingly to cache implementation + + + + + + + Skip directory + + + + + + + + + + + + + + Patterns to exclude output artifacts applicable to all projects in the build + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Specify property which should be reconciled against running build + + + + + + + Specify property which should be logged to build metadata for exploration + + + + + + + Specify property which should not be logged + + + + + + + + Controls if all plugin properties to be logged (true is default). All the properties logged + with respect to log/nolog children: + * true: logged all if no blacklists () and whitelists () specified on plugin + level + * false: logged only tracked and included by whitelists () on plugin level + + + + + + + + + + + + + Specify which plugin should run always if present in build regardless of cached status + + + + + + + Specify which executions/plugins/goals do not affect generated artifacts and do not affect build correctness. + If cached build lacks of ignorable executions only, it still could be reused. + Typically case is then cached build is produced with 'verify' and you locally you run 'install'. + Strictly speaking these are different builds but in most of cases you want this difference to be ignored + + + + + + + Specify which plugin should run always if present in build regardless of cached status + + + + + + + + Reconciliation rules for plugin properties which might be affected by command line + flags, etc + + + + + + + + Controls if all plugin properties to be logged (true is default). All the properties + logged with respect to children: + * logAll on plugin level overrides global value + * true: logged all if no blacklists () and whitelists () specified on + plugin level + * false: logged only tracked and included by whitelists () on plugin level + + + + + + + + + + + + + + + Specify which plugin should run always if present in build regardless of cached status + + + + + + + Specify which executions should run always if present in build regardless of cached status + + + + + + + Specify which goals should run always if present in build regardless of cached status + + + + + + + + + + + + + + Goals identification + + + + + + + + + + + + + + + + + + + + + + + + + Executions ids list with plugin identifier + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Specify which value denotes skipped execution in plugin config. + If active build skips execution (property set to skipValue) cache will allow such + discrepancy. + + + + + + + Manual value for reconciliation. Required to reconcile runtime only properties + + + + + + + + diff --git a/maven-core/src/main/resources/cache-domain-instance.xml b/maven-core/src/main/resources/cache-domain-instance.xml new file mode 100644 index 000000000000..1c859de7f831 --- /dev/null +++ b/maven-core/src/main/resources/cache-domain-instance.xml @@ -0,0 +1,44 @@ + + + v3 + 1980-03-23T10:20:15 + my-server.com + SHA-256 + + clean + verify + + + com.my.shared + my-server + jar + my-server.jar + hashvalue + 123456 + + + + com.my.shared + my-server + java-source + sources + my-server-sources.jar + + + + + default:check:verify:duplicate-finder-maven-plugin:org.basepom.maven:1.3.0 + org.basepom.mojo.duplicatefinder.DuplicateFinderMojo + + true + false + + + + + 0136171ac2c9d9b066805bd09904a25318cfb2037189b20c48e79b20b63b81ed + src/main/conf/my-context.xml + + diff --git a/maven-core/src/main/resources/cache-domain.xsd b/maven-core/src/main/resources/cache-domain.xsd new file mode 100644 index 000000000000..48446ca7370c --- /dev/null +++ b/maven-core/src/main/resources/cache-domain.xsd @@ -0,0 +1,167 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java b/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java new file mode 100644 index 000000000000..6c9b14c418aa --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java @@ -0,0 +1,113 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +import com.google.common.collect.Lists; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.caching.hash.HashFactory; +import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.caching.jaxb.BuildInfoType; +import org.apache.maven.caching.jaxb.CompletedExecutionType; +import org.apache.maven.caching.jaxb.DigestItemType; +import org.apache.maven.caching.jaxb.ProjectsInputInfoType; +import org.apache.maven.caching.jaxb.PropertyValueType; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.XmlService; + +import javax.xml.datatype.DatatypeFactory; +import java.io.File; +import java.math.BigInteger; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.GregorianCalendar; + +import static org.apache.maven.caching.xml.BuildInfo.createGoals; + +public class BuildInfoTest { + + // @Test + public void name() throws Exception { + + XmlService xmlService = new XmlService(); + + ProjectsInputInfoType main = new ProjectsInputInfoType(); + main.setChecksum("dependencyChecksum"); + main.getItem().add(createItem("pom", "4.0.0", "hash1")); + main.getItem().add(createItem("file", Paths.get(".").toString(), "hash2")); + + ArtifactType artifact = new ArtifactType(); + artifact.setGroupId("g"); + artifact.setArtifactId("a"); + artifact.setType("t"); + artifact.setClassifier("c"); + artifact.setScope("s"); + artifact.setFileName("f"); + artifact.setFileSize(BigInteger.valueOf(123456)); + artifact.setFileHash("456L"); + + BuildInfoType buildInfo = new BuildInfoType(); + buildInfo.setCacheImplementationVersion("cacheImplementationVersion"); + buildInfo.setBuildServer("server"); + buildInfo.setBuildTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar())); + buildInfo.setArtifact(artifact); + buildInfo.setHashFunction("SHA-256"); + buildInfo.setGoals(createGoals(Lists.newArrayList("install"))); + final Artifact attachedArtifact = new DefaultArtifact("ag", "aa", "av", "as", "at", "ac", new DefaultArtifactHandler()); + buildInfo.setAttachedArtifacts(BuildInfo.createAttachedArtifacts(Lists.newArrayList(attachedArtifact), HashFactory.XX.createAlgorithm())); + buildInfo.setProjectsInputInfo(main); + buildInfo.setExecutions(createExecutions()); + + byte[] bytes = xmlService.toBytes(buildInfo); + System.out.println(new String(bytes, StandardCharsets.UTF_8)); + Path tempFilePath = Files.createTempFile("test", "test"); + File file = tempFilePath.toFile(); + file.deleteOnExit(); + Files.write(tempFilePath, bytes); + + BuildInfoType buildInfo1 = xmlService.fromFile(BuildInfoType.class, file); + System.out.println(buildInfo1); + } + + private BuildInfoType.Executions createExecutions() { + CompletedExecutionType execution = new CompletedExecutionType(); + execution.setExecutionKey("execkey"); + execution.setConfiguration(new CompletedExecutionType.Configuration()); + PropertyValueType property = new PropertyValueType(); + property.setValue("value"); + property.setName("key"); + execution.getConfiguration().getProperty().add(property); + BuildInfoType.Executions executions = new BuildInfoType.Executions(); + executions.getExecution().add(execution); + return executions; + } + + private DigestItemType createItem(String pom, String s, String hash1) { + final DigestItemType d1 = new DigestItemType(); + d1.setType(pom); + d1.setHash(s); + d1.setValue(hash1); + return d1; + } +} \ No newline at end of file diff --git a/maven-core/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java b/maven-core/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java new file mode 100644 index 000000000000..d420134e6746 --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java @@ -0,0 +1,85 @@ +package org.apache.maven.caching.checksum; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class MavenProjectInputTest { + + private static final String GLOB = "{*-pom.xml}"; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testAddInputsRelativePath() { +// MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), Paths.get("src\\test\\resources\\org"), GLOB); +// ArrayList files = new ArrayList<>(); +// inputs.listDirOrFile("../../resources", inputs.dirGlob, files, new HashSet()); +// assertEquals(4, files.size()); + } + + @Test + public void testAddInputsAbsolutePath() { +// Path baseDirPath = Paths.get("src\\test\\resources\\org"); +// MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), baseDirPath, GLOB); +// ArrayList files = new ArrayList<>(); +// Path candidatePath = baseDirPath.resolve("../../resources").normalize().toAbsolutePath(); +// inputs.listDirOrFile(candidatePath.toString(), inputs.dirGlob, files, new HashSet()); +// assertEquals(4, files.size()); // pom is filtered out by hardcoded if + } + + @Test + public void testGlobInput() { +// Path baseDirPath = Paths.get("src\\test\\resources"); +// MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), baseDirPath, GLOB); +// ArrayList files = new ArrayList<>(); +// inputs.tryAddInputs("*.java", files, new HashSet()); +// assertEquals(0, files.size()); // pom is filtered out by hardcoded if + } + + @Test + public void testGetDirectoryFiles() { + List directoryFiles = new ArrayList<>(); + MavenProjectInput.walkDirectoryFiles(Paths.get("src/test/resources"), directoryFiles, MavenProjectInput.DEFAULT_GLOB); + assertEquals(0, directoryFiles.size()); // pom is filtered out by hardcoded if + } + + @Test + public void testGetDirectoryFiles2() { + List directoryFiles = new ArrayList<>(); + MavenProjectInput.walkDirectoryFiles(Paths.get("src/test/resources"), directoryFiles, GLOB); + assertEquals(4, directoryFiles.size()); // pom is filtered out by hardcoded if + } +} diff --git a/maven-core/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java b/maven-core/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java new file mode 100644 index 000000000000..9cf5bb405f91 --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java @@ -0,0 +1,72 @@ +package org.apache.maven.caching.checksum; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.caching.hash.HashAlgorithm; +import org.apache.maven.caching.hash.HashChecksum; +import org.junit.Test; + +import java.nio.charset.StandardCharsets; + +import static org.apache.maven.caching.hash.HashFactory.SHA256; +import static org.junit.Assert.assertEquals; + +public class SHAHashTest { + private static final byte[] HELLO_ARRAY = "hello".getBytes(StandardCharsets.UTF_8); + private static final byte[] WORLD_ARRAY = "world".getBytes(StandardCharsets.UTF_8); + private static final String EMPTY_HASH = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; + private static final String HELLO_HASH = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"; + private static final String WORLD_HASH = "486ea46224d1bb4fb680f34f7c9ad96a8f24ec88be73ea8e5a6c65260e9cb8a7"; + private static final String HELLO_CHECKSUM = "9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50"; + private static final String WORLD_CHECKSUM = "63e5c163c81ee9a3ed99d365ff963ecea340cc455deeac7c4b63ac75b9cf4706"; + private static final String FULL_CHECKSUM = "7305db9b2abccd706c256db3d97e5ff48d677cfe4d3a5904afb7da0e3950e1e2"; + + private static final HashAlgorithm ALGORITHM = SHA256.createAlgorithm(); + private static final HashChecksum CHECKSUM = SHA256.createChecksum(0); + + @Test + public void testEmptyArray() { + byte[] emptyArray = new byte[0]; + String hash = ALGORITHM.hash(emptyArray); + assertEquals(EMPTY_HASH, hash); + } + + @Test + public void testSimpleHash() { + String helloHash = ALGORITHM.hash(HELLO_ARRAY); + assertEquals(HELLO_HASH, helloHash); + + String worldHash = ALGORITHM.hash(WORLD_ARRAY); + assertEquals(WORLD_HASH, worldHash); + } + + @Test + public void testSimpleChecksum() { + assertEquals(HELLO_HASH, CHECKSUM.update(HELLO_ARRAY)); + assertEquals(HELLO_CHECKSUM, CHECKSUM.digest()); + + assertEquals(WORLD_HASH, CHECKSUM.update(WORLD_ARRAY)); + assertEquals(WORLD_CHECKSUM, CHECKSUM.digest()); + + assertEquals(HELLO_HASH, CHECKSUM.update(HELLO_ARRAY)); + assertEquals(WORLD_HASH, CHECKSUM.update(WORLD_ARRAY)); + assertEquals(FULL_CHECKSUM, CHECKSUM.digest()); + } +} diff --git a/maven-core/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java b/maven-core/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java new file mode 100644 index 000000000000..3a1a46ecf492 --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java @@ -0,0 +1,132 @@ +package org.apache.maven.caching.checksum; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.caching.hash.HashAlgorithm; +import org.apache.maven.caching.hash.HashChecksum; +import org.junit.Test; + +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; + +import static org.apache.maven.caching.hash.HashFactory.XX; +import static org.apache.maven.caching.hash.HashFactory.XXMM; +import static org.junit.Assert.assertEquals; + +public class XXHashTest { + private static final byte[] HELLO_ARRAY = "hello".getBytes(StandardCharsets.UTF_8); + private static final byte[] WORLD_ARRAY = "world".getBytes(StandardCharsets.UTF_8); + private static final long HELLO_LONG = 2794345569481354659L; + private static final long WORLD_LONG = -1767385783675760145L; + private static final String EMPTY_HASH = "ef46db3751d8e999"; + private static final String HELLO_HASH = "26c7827d889f6da3"; + private static final String WORLD_HASH = "e778fbfe66ee51ef"; + private static final String HELLO_CHECKSUM = "c07c10338a825a5d"; + private static final String WORLD_CHECKSUM = "cb21505d7a714523"; + private static final String FULL_CHECKSUM = "b8ca8fa824d335e9"; + + private static final HashAlgorithm ALGORITHM = XX.createAlgorithm(); + + @Test + public void testEmptyArray() { + byte[] emptyArray = new byte[0]; + String hash = ALGORITHM.hash(emptyArray); + assertEquals(EMPTY_HASH, hash); + } + + @Test + public void testSimpleHash() { + String helloHash = ALGORITHM.hash(HELLO_ARRAY); + assertEquals(HELLO_HASH, helloHash); + + String worldHash = ALGORITHM.hash(WORLD_ARRAY); + assertEquals(WORLD_HASH, worldHash); + } + + @Test + public void testSimpleChecksum() { + String helloChecksum = ALGORITHM.hash(longToBytes(1, HELLO_LONG)); + assertEquals(HELLO_CHECKSUM, helloChecksum); + + String worldChecksum = ALGORITHM.hash(longToBytes(1, WORLD_LONG)); + assertEquals(WORLD_CHECKSUM, worldChecksum); + + String checksum = ALGORITHM.hash(longToBytes(2, HELLO_LONG, WORLD_LONG)); + assertEquals(FULL_CHECKSUM, checksum); + } + + @Test + public void testEmptyBuffer() { + assertEmptyBuffer(XX.createChecksum(0)); + assertEmptyBuffer(XXMM.createChecksum(0)); + } + + @Test + public void testSingleHash() { + assertSingleHash(XX.createChecksum(1)); + assertSingleHash(XXMM.createChecksum(1)); + } + + @Test + public void testSingleChecksum() { + assertSingleChecksum(XX.createChecksum(1)); + assertSingleChecksum(XXMM.createChecksum(1)); + } + + @Test + public void testNotFullChecksum() { + assertSingleChecksum(XX.createChecksum(2)); + assertSingleChecksum(XXMM.createChecksum(2)); + } + + @Test + public void testFullChecksum() { + assertFullChecksum(XX.createChecksum(2)); + assertFullChecksum(XXMM.createChecksum(2)); + } + + private void assertEmptyBuffer(HashChecksum checksum) { + assertEquals(EMPTY_HASH, checksum.digest()); + } + + private void assertSingleHash(HashChecksum checksum) { + assertEquals(HELLO_HASH, checksum.update(HELLO_ARRAY)); + assertEquals(HELLO_CHECKSUM, checksum.digest()); + } + + private void assertSingleChecksum(HashChecksum checksum) { + assertEquals(HELLO_HASH, checksum.update(HELLO_HASH)); + assertEquals(HELLO_CHECKSUM, checksum.digest()); + } + + private void assertFullChecksum(HashChecksum checksum) { + assertEquals(HELLO_HASH, checksum.update(HELLO_HASH)); + assertEquals(WORLD_HASH, checksum.update(WORLD_HASH)); + assertEquals(FULL_CHECKSUM, checksum.digest()); + } + + private byte[] longToBytes(int size, long... values) { + final ByteBuffer buffer = ByteBuffer.allocate(size * Long.SIZE / Byte.SIZE); + for (long value : values) { + buffer.putLong(value); + } + return buffer.array(); + } +} diff --git a/maven-core/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java b/maven-core/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java new file mode 100644 index 000000000000..e9615f493e20 --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java @@ -0,0 +1,50 @@ +package org.apache.maven.caching.hash; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +public class HexUtilsTest { + + @Test + public void testEncodeToHex() { + //array length = 8 left padded with zeroes + assertEquals("0", HexUtils.encode(new byte[8])); + assertEquals("0", HexUtils.encode(new byte[1])); + + assertEquals("a", HexUtils.encode(new byte[]{10})); + assertEquals("a", HexUtils.encode(new byte[]{0, 0, 0, 0, 0, 0, 0, 10})); + + assertEquals("100", HexUtils.encode(new byte[]{1, 0})); + assertEquals("101", HexUtils.encode(new byte[]{0, 0, 0, 0, 0, 0, 1, 1})); + } + + @Test + public void testDecodeHex() { + assertArrayEquals(new byte[]{0}, HexUtils.decode("0")); + assertArrayEquals(new byte[]{10}, HexUtils.decode("a")); + assertArrayEquals(new byte[]{10}, HexUtils.decode("A")); + assertArrayEquals(new byte[]{1, 0}, HexUtils.decode("100")); + } + +} \ No newline at end of file diff --git a/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java b/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java new file mode 100644 index 000000000000..b18752fd0594 --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java @@ -0,0 +1,35 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.junit.Test; + +import java.nio.file.Path; +import java.nio.file.Paths; + +public class CacheConfigTest { + + @Test + public void testMU() { +// final Path path = Paths.get("W:\\dev\\abfx\\maven-cache-config.xml"); +// final CacheConfig cacheConfig = CacheConfig.fromFile(path.toFile()); +// System.out.println(cacheConfig.toString()); + } +} \ No newline at end of file diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java index 8a6580b699af..1650e24eb681 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java @@ -17,10 +17,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.LifecycleExecutionException; -import org.apache.maven.lifecycle.internal.DependencyContext; -import org.apache.maven.lifecycle.internal.MojoExecutor; -import org.apache.maven.lifecycle.internal.PhaseRecorder; -import org.apache.maven.lifecycle.internal.ProjectIndex; +import org.apache.maven.lifecycle.internal.*; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; @@ -39,8 +36,8 @@ public class MojoExecutorStub public List executions = Collections.synchronizedList( new ArrayList() ); @Override - public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, - DependencyContext dependencyContext, PhaseRecorder phaseRecorder ) + public void execute(MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, + IDependencyContext dependencyContext, PhaseRecorder phaseRecorder ) throws LifecycleExecutionException { executions.add( mojoExecution ); diff --git a/pom.xml b/pom.xml index a5848644d563..d2bf50e677fc 100644 --- a/pom.xml +++ b/pom.xml @@ -47,8 +47,8 @@ under the License. 3.0.5 - 1.7 - 1.7 + 1.8 + 1.8 2.6.0 1.4 3.8.1 @@ -591,6 +591,7 @@ under the License. animal-sniffer-maven-plugin 1.17 + false org.codehaus.mojo.signature java17 From af3f957659d4416e9d0d9ff5a274bbe6148e98a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sun, 12 Sep 2021 19:24:09 +0200 Subject: [PATCH 096/188] fix typo --- .../src/main/java/org/apache/maven/caching/CacheEventSpy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java b/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java index 99f7e1a72542..c6c9a202b380 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java @@ -1,4 +1,4 @@ -package org.apache.maven.caching; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.caching; /* * Licensed to the Apache Software Foundation (ASF) under one From 803a8c45aacb0a243288c6f74af2192fd5f9231e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sun, 17 Oct 2021 18:58:55 +0200 Subject: [PATCH 097/188] add missing license --- maven-core/pom.xml | 1 - .../apache/maven/project/MavenProject.java | 27 ++++--------------- .../main/resources/cache-config-instance.xml | 20 ++++++++++++++ .../src/main/resources/cache-config.xsd | 20 ++++++++++++++ .../main/resources/cache-domain-instance.xml | 20 ++++++++++++++ .../src/main/resources/cache-domain.xsd | 20 ++++++++++++++ 6 files changed, 85 insertions(+), 23 deletions(-) diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 8f60c1bea85f..ffdac640f1aa 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -195,7 +195,6 @@ under the License. plugin-manager.txt project-builder.txt src/site/resources/design/** - src/main/resources/cache-* diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index ea15bda90a09..5ddeff77dc5f 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -1159,14 +1159,9 @@ public Plugin getPlugin( String pluginKey ) @Override public String toString() { - StringBuilder sb = new StringBuilder( 128 ); - sb.append( "MavenProject: " ); - sb.append( getGroupId() ); - sb.append( ':' ); - sb.append( getArtifactId() ); - sb.append( ':' ); - sb.append( getVersion() ); - sb.append( " @ " ); + StringBuilder sb = + new StringBuilder( 128 ).append( "MavenProject: " ).append( getGroupId() ).append( ':' ) + .append( getArtifactId() ).append( ':' ).append( getVersion() ).append( " @ " ); try { @@ -1581,12 +1576,9 @@ public void addScriptSourceRoot( String path ) if ( path != null ) { path = path.trim(); - if ( path.length() != 0 ) + if ( ( path.length() != 0 ) && !getScriptSourceRoots().contains( path ) ) { - if ( !getScriptSourceRoots().contains( path ) ) - { - getScriptSourceRoots().add( path ); - } + getScriptSourceRoots().add( path ); } } } @@ -1637,14 +1629,12 @@ public List getCompileDependencies() || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) ) { Dependency dependency = new Dependency(); - dependency.setArtifactId( a.getArtifactId() ); dependency.setGroupId( a.getGroupId() ); dependency.setVersion( a.getVersion() ); dependency.setScope( a.getScope() ); dependency.setType( a.getType() ); dependency.setClassifier( a.getClassifier() ); - list.add( dependency ); } } @@ -1682,14 +1672,12 @@ public List getTestDependencies() for ( Artifact a : getArtifacts() ) { Dependency dependency = new Dependency(); - dependency.setArtifactId( a.getArtifactId() ); dependency.setGroupId( a.getGroupId() ); dependency.setVersion( a.getVersion() ); dependency.setScope( a.getScope() ); dependency.setType( a.getType() ); dependency.setClassifier( a.getClassifier() ); - list.add( dependency ); } return Collections.unmodifiableList( list ); @@ -1713,14 +1701,12 @@ public List getRuntimeDependencies() if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) ) { Dependency dependency = new Dependency(); - dependency.setArtifactId( a.getArtifactId() ); dependency.setGroupId( a.getGroupId() ); dependency.setVersion( a.getVersion() ); dependency.setScope( a.getScope() ); dependency.setType( a.getType() ); dependency.setClassifier( a.getClassifier() ); - list.add( dependency ); } } @@ -1802,21 +1788,18 @@ public List getSystemDependencies() } List list = new ArrayList<>( artifacts.size() ); - for ( Artifact a : getArtifacts() ) { // TODO let the scope handler deal with this if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) ) { Dependency dependency = new Dependency(); - dependency.setArtifactId( a.getArtifactId() ); dependency.setGroupId( a.getGroupId() ); dependency.setVersion( a.getVersion() ); dependency.setScope( a.getScope() ); dependency.setType( a.getType() ); dependency.setClassifier( a.getClassifier() ); - list.add( dependency ); } } diff --git a/maven-core/src/main/resources/cache-config-instance.xml b/maven-core/src/main/resources/cache-config-instance.xml index 79f7422c24c4..68555927800a 100644 --- a/maven-core/src/main/resources/cache-config-instance.xml +++ b/maven-core/src/main/resources/cache-config-instance.xml @@ -1,4 +1,24 @@ + + + diff --git a/maven-core/src/main/resources/cache-config.xsd b/maven-core/src/main/resources/cache-config.xsd index 1f5eb4eb9be6..69437d993300 100644 --- a/maven-core/src/main/resources/cache-config.xsd +++ b/maven-core/src/main/resources/cache-config.xsd @@ -1,4 +1,24 @@ + + + + + + diff --git a/maven-core/src/main/resources/cache-domain.xsd b/maven-core/src/main/resources/cache-domain.xsd index 48446ca7370c..c233ed46e463 100644 --- a/maven-core/src/main/resources/cache-domain.xsd +++ b/maven-core/src/main/resources/cache-domain.xsd @@ -1,4 +1,24 @@ + + + Date: Wed, 3 Nov 2021 13:50:55 +0100 Subject: [PATCH 098/188] Make sure forked mojo executions have a correct phase set --- .../internal/DefaultLifecycleExecutionPlanCalculator.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java index ef60c4eb36b0..9992cf368c85 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java @@ -554,6 +554,8 @@ private List calculateForkedGoal( MojoExecution mojoExecution, Ma MojoExecution forkedExecution = new MojoExecution( forkedMojoDescriptor, forkedGoal ); + forkedExecution.setLifecyclePhase( mojoExecution.getLifecyclePhase() ); + mojoExecutionConfigurator( forkedExecution ).configure( project, forkedExecution, true ); finalizeMojoConfiguration( forkedExecution ); From b467ea4ecb6f3f06253b30919b3dc1cc376a004d Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 3 Nov 2021 14:21:46 +0100 Subject: [PATCH 099/188] Avoid IllegalStateException when cache is not enabled --- .../org/apache/maven/caching/CacheEventSpy.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java b/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java index c6c9a202b380..3cd5578d9be3 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java @@ -19,6 +19,7 @@ * under the License. */ +import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.eventspy.AbstractEventSpy; import org.apache.maven.eventspy.EventSpy; import org.apache.maven.execution.ExecutionEvent; @@ -31,18 +32,24 @@ @Component( role = EventSpy.class ) public class CacheEventSpy extends AbstractEventSpy { + @Requirement + private CacheConfig cacheConfig; + @Requirement private CacheController cacheController; @Override public void onEvent( Object event ) throws Exception { - if ( event instanceof ExecutionEvent ) + if ( cacheConfig.isEnabled() ) { - ExecutionEvent executionEvent = (ExecutionEvent) event; - if ( executionEvent.getType() == ExecutionEvent.Type.SessionEnded ) + if ( event instanceof ExecutionEvent ) { - cacheController.saveCacheReport( executionEvent.getSession() ); + ExecutionEvent executionEvent = (ExecutionEvent) event; + if ( executionEvent.getType() == ExecutionEvent.Type.SessionEnded ) + { + cacheController.saveCacheReport( executionEvent.getSession() ); + } } } } From a6bead751fcace3c8b6c67f57b06d5bf89dd1e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sun, 17 Oct 2021 23:21:20 +0200 Subject: [PATCH 100/188] [MNG-7324] first step to use Modello for cache-domain --- maven-core/pom.xml | 29 ++- maven-core/src/main/mdo/cache-domain.mdo | 296 +++++++++++++++++++++++ 2 files changed, 324 insertions(+), 1 deletion(-) create mode 100644 maven-core/src/main/mdo/cache-domain.mdo diff --git a/maven-core/pom.xml b/maven-core/pom.xml index ffdac640f1aa..d7890dbe7a10 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -220,7 +220,34 @@ under the License. - modello-site-doc + modello-site-docs-cache + pre-site + + xdoc + xsd + + + 1.0.0 + + src/main/mdo/cache-domain.mdo + + + + + modello-cache + + java + xpp3-reader + + + 1.0.0 + + src/main/mdo/cache-domain.mdo + + + + + modello-site-docs-extension pre-site xdoc diff --git a/maven-core/src/main/mdo/cache-domain.mdo b/maven-core/src/main/mdo/cache-domain.mdo new file mode 100644 index 000000000000..cb0ba6db99f9 --- /dev/null +++ b/maven-core/src/main/mdo/cache-domain.mdo @@ -0,0 +1,296 @@ + + + + cache-domain + CacheDomain + + + + package + org.apache.maven.caching.domain + + + + + + BuildInfoType + 1.0.0+ + extension.xml file.]]> + + + + cacheImplementationVersion + 1.0.0+ + String + + + + + + + hashFunction + 1.0.0+ + String + + + + + + buildServer + 1.0.0+ + String + + + + + + + goals + 1.0.0+ + + String + * + + + + + + artifact + 1.0.0+ + + ArtifactType + + + + + + + + + + ArtifactType + + + + + groupId + 1.0.0+ + String + + + + + artifactId + 1.0.0+ + String + + + + + version + 1.0.0+ + String + + + + + classifier + 1.0.0+ + String + + + + + type + 1.0.0+ + String + + + + + scope + 1.0.0+ + String + + + + + fileName + 1.0.0+ + String + + + + + fileHash + 1.0.0+ + String + + + + + + + + + + + + + + + + + From 1ae6bd14adb4a1aebcb53c128c0677e860aa53a1 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 4 Nov 2021 20:57:07 +0100 Subject: [PATCH 101/188] [MNG-7324] Complete modello switch --- maven-core/pom.xml | 7 + .../maven/caching/ArtifactsRepository.java | 2 +- .../apache/maven/caching/CacheContext.java | 2 +- .../maven/caching/CacheControllerImpl.java | 29 +- .../org/apache/maven/caching/CacheDiff.java | 28 +- .../org/apache/maven/caching/CacheResult.java | 2 +- .../caching/DefaultPluginScanConfig.java | 2 +- .../maven/caching/HttpRepositoryImpl.java | 10 +- .../caching/LocalArtifactsRepository.java | 2 +- .../maven/caching/LocalRepositoryImpl.java | 11 +- .../maven/caching/MojoExecutionManager.java | 6 +- .../maven/caching/PluginScanConfig.java | 2 +- .../maven/caching/PluginScanConfigImpl.java | 8 +- .../apache/maven/caching/ProjectUtils.java | 6 +- .../caching/RemoteArtifactsRepository.java | 2 +- .../maven/caching/checksum/DigestUtils.java | 2 +- .../maven/caching/checksum/KeyUtils.java | 2 +- .../caching/checksum/MavenProjectInput.java | 6 +- .../apache/maven/caching/xml/BuildInfo.java | 72 +- .../apache/maven/caching/xml/CacheConfig.java | 8 +- .../maven/caching/xml/CacheConfigImpl.java | 68 +- .../apache/maven/caching/xml/DtoUtils.java | 69 +- .../apache/maven/caching/xml/XmlService.java | 149 +- maven-core/src/main/mdo/cache-config.mdo | 1390 +++++++++++++++++ maven-core/src/main/mdo/cache-diff.mdo | 109 ++ maven-core/src/main/mdo/cache-domain.mdo | 365 +++-- maven-core/src/main/mdo/cache-report.mdo | 108 ++ .../apache/maven/caching/BuildInfoTest.java | 39 +- 28 files changed, 2080 insertions(+), 426 deletions(-) create mode 100644 maven-core/src/main/mdo/cache-config.mdo create mode 100644 maven-core/src/main/mdo/cache-diff.mdo create mode 100644 maven-core/src/main/mdo/cache-report.mdo diff --git a/maven-core/pom.xml b/maven-core/pom.xml index d7890dbe7a10..67a9bcb80922 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -238,11 +238,16 @@ under the License. java xpp3-reader + xpp3-writer + xsd 1.0.0 + src/main/mdo/cache-config.mdo src/main/mdo/cache-domain.mdo + src/main/mdo/cache-diff.mdo + src/main/mdo/cache-report.mdo @@ -278,6 +283,7 @@ under the License. + diff --git a/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java b/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java index 65315498c7ff..968bae24b759 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java +++ b/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java @@ -20,7 +20,7 @@ */ import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.jaxb.CacheReportType; +import org.apache.maven.caching.domain.CacheReportType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.execution.MavenSession; diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java b/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java index 569286d8b841..49b552ea8742 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.jaxb.ProjectsInputInfoType; +import org.apache.maven.caching.domain.ProjectsInputInfoType; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index ad9d490c6ebb..05e56a5b9828 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -31,18 +31,18 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.caching.checksum.KeyUtils; import org.apache.maven.caching.checksum.MavenProjectInput; +import org.apache.maven.caching.domain.Scm; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.jaxb.ArtifactType; -import org.apache.maven.caching.jaxb.BuildDiffType; -import org.apache.maven.caching.jaxb.BuildInfoType; -import org.apache.maven.caching.jaxb.CacheReportType; -import org.apache.maven.caching.jaxb.CompletedExecutionType; -import org.apache.maven.caching.jaxb.DigestItemType; -import org.apache.maven.caching.jaxb.ProjectReportType; -import org.apache.maven.caching.jaxb.ProjectsInputInfoType; -import org.apache.maven.caching.jaxb.PropertyNameType; -import org.apache.maven.caching.jaxb.TrackedPropertyType; +import org.apache.maven.caching.domain.ArtifactType; +import org.apache.maven.caching.domain.BuildDiffType; +import org.apache.maven.caching.domain.CacheReportType; +import org.apache.maven.caching.domain.CompletedExecutionType; +import org.apache.maven.caching.domain.DigestItemType; +import org.apache.maven.caching.domain.ProjectReportType; +import org.apache.maven.caching.domain.ProjectsInputInfoType; +import org.apache.maven.caching.domain.PropertyNameType; +import org.apache.maven.caching.domain.TrackedPropertyType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; @@ -67,7 +67,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.nio.file.FileVisitResult; import java.nio.file.Files; @@ -143,7 +142,7 @@ public class CacheControllerImpl implements CacheController private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); - private volatile BuildInfoType.Scm scm; + private volatile Scm scm; @Override @Nonnull @@ -434,7 +433,7 @@ public void save( CacheResult cacheResult, List mojoExecutions, final BuildInfo buildInfo = new BuildInfo( session.getGoals(), projectArtifactDto, attachedArtifactDtos, context.getInputInfo(), completedExecution, hashFactory.getAlgorithm() ); populateGitInfo( buildInfo, session ); - buildInfo.getDto().setFinal( cacheConfig.isSaveFinal() ); + buildInfo.getDto().set_final( cacheConfig.isSaveFinal() ); cacheResults.put( getVersionlessProjectKey( project ), rebuilded( cacheResult, buildInfo ) ); // if package phase presence means new artifacts were packaged @@ -554,7 +553,7 @@ private ArtifactType artifactDto( Artifact projectArtifact, HashAlgorithm algori { final Path file = projectArtifact.getFile().toPath(); dto.setFileHash( algorithm.hash( file ) ); - dto.setFileSize( BigInteger.valueOf( Files.size( file ) ) ); + dto.setFileSize( Files.size( file ) ); } return dto; } @@ -798,7 +797,7 @@ private void populateGitInfo( BuildInfo buildInfo, MavenSession session ) throws } catch ( IOException e ) { - scm = new BuildInfoType.Scm(); + scm = new Scm(); logger.error( "Cannot populate git info", e ); } } diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java b/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java index 9e066a598eff..5808e1807426 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java @@ -22,13 +22,13 @@ import com.google.common.base.Optional; import com.google.common.collect.Sets; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.jaxb.BuildDiffType; -import org.apache.maven.caching.jaxb.BuildInfoType; -import org.apache.maven.caching.jaxb.CompletedExecutionType; -import org.apache.maven.caching.jaxb.DigestItemType; -import org.apache.maven.caching.jaxb.MismatchType; -import org.apache.maven.caching.jaxb.ProjectsInputInfoType; -import org.apache.maven.caching.jaxb.PropertyValueType; +import org.apache.maven.caching.domain.BuildDiffType; +import org.apache.maven.caching.domain.BuildInfoType; +import org.apache.maven.caching.domain.CompletedExecutionType; +import org.apache.maven.caching.domain.DigestItemType; +import org.apache.maven.caching.domain.MismatchType; +import org.apache.maven.caching.domain.ProjectsInputInfoType; +import org.apache.maven.caching.domain.PropertyValueType; import org.apache.maven.caching.xml.CacheConfig; import java.util.ArrayList; @@ -232,23 +232,23 @@ private void compareDependencies( ProjectsInputInfoType current, ProjectsInputIn } - private void compareExecutions( BuildInfoType.Executions current, BuildInfoType.Executions baseline ) + private void compareExecutions( List current, List baseline ) { Map baselineExecutionsByKey = new HashMap<>(); - for ( CompletedExecutionType completedExecutionType : baseline.getExecution() ) + for ( CompletedExecutionType completedExecutionType : baseline ) { baselineExecutionsByKey.put( completedExecutionType.getExecutionKey(), completedExecutionType ); } Map currentExecutionsByKey = new HashMap<>(); - for ( CompletedExecutionType e1 : current.getExecution() ) + for ( CompletedExecutionType e1 : current ) { currentExecutionsByKey.put( e1.getExecutionKey(), e1 ); } // such situation normally means different poms and mismatch in effective poms, // but in any case it is helpful to report - for ( CompletedExecutionType baselineExecution : baseline.getExecution() ) + for ( CompletedExecutionType baselineExecution : baseline ) { if ( !currentExecutionsByKey.containsKey( baselineExecution.getExecutionKey() ) ) { @@ -261,7 +261,7 @@ private void compareExecutions( BuildInfoType.Executions current, BuildInfoType. } } - for ( CompletedExecutionType currentExecution : current.getExecution() ) + for ( CompletedExecutionType currentExecution : current ) { if ( !baselineExecutionsByKey.containsKey( currentExecution.getExecutionKey() ) ) { @@ -285,7 +285,7 @@ private void comparePlugins( CompletedExecutionType current, CompletedExecutionT { // TODO add support for skip values final List trackedProperties = new ArrayList<>(); - for ( PropertyValueType propertyValueType : current.getConfiguration().getProperty() ) + for ( PropertyValueType propertyValueType : current.getConfiguration() ) { if ( propertyValueType.isTracked() ) { @@ -298,7 +298,7 @@ private void comparePlugins( CompletedExecutionType current, CompletedExecutionT } final Map baselinePropertiesByName = new HashMap<>(); - for ( PropertyValueType propertyValueType : baseline.getConfiguration().getProperty() ) + for ( PropertyValueType propertyValueType : baseline.getConfiguration() ) { baselinePropertiesByName.put( propertyValueType.getName(), propertyValueType ); } diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheResult.java b/maven-core/src/main/java/org/apache/maven/caching/CacheResult.java index 8d886764f8b8..84038a3311d8 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheResult.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheResult.java @@ -117,6 +117,6 @@ public RestoreStatus getStatus() public boolean isFinal() { - return buildInfo != null && buildInfo.getDto().isFinal(); + return buildInfo != null && buildInfo.getDto().is_final(); } } diff --git a/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java b/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java index 408d097cf10e..8229435ce65d 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java +++ b/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.jaxb.DirScanConfigType; +import org.apache.maven.caching.domain.DirScanConfigType; import javax.annotation.Nonnull; diff --git a/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java index fbbe509bb28d..6747532bff42 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java @@ -33,10 +33,10 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.maven.artifact.Artifact; import org.apache.maven.caching.checksum.MavenProjectInput; -import org.apache.maven.caching.jaxb.ArtifactType; -import org.apache.maven.caching.jaxb.BuildInfoType; -import org.apache.maven.caching.jaxb.CacheReportType; -import org.apache.maven.caching.jaxb.ProjectReportType; +import org.apache.maven.caching.domain.ArtifactType; +import org.apache.maven.caching.domain.BuildInfoType; +import org.apache.maven.caching.domain.CacheReportType; +import org.apache.maven.caching.domain.ProjectReportType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; @@ -268,7 +268,7 @@ public Optional findBaselineBuild( MavenProject project ) { String url; final ProjectReportType projectReport = cachedProjectHolder.get(); - if ( projectReport.isSetUrl() ) + if ( projectReport.getUrl() != null ) { url = cachedProjectHolder.get().getUrl(); logInfo( "Retrieving baseline buildinfo: " + projectReport.getUrl(), project.getArtifactId() ); diff --git a/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java b/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java index c5916b2c64ba..280c2be5943c 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java +++ b/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java @@ -20,7 +20,7 @@ */ import com.google.common.base.Optional; -import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.caching.domain.ArtifactType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheSource; import org.apache.maven.execution.MavenSession; diff --git a/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java index ec75b476e4b4..78d1d1ac994d 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java @@ -31,9 +31,10 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.jaxb.ArtifactType; -import org.apache.maven.caching.jaxb.BuildInfoType; -import org.apache.maven.caching.jaxb.CacheReportType; +import org.apache.maven.caching.domain.ArtifactType; +import org.apache.maven.caching.domain.BuildInfoType; +import org.apache.maven.caching.domain.CacheReportType; +import org.apache.maven.caching.domain.Scm; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; @@ -350,11 +351,11 @@ public FileVisitResult visitFile( Path o, BasicFileAttributes basicFileAttribute return Optional.of( orderedFiles.get( 0 ).getLeft() ); } - private String getScmRef( BuildInfoType.Scm scm ) + private String getScmRef( Scm scm ) { if ( scm != null ) { - return scm.isSetSourceBranch() ? scm.getSourceBranch() : scm.getRevision(); + return scm.getSourceBranch() != null ? scm.getSourceBranch() : scm.getRevision(); } else { diff --git a/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java b/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java index 9c07e5815e69..a6e193695b30 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java +++ b/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java @@ -20,8 +20,8 @@ */ import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.jaxb.CompletedExecutionType; -import org.apache.maven.caching.jaxb.TrackedPropertyType; +import org.apache.maven.caching.domain.CompletedExecutionType; +import org.apache.maven.caching.domain.TrackedPropertyType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; @@ -124,7 +124,7 @@ private boolean isParamsMatched( MavenProject project, final String propertyName = trackedProperty.getPropertyName(); String expectedValue = DtoUtils.findPropertyValue( propertyName, completedExecution ); - if ( expectedValue == null && trackedProperty.isSetDefaultValue() ) + if ( expectedValue == null && trackedProperty.getDefaultValue() != null ) { expectedValue = trackedProperty.getDefaultValue(); } diff --git a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java index 93bcccba0b1c..a3af7b6cda96 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java +++ b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.jaxb.DirScanConfigType; +import org.apache.maven.caching.domain.DirScanConfigType; import javax.annotation.Nonnull; diff --git a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java index 87791905100d..e95342c2f1ed 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java @@ -20,9 +20,9 @@ */ import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.jaxb.DirScanConfigType; -import org.apache.maven.caching.jaxb.TagNameType; -import org.apache.maven.caching.jaxb.TagScanConfigType; +import org.apache.maven.caching.domain.DirScanConfigType; +import org.apache.maven.caching.domain.TagNameType; +import org.apache.maven.caching.domain.TagScanConfigType; import javax.annotation.Nonnull; import java.util.List; @@ -95,7 +95,7 @@ public PluginScanConfig mergeWith( final PluginScanConfig overrideConfig ) } DirScanConfigType merged = new DirScanConfigType(); - if ( override.isSetMode() ) + if ( override.getMode() != null ) { merged.setMode( override.getMode() ); } diff --git a/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java b/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java index 176556850377..dbf9251ea61a 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java @@ -25,7 +25,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.caching.jaxb.BuildInfoType; +import org.apache.maven.caching.domain.Scm; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.internal.ProjectIndex; import org.apache.maven.lifecycle.internal.builder.BuilderCommon; @@ -155,9 +155,9 @@ public static String getMultimoduleRoot( MavenSession session ) return System.getProperty( "maven.multiModuleProjectDirectory", session.getExecutionRootDirectory() ); } - public static BuildInfoType.Scm readGitInfo( MavenSession session ) throws IOException + public static Scm readGitInfo( MavenSession session ) throws IOException { - final BuildInfoType.Scm scmCandidate = new BuildInfoType.Scm(); + final Scm scmCandidate = new Scm(); final Path gitDir = Paths.get( getMultimoduleRoot( session ), ".git" ); if ( Files.isDirectory( gitDir ) ) { diff --git a/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java b/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java index 7c118c405739..826faf38ab8a 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java +++ b/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java @@ -20,7 +20,7 @@ */ import com.google.common.base.Optional; -import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.caching.domain.ArtifactType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.project.MavenProject; diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java index e837da1f8587..0a156e2296a9 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java @@ -22,7 +22,7 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.maven.caching.hash.HashChecksum; -import org.apache.maven.caching.jaxb.DigestItemType; +import org.apache.maven.caching.domain.DigestItemType; import org.mozilla.universalchardet.UniversalDetector; import java.io.IOException; diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java index 04d9207cb0dc..90da23e90f6d 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java @@ -21,7 +21,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.jaxb.ArtifactType; +import org.apache.maven.caching.domain.ArtifactType; import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 8e5873ce7dcd..ca78adaba6b0 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -36,8 +36,9 @@ import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashChecksum; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.jaxb.DigestItemType; -import org.apache.maven.caching.jaxb.ProjectsInputInfoType; +import org.apache.maven.caching.domain.DigestItemType; +import org.apache.maven.caching.domain.Include; +import org.apache.maven.caching.domain.ProjectsInputInfoType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; @@ -94,7 +95,6 @@ import static org.apache.commons.lang3.StringUtils.stripToEmpty; import static org.apache.maven.caching.ProjectUtils.isBuilding; import static org.apache.maven.caching.ProjectUtils.isSnapshot; -import static org.apache.maven.caching.jaxb.PathSetType.Include; /** * MavenProjectInput diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java b/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java index 0b61bfd89d74..452811e6f79c 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java @@ -24,24 +24,22 @@ import org.apache.maven.caching.ProjectUtils; import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.hash.HashAlgorithm; -import org.apache.maven.caching.jaxb.ArtifactType; -import org.apache.maven.caching.jaxb.BuildInfoType; -import org.apache.maven.caching.jaxb.CompletedExecutionType; -import org.apache.maven.caching.jaxb.DigestItemType; -import org.apache.maven.caching.jaxb.ProjectsInputInfoType; +import org.apache.maven.caching.domain.ArtifactType; +import org.apache.maven.caching.domain.BuildInfoType; +import org.apache.maven.caching.domain.CompletedExecutionType; +import org.apache.maven.caching.domain.DigestItemType; +import org.apache.maven.caching.domain.ProjectsInputInfoType; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecution; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; -import java.util.GregorianCalendar; +import java.util.Date; import java.util.List; import java.util.Objects; @@ -66,13 +64,7 @@ public BuildInfo( List goals, { this.dto = new BuildInfoType(); this.dto.setCacheImplementationVersion( MavenProjectInput.CACHE_IMPLMENTATION_VERSION ); - try - { - this.dto.setBuildTime( DatatypeFactory.newInstance().newXMLGregorianCalendar( new GregorianCalendar() ) ); - } - catch ( DatatypeConfigurationException ignore ) - { - } + this.dto.setBuildTime( new Date() ); try { this.dto.setBuildServer( InetAddress.getLocalHost().getCanonicalHostName() ); @@ -83,10 +75,9 @@ public BuildInfo( List goals, } this.dto.setHashFunction( hashAlgorithm ); this.dto.setArtifact( artifact ); - this.dto.setGoals( createGoals( goals ) ); - this.dto.setAttachedArtifacts( new BuildInfoType.AttachedArtifacts() ); - this.dto.getAttachedArtifacts().getArtifact().addAll( attachedArtifacts ); - this.dto.setExecutions( createExecutions( completedExecutions ) ); + this.dto.setGoals( goals ); + this.dto.setAttachedArtifacts( attachedArtifacts ); + this.dto.setExecutions( completedExecutions ); this.dto.setProjectsInputInfo( projectsInputInfo ); this.source = CacheSource.BUILD; } @@ -96,30 +87,16 @@ public CacheSource getSource() return source; } - private BuildInfoType.Executions createExecutions( List completedExecutions ) - { - BuildInfoType.Executions executions = new BuildInfoType.Executions(); - executions.getExecution().addAll( completedExecutions ); - return executions; - } - public BuildInfo( BuildInfoType buildInfo, CacheSource source ) { this.dto = buildInfo; this.source = source; } - public static BuildInfoType.Goals createGoals( List list ) - { - BuildInfoType.Goals goals = new BuildInfoType.Goals(); - goals.getGoal().addAll( list ); - return goals; - } - - public static BuildInfoType.AttachedArtifacts createAttachedArtifacts( List artifacts, - HashAlgorithm algorithm ) throws IOException + public static List createAttachedArtifacts( List artifacts, + HashAlgorithm algorithm ) throws IOException { - BuildInfoType.AttachedArtifacts attachedArtifacts = new BuildInfoType.AttachedArtifacts(); + List attachedArtifacts = new ArrayList<>(); for ( Artifact artifact : artifacts ) { final ArtifactType dto = DtoUtils.createDto( artifact ); @@ -127,7 +104,7 @@ public static BuildInfoType.AttachedArtifacts createAttachedArtifacts( List mojos, Logger logger private boolean hasCompletedExecution( String mojoExecutionKey ) { - final List completedExecutions = dto.getExecutions().getExecution(); - for ( CompletedExecutionType completedExecution : completedExecutions ) + final List completedExecutions = dto.getExecutions(); + if ( dto.getExecutions() != null ) { - if ( StringUtils.equals( completedExecution.getExecutionKey(), mojoExecutionKey ) ) + for ( CompletedExecutionType completedExecution : completedExecutions ) { - return true; + if ( StringUtils.equals( completedExecution.getExecutionKey(), mojoExecutionKey ) ) + { + return true; + } } } return false; @@ -168,12 +148,12 @@ public String toString() public CompletedExecutionType findMojoExecutionInfo( MojoExecution mojoExecution ) { - if ( !dto.isSetExecutions() ) + if ( dto.getExecutions() == null ) { return null; } - final List executions = dto.getExecutions().getExecution(); + final List executions = dto.getExecutions(); for ( CompletedExecutionType execution : executions ) { if ( StringUtils.equals( execution.getExecutionKey(), mojoExecutionKey( mojoExecution ) ) ) @@ -196,9 +176,9 @@ public ArtifactType getArtifact() public List getAttachedArtifacts() { - if ( dto.isSetAttachedArtifacts() ) + if ( dto.getAttachedArtifacts() != null ) { - return dto.getAttachedArtifacts().getArtifact(); + return dto.getAttachedArtifacts(); } return Collections.emptyList(); } @@ -210,7 +190,7 @@ public BuildInfoType getDto() public String getHighestCompletedGoal() { - return Iterables.getLast( dto.getGoals().getGoal() ); + return Iterables.getLast( dto.getGoals() ); } public List getCachedSegment( List mojoExecutions ) diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java index 2f5137d9a3ea..e07ce6a9b74e 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java @@ -22,9 +22,9 @@ import org.apache.maven.caching.PluginScanConfig; import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.jaxb.PathSetType; -import org.apache.maven.caching.jaxb.PropertyNameType; -import org.apache.maven.caching.jaxb.TrackedPropertyType; +import org.apache.maven.caching.domain.Include; +import org.apache.maven.caching.domain.PropertyNameType; +import org.apache.maven.caching.domain.TrackedPropertyType; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; @@ -62,7 +62,7 @@ public interface CacheConfig String getDefaultGlob(); @Nonnull - List getGlobalIncludePaths(); + List getGlobalIncludePaths(); @Nonnull List getGlobalExcludePaths(); diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 9dd0e85f578f..7946942aee63 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -26,21 +26,25 @@ import org.apache.maven.caching.PluginScanConfig; import org.apache.maven.caching.PluginScanConfigImpl; import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; +import org.apache.maven.caching.domain.AttachedOutputs; +import org.apache.maven.caching.domain.Include; +import org.apache.maven.caching.domain.Local; +import org.apache.maven.caching.domain.ProjectDiscoveryStrategy; +import org.apache.maven.caching.domain.Remote; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.jaxb.CacheType; -import org.apache.maven.caching.jaxb.ConfigurationType; -import org.apache.maven.caching.jaxb.CoordinatesBaseType; -import org.apache.maven.caching.jaxb.ExecutablesType; -import org.apache.maven.caching.jaxb.ExecutionConfigurationScanType; -import org.apache.maven.caching.jaxb.ExecutionControlType; -import org.apache.maven.caching.jaxb.ExecutionIdsListType; -import org.apache.maven.caching.jaxb.GoalReconciliationType; -import org.apache.maven.caching.jaxb.GoalsListType; -import org.apache.maven.caching.jaxb.PathSetType; -import org.apache.maven.caching.jaxb.PluginConfigurationScanType; -import org.apache.maven.caching.jaxb.PluginSetType; -import org.apache.maven.caching.jaxb.PropertyNameType; -import org.apache.maven.caching.jaxb.TrackedPropertyType; +import org.apache.maven.caching.domain.CacheType; +import org.apache.maven.caching.domain.ConfigurationType; +import org.apache.maven.caching.domain.CoordinatesBaseType; +import org.apache.maven.caching.domain.ExecutablesType; +import org.apache.maven.caching.domain.ExecutionConfigurationScanType; +import org.apache.maven.caching.domain.ExecutionControlType; +import org.apache.maven.caching.domain.ExecutionIdsListType; +import org.apache.maven.caching.domain.GoalReconciliationType; +import org.apache.maven.caching.domain.GoalsListType; +import org.apache.maven.caching.domain.PluginConfigurationScanType; +import org.apache.maven.caching.domain.PluginSetType; +import org.apache.maven.caching.domain.PropertyNameType; +import org.apache.maven.caching.domain.TrackedPropertyType; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; @@ -202,20 +206,20 @@ public boolean isLogAllProperties( MojoExecution mojoExecution ) { return true; } - return cacheConfig.isSetExecutionControl() && cacheConfig.getExecutionControl().isSetReconcile() + return cacheConfig.getExecutionControl() != null && cacheConfig.getExecutionControl().getReconcile() != null && cacheConfig.getExecutionControl().getReconcile().isLogAllProperties(); } private GoalReconciliationType findReconciliationConfig( MojoExecution mojoExecution ) { - if ( !cacheConfig.isSetExecutionControl() ) + if ( cacheConfig.getExecutionControl() == null ) { return null; } final ExecutionControlType executionControl = cacheConfig.getExecutionControl(); - if ( !executionControl.isSetReconcile() ) + if ( executionControl.getReconcile() == null ) { return null; } @@ -276,7 +280,7 @@ public List getEffectivePomExcludeProperties( Plugin plugin ) checkInitializedState(); final PluginConfigurationScanType pluginConfig = findPluginScanConfig( plugin ); - if ( pluginConfig != null && pluginConfig.isSetEffectivePom() ) + if ( pluginConfig != null && pluginConfig.getEffectivePom() != null ) { return pluginConfig.getEffectivePom().getExcludeProperty(); } @@ -286,7 +290,7 @@ public List getEffectivePomExcludeProperties( Plugin plugin ) private PluginConfigurationScanType findPluginScanConfig( Plugin plugin ) { - if ( !cacheConfig.isSetInput() ) + if ( cacheConfig.getInput() == null ) { return null; } @@ -305,7 +309,7 @@ private PluginConfigurationScanType findPluginScanConfig( Plugin plugin ) private boolean isPluginMatch( Plugin plugin, CoordinatesBaseType pluginConfig ) { return StringUtils.equals( pluginConfig.getArtifactId(), - plugin.getArtifactId() ) && ( !pluginConfig.isSetGroupId() || StringUtils.equals( + plugin.getArtifactId() ) && ( pluginConfig.getGroupId() == null || StringUtils.equals( pluginConfig.getGroupId(), plugin.getGroupId() ) ); } @@ -316,7 +320,7 @@ public PluginScanConfig getPluginDirScanConfig( Plugin plugin ) { checkInitializedState(); final PluginConfigurationScanType pluginConfig = findPluginScanConfig( plugin ); - if ( pluginConfig == null || !pluginConfig.isSetDirScan() ) + if ( pluginConfig == null || pluginConfig.getDirScan() == null ) { return new DefaultPluginScanConfig(); } @@ -335,7 +339,7 @@ public PluginScanConfig getExecutionDirScanConfig( Plugin plugin, PluginExecutio { final ExecutionConfigurationScanType executionScanConfig = findExecutionScanConfig( exec, pluginScanConfig.getExecution() ); - if ( executionScanConfig != null && executionScanConfig.isSetDirScan() ) + if ( executionScanConfig != null && executionScanConfig.getDirScan() != null ) { return new PluginScanConfigImpl( executionScanConfig.getDirScan() ); } @@ -373,7 +377,7 @@ public String getDefaultGlob() @Nonnull @Override - public List getGlobalIncludePaths() + public List getGlobalIncludePaths() { checkInitializedState(); return cacheConfig.getInput().getGlobal().getInclude(); @@ -392,9 +396,9 @@ public List getGlobalExcludePaths() public MultimoduleDiscoveryStrategy getMultimoduleDiscoveryStrategy() { checkInitializedState(); - final ConfigurationType.ProjectDiscoveryStrategy projectDiscoveryStrategy = + final ProjectDiscoveryStrategy projectDiscoveryStrategy = cacheConfig.getConfiguration().getProjectDiscoveryStrategy(); - if ( projectDiscoveryStrategy.isSetSpecificVersion() ) + if ( projectDiscoveryStrategy.getSpecificVersion() != null ) { return new SentinelVersionStartegy( projectDiscoveryStrategy.getSpecificVersion() ); } @@ -413,7 +417,7 @@ public HashFactory getHashFactory() public boolean canIgnore( MojoExecution mojoExecution ) { checkInitializedState(); - if ( !cacheConfig.isSetExecutionControl() || !cacheConfig.getExecutionControl().isSetIgnoreMissing() ) + if ( cacheConfig.getExecutionControl() == null || cacheConfig.getExecutionControl().getIgnoreMissing() == null ) { return false; } @@ -425,7 +429,7 @@ public boolean canIgnore( MojoExecution mojoExecution ) public boolean isForcedExecution( MojoExecution execution ) { checkInitializedState(); - if ( !cacheConfig.isSetExecutionControl() || !cacheConfig.getExecutionControl().isSetRunAlways() ) + if ( cacheConfig.getExecutionControl() == null || cacheConfig.getExecutionControl().getRunAlways() == null ) { return false; } @@ -524,14 +528,14 @@ public String getUrl() public int getMaxLocalBuildsCached() { checkInitializedState(); - return getLocal().getMaxBuildsCached().intValue(); + return getLocal().getMaxBuildsCached(); } @Override public List getAttachedOutputs() { checkInitializedState(); - final ConfigurationType.AttachedOutputs attachedOutputs = getConfiguration().getAttachedOutputs(); + final AttachedOutputs attachedOutputs = getConfiguration().getAttachedOutputs(); return attachedOutputs == null ? Collections.emptyList() : attachedOutputs.getDirName(); } @@ -545,7 +549,7 @@ public List getExcludePatterns() private List compileExcludePatterns() { - if ( cacheConfig.isSetOutput() && cacheConfig.getOutput().isSetExclude() ) + if ( cacheConfig.getOutput() != null && cacheConfig.getOutput().getExclude() != null ) { List patterns = new ArrayList<>(); for ( String pattern : cacheConfig.getOutput().getExclude().getPattern() ) @@ -557,12 +561,12 @@ private List compileExcludePatterns() return Collections.emptyList(); } - private ConfigurationType.Remote getRemote() + private Remote getRemote() { return getConfiguration().getRemote(); } - private ConfigurationType.Local getLocal() + private Local getLocal() { return getConfiguration().getLocal(); } diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java b/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java index a2810ab86824..7bd2d2b2dc2f 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java @@ -23,14 +23,16 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.caching.ProjectUtils; -import org.apache.maven.caching.jaxb.ArtifactType; -import org.apache.maven.caching.jaxb.CompletedExecutionType; -import org.apache.maven.caching.jaxb.DigestItemType; -import org.apache.maven.caching.jaxb.PropertyValueType; -import org.apache.maven.caching.jaxb.TrackedPropertyType; +import org.apache.maven.caching.domain.ArtifactType; +import org.apache.maven.caching.domain.CompletedExecutionType; +import org.apache.maven.caching.domain.DigestItemType; +import org.apache.maven.caching.domain.PropertyValueType; +import org.apache.maven.caching.domain.TrackedPropertyType; import org.apache.maven.model.Dependency; import javax.annotation.Nonnull; + +import java.util.ArrayList; import java.util.List; import static org.apache.maven.caching.checksum.KeyUtils.getArtifactKey; @@ -43,12 +45,12 @@ public class DtoUtils public static String findPropertyValue( String propertyName, CompletedExecutionType completedExecution ) { - final CompletedExecutionType.Configuration configuration = completedExecution.getConfiguration(); + final List configuration = completedExecution.getConfiguration(); if ( configuration == null ) { return null; } - final List properties = configuration.getProperty(); + final List properties = configuration; for ( PropertyValueType property : properties ) { if ( StringUtils.equals( propertyName, property.getName() ) ) @@ -124,7 +126,7 @@ public static void addProperty( CompletedExecutionType execution, { if ( execution.getConfiguration() == null ) { - execution.setConfiguration( new CompletedExecutionType.Configuration() ); + execution.setConfiguration( new ArrayList<>() ); } final PropertyValueType valueType = new PropertyValueType(); valueType.setName( propertyName ); @@ -135,7 +137,7 @@ public static void addProperty( CompletedExecutionType execution, final String valueText = String.valueOf( value ); valueType.setValue( StringUtils.remove( valueText, baseDirPath ) ); valueType.setTracked( tracked ); - execution.getConfiguration().getProperty().add( valueType ); + execution.getConfiguration().add( valueType ); } public static boolean containsAllProperties( @@ -147,12 +149,12 @@ public static boolean containsAllProperties( return true; } - if ( !cachedExecution.isSetConfiguration() ) + if ( cachedExecution.getConfiguration() == null ) { return false; } - final List executionProperties = cachedExecution.getConfiguration().getProperty(); + final List executionProperties = cachedExecution.getConfiguration(); for ( TrackedPropertyType trackedProperty : trackedProperties ) { if ( !contains( executionProperties, trackedProperty.getPropertyName() ) ) @@ -178,42 +180,15 @@ public static boolean contains( List executionProperties, Str public static ArtifactType copy( ArtifactType artifact ) { ArtifactType copy = new ArtifactType(); - if ( artifact.isSetArtifactId() ) - { - copy.setArtifactId( artifact.getArtifactId() ); - } - if ( artifact.isSetGroupId() ) - { - copy.setGroupId( artifact.getGroupId() ); - } - if ( artifact.isSetVersion() ) - { - copy.setVersion( artifact.getVersion() ); - } - if ( artifact.isSetType() ) - { - copy.setType( artifact.getType() ); - } - if ( artifact.isSetClassifier() ) - { - copy.setClassifier( artifact.getClassifier() ); - } - if ( artifact.isSetScope() ) - { - copy.setScope( artifact.getScope() ); - } - if ( artifact.isSetFileName() ) - { - copy.setFileName( artifact.getFileName() ); - } - if ( artifact.isSetFileHash() ) - { - copy.setFileHash( artifact.getFileHash() ); - } - if ( artifact.isSetFileSize() ) - { - copy.setFileSize( artifact.getFileSize() ); - } + copy.setArtifactId( artifact.getArtifactId() ); + copy.setGroupId( artifact.getGroupId() ); + copy.setVersion( artifact.getVersion() ); + copy.setType( artifact.getType() ); + copy.setClassifier( artifact.getClassifier() ); + copy.setScope( artifact.getScope() ); + copy.setFileName( artifact.getFileName() ); + copy.setFileHash( artifact.getFileHash() ); + copy.setFileSize( artifact.getFileSize() ); return copy; } } diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java b/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java index 658c9d0dd3b1..f63ffe6c9cb5 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java @@ -19,27 +19,26 @@ * under the License. */ -import org.apache.maven.caching.jaxb.BuildDiffType; -import org.apache.maven.caching.jaxb.BuildInfoType; -import org.apache.maven.caching.jaxb.CacheReportType; -import org.apache.maven.caching.jaxb.ObjectFactory; +import org.apache.maven.caching.domain.CacheType; +import org.apache.maven.caching.domain.io.xpp3.CacheConfigXpp3Reader; +import org.apache.maven.caching.domain.io.xpp3.CacheConfigXpp3Writer; +import org.apache.maven.caching.domain.io.xpp3.CacheDiffXpp3Reader; +import org.apache.maven.caching.domain.io.xpp3.CacheDiffXpp3Writer; +import org.apache.maven.caching.domain.io.xpp3.CacheDomainXpp3Reader; +import org.apache.maven.caching.domain.BuildDiffType; +import org.apache.maven.caching.domain.BuildInfoType; +import org.apache.maven.caching.domain.CacheReportType; +import org.apache.maven.caching.domain.io.xpp3.CacheDomainXpp3Writer; +import org.apache.maven.caching.domain.io.xpp3.CacheReportXpp3Reader; +import org.apache.maven.caching.domain.io.xpp3.CacheReportXpp3Writer; import org.codehaus.plexus.component.annotations.Component; -import org.xml.sax.SAXException; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import javax.xml.XMLConstants; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.InputStream; +import java.io.IOException; +import java.nio.file.Files; /** * XmlService @@ -48,98 +47,94 @@ public class XmlService { - private final ObjectFactory objectFactory; - private final JAXBContext jaxbContext; - private final Schema schema; - - public XmlService() throws JAXBException, SAXException + public byte[] toBytes( CacheType cache ) throws IOException { - objectFactory = new ObjectFactory(); - jaxbContext = JAXBContext.newInstance( "org.apache.maven.caching.jaxb", XmlService.class.getClassLoader() ); - - SchemaFactory sf = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI ); - final InputStream domainSchemaStream = getResourceAsStream( "cache-domain.xsd" ); - final Source domainSchema = new StreamSource( domainSchemaStream ); - final InputStream configSchemaStream = getResourceAsStream( "cache-config.xsd" ); - final Source configSchema = new StreamSource( configSchemaStream ); - schema = sf.newSchema( new Source[] {domainSchema, configSchema} ); + try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) + { + new CacheConfigXpp3Writer().write( baos, cache ); + return baos.toByteArray(); + } } - public byte[] toBytes( BuildInfoType buildInfo ) + public byte[] toBytes( BuildInfoType buildInfo ) throws IOException { - return serializeXml( objectFactory.createBuild( buildInfo ) ); + try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) + { + new CacheDomainXpp3Writer().write( baos, buildInfo ); + return baos.toByteArray(); + } } - public byte[] toBytes( BuildDiffType diff ) + public byte[] toBytes( BuildDiffType diff ) throws IOException { - return serializeXml( objectFactory.createDiff( diff ) ); + try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) + { + new CacheDiffXpp3Writer().write( baos, diff ); + return baos.toByteArray(); + } } - public byte[] toBytes( CacheReportType cacheReportType ) + public byte[] toBytes( CacheReportType cacheReportType ) throws IOException { - - return serializeXml( objectFactory.createReport( cacheReportType ) ); + try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) + { + new CacheReportXpp3Writer().write( baos, cacheReportType ); + return baos.toByteArray(); + } } - private byte[] serializeXml( JAXBElement element ) + public T fromFile( Class clazz, File file ) throws IOException, XmlPullParserException { - try + if ( clazz == BuildInfoType.class ) { - Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); - jaxbMarshaller.setSchema( schema ); - // output pretty printed - jaxbMarshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true ); - jaxbMarshaller.setProperty( Marshaller.JAXB_ENCODING, "UTF-8" ); - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - jaxbMarshaller.marshal( element, baos ); - return baos.toByteArray(); + return clazz.cast( new CacheDomainXpp3Reader().read( Files.newInputStream( file.toPath() ) ) ); } - catch ( Exception e ) + else if ( clazz == CacheType.class ) { - throw new RuntimeException( "Errors in jaxb serialization: " + e.toString(), e ); + return clazz.cast( new CacheConfigXpp3Reader().read( Files.newInputStream( file.toPath() ) ) ); } - } - - public T fromFile( Class clazz, File file ) - { - - try + else if ( clazz == BuildDiffType.class ) { - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - unmarshaller.setSchema( schema ); - JAXBElement result = (JAXBElement) unmarshaller.unmarshal( file ); - return result.getValue(); + return clazz.cast( new CacheDiffXpp3Reader().read( Files.newInputStream( file.toPath() ) ) ); } - catch ( Exception e ) + else if ( clazz == CacheReportType.class ) { - throw new RuntimeException( "Errors in jaxb serialization: " + e.toString(), e ); + return clazz.cast( new CacheReportXpp3Reader().read( Files.newInputStream( file.toPath() ) ) ); } - } - - public static InputStream getResourceAsStream( String name ) - { - ClassLoader cl = XmlService.class.getClassLoader(); - if ( cl == null ) + else { - // A system class. - return ClassLoader.getSystemResourceAsStream( name ); + throw new IllegalArgumentException( "Unsupported type " + clazz ); } - return cl.getResourceAsStream( name ); } public T fromBytes( Class clazz, byte[] bytes ) { try { - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - unmarshaller.setSchema( schema ); - JAXBElement result = (JAXBElement) unmarshaller.unmarshal( new ByteArrayInputStream( bytes ) ); - return result.getValue(); - + if ( clazz == BuildInfoType.class ) + { + return clazz.cast( new CacheDomainXpp3Reader().read( new ByteArrayInputStream( bytes ) ) ); + } + else if ( clazz == CacheType.class ) + { + return clazz.cast( new CacheConfigXpp3Reader().read( new ByteArrayInputStream( bytes ) ) ); + } + else if ( clazz == BuildDiffType.class ) + { + return clazz.cast( new CacheDiffXpp3Reader().read( new ByteArrayInputStream( bytes ) ) ); + } + else if ( clazz == CacheReportType.class ) + { + return clazz.cast( new CacheReportXpp3Reader().read( new ByteArrayInputStream( bytes ) ) ); + } + else + { + throw new IllegalArgumentException( "Unsupported type " + clazz ); + } } - catch ( Exception e ) + catch ( IOException | XmlPullParserException e ) { - throw new RuntimeException( "Errors in jaxb serialization: " + e.toString(), e ); + throw new RuntimeException( "Unable to parse cache xml element", e ); } } } diff --git a/maven-core/src/main/mdo/cache-config.mdo b/maven-core/src/main/mdo/cache-config.mdo new file mode 100644 index 000000000000..dfd4bf651863 --- /dev/null +++ b/maven-core/src/main/mdo/cache-config.mdo @@ -0,0 +1,1390 @@ + + + + cache-config + CacheConfig + + + + + package + org.apache.maven.caching.domain + + + + + + + + CacheType + + + configuration + + ConfigurationType + + + + input + + InputType + + + + output + + OutputType + + + + executionControl + + ExecutionControlType + + + + + + + + Remote + + + url + String + address of remote cache + + + enabled + boolean + true + + + saveToRemote + boolean + false + Save output to remote cache. Recommended to enable on CI agents only. + + + + + + + ConfigurationType + + + enabled + boolean + + + hashAlgorithm + String + One of XX, XXMM, SHA-1, SHA-256, SHA-384, SHA-512 + + + validateXml + boolean + true + Validate cache config and builds metadata against xsd. + + + projectDiscoveryStrategy + + ProjectDiscoveryStrategy + + Specifies how to identify belonging to a cached project then submodule is being build. + + + remote + + Remote + + + + attachedOutputs + + AttachedOutputs + + + + local + + Local + + + + debug + + String + * + + FileHash (causes file hash is saved in build metadata) or + EffectivePom (causes effective pom info is saved in build metadata) + + + + + + + ProjectDiscoveryStrategy + + + specificVersion + String + + Any project dependency this this version will be considered cache eligible and will + be processed cache aware + + + + + + + + AttachedOutputs + + + dirName + + String + * + + Directory name in build output directory to attach to cached artifacts + + + + + + + Local + + + maxBuildsCached + int + 3 + Maximum number of cached build per artifact in local cache. First created cache (the + oldest) is evicted if breached. + + + + + + + InputType + + + global + + PathSetType + + Global input calculation rules applicable to all projects and plugins in the build + + + plugin + + PluginConfigurationScanType + * + + Plugin specific input calculation rules + + + + + + + PluginConfigurationScanType + CoordinatesBaseType + + + effectivePom + + EffectivePom + + Effective pom calculation rules + + + dirScan + + DirScanConfigType + + Specifies plugin level rules of configuration processing in search of referenced source files + + + execution + + ExecutionConfigurationScanType + * + + Specifies execution specific configuration processing in search of referenced source files + + + + + + + EffectivePom + + + excludeProperty + + String + * + + Plugin configuration property should be excluded from effective pom calculation + + + + + + + ExecutionConfigurationScanType + + + execId + + String + * + + + + dirScan + + DirScanConfigType + + Specifies rules of configuration processing in search of referenced source files + + + ignoreParentConfig + boolean + ignore parent config or inherit/merge + + + + + + + TagScanConfigType + TagNameType + + + recursive + boolean + true + + + glob + String + * + + + + + + + DirScanConfigType + + + include + + TagScanConfigType + * + + Forces cache to treat property value as input and include in calculation. If set, only included + properties will be takein in calculation (whitelist) + + + exclude + + TagNameType + * + + Tag to exclude when scanning plugin configuration for input files (blacklist) + + + tagScanConfig + + TagScanConfigType + * + + Additional processing rules for non-blacklisted tags + + + ignoreParent + boolean + false + Ignore parent settings or inherit and merge + + + mode + String + + Either 'auto' (scan directory accordingly to cache implementation) or 'skip' (skip directory). + + + + + + + + OutputType + + + exclude + + OutputTypeExclude + + Patterns to exclude output artifacts applicable to all projects in the build + + + + + + OutputTypeExclude + + + pattern + + String + * + + + + + + + + PathSetType + + + glob + String + * + + + include + + Include + * + + + + exclude + + String + * + + + + + + Include + + + value + String + + + recursive + boolean + true + + + glob + String + * + + + + + + + + + + GoalReconciliationType + GoalIdType + + + reconcile + + TrackedPropertyType + * + + + + log + + PropertyNameType + * + + Specify property which should be logged to build metadata for exploration + + + nolog + + PropertyNameType + * + + Specify property which should not be logged + + + logAll + boolean + true + Controls if all plugin properties to be logged (true is default). All the properties logged + with respect to log/nolog children: + * true: logged all if no blacklists (<nolog/>) and whitelists (<log/>) specified on plugin + level + * false: logged only tracked and included by whitelists (<log/>) on plugin level + + + + + + + + + ExecutionControlType + + + runAlways + + ExecutablesType + + Specify which plugin should run always if present in build regardless of cached status + + + ignoreMissing + + ExecutablesType + + + Specify which executions/plugins/goals do not affect generated artifacts and do not affect build correctness. + If cached build lacks of ignorable executions only, it still could be reused. + Typically case is then cached build is produced with 'verify' and you locally you run 'install'. + Strictly speaking these are different builds but in most of cases you want this difference to be ignored + + + + reconcile + + Reconcile + + Specify which plugin should run always if present in build regardless of cached status + + + + + + + + Reconcile + + + plugin + + GoalReconciliationType + * + + Reconciliation rules for plugin properties which might be affected by command line flags, etc + + + logAllProperties + boolean + true + + Controls if all plugin properties to be logged (true is default). All the properties + logged with respect to children: + * logAll on plugin level overrides global value + * true: logged all if no blacklists (<nolog/>) and whitelists (<log/>) specified on + plugin level + * false: logged only tracked and included by whitelists (<log/>) on plugin level + <log/> + + + + + + + + + ExecutablesType + + + plugin + + PluginSetType + * + + Specify which executions should run always if present in build regardless of cached status + + + execution + + ExecutionIdsListType + * + + Specify which executions should run always if present in build regardless of cached status + + + goals + + GoalsListType + * + + Specify which goals should run always if present in build regardless of cached status + + + + + + + + GoalsListType + CoordinatesBaseType + + + goal + + String + * + + Goals identification + + + + + + + + GoalIdType + CoordinatesBaseType + + + goal + String + true + + + + + + + + ExecutionIdsListType + CoordinatesBaseType + + + execId + + String + * + + Executions ids list with plugin identifier + + + + + + + + PluginSetType + CoordinatesBaseType + + + + + + CoordinatesBaseType + + + groupId + String + + + artifactId + String + + + + + + + + TagNameType + + + tagName + String + true + + + + + + + + PropertyNameType + + + value + String + + + propertyName + String + + + + + + + + TrackedPropertyType + + + value + String + + + propertyName + String + + + skipValue + String + + + defaultValue + String + + + + + + + + diff --git a/maven-core/src/main/mdo/cache-diff.mdo b/maven-core/src/main/mdo/cache-diff.mdo new file mode 100644 index 000000000000..e2a9cfec34c9 --- /dev/null +++ b/maven-core/src/main/mdo/cache-diff.mdo @@ -0,0 +1,109 @@ + + + + cache-diff + CacheDiff + + + + package + org.apache.maven.caching.domain + + + + + + + + BuildDiffType + + + mismatch + + MismatchType + * + + + + + + + + + MismatchType + + + detail + + MismatchDetailType + * + + + + item + String + + + current + String + + + baseline + String + + + reason + String + + + resolution + String + + + context + String + + + + + + + MismatchDetailType + + + + diff --git a/maven-core/src/main/mdo/cache-domain.mdo b/maven-core/src/main/mdo/cache-domain.mdo index cb0ba6db99f9..43c353041ba8 100644 --- a/maven-core/src/main/mdo/cache-domain.mdo +++ b/maven-core/src/main/mdo/cache-domain.mdo @@ -18,7 +18,8 @@ under the License. --> + xsi:schemaLocation="http://codehaus-plexus.github.io/MODELLO/1.4.0 http://codehaus-plexus.github.io/modello/xsd/modello-1.4.0.xsd" + xsd.namespace="org:apache:maven:cache:domain"> cache-domain CacheDomain BuildInfoType 1.0.0+ extension.xml file.]]> - + + cacheImplementationVersion 1.0.0+ String - - - + + _final 1.0.0+ Boolean - - - + final + + hashFunction 1.0.0+ String - - - + + + buildTime + 1.0.0+ + Date + + buildServer 1.0.0+ String - - - - + + + scm + 1.0.0+ + + Scm + + + goals 1.0.0+ @@ -90,7 +100,7 @@ under the License. - + artifact 1.0.0+ @@ -99,109 +109,137 @@ under the License. - + + + attachedArtifacts + + ArtifactType + * + + + + + + executions + + CompletedExecutionType + * + + + + + projectsInputInfo + + ProjectsInputInfoType + + + + + + + + Scm + + + sourceBranch + String + + + revision + String + ArtifactType - + - + groupId - 1.0.0+ String - - + artifactId - 1.0.0+ String - - + version - 1.0.0+ String - - + classifier - 1.0.0+ String - - + type - 1.0.0+ String - - + scope - 1.0.0+ String - - + fileName - 1.0.0+ String - - + fileHash - 1.0.0+ String - - + - + + fileSize + long + + @@ -218,25 +256,80 @@ under the License. - + + + CompletedExecutionType + + + executionKey + String + + + mojoClassName + String + + + configuration + + PropertyValueType + * + + + + - + - + + PropertyValueType + + + value + String + + + name + String + + + tracked + Boolean + + + + + - + + ProjectsInputInfoType + + + checksum + String + + + item + + DigestItemType + * + + + + + + - - - - - - - - - - - - diff --git a/maven-core/src/main/mdo/cache-report.mdo b/maven-core/src/main/mdo/cache-report.mdo new file mode 100644 index 000000000000..d08194633954 --- /dev/null +++ b/maven-core/src/main/mdo/cache-report.mdo @@ -0,0 +1,108 @@ + + + + cache-report + CacheReport + + + + package + org.apache.maven.caching.domain + + + + + + CacheReportType + + + project + + ProjectReportType + * + + + + + + + + + + + + + + ProjectReportType + + + groupId + String + + + artifactId + String + + + checksum + String + + + checksumMatched + Boolean + + + lifecycleMatched + Boolean + + + pluginsMatched + Boolean + + + source + String + + + sharedToRemote + Boolean + + + url + String + + + + + + diff --git a/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java b/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java index 6c9b14c418aa..19c1de408a16 100644 --- a/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java +++ b/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java @@ -25,29 +25,29 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.jaxb.ArtifactType; -import org.apache.maven.caching.jaxb.BuildInfoType; -import org.apache.maven.caching.jaxb.CompletedExecutionType; -import org.apache.maven.caching.jaxb.DigestItemType; -import org.apache.maven.caching.jaxb.ProjectsInputInfoType; -import org.apache.maven.caching.jaxb.PropertyValueType; +import org.apache.maven.caching.domain.ArtifactType; +import org.apache.maven.caching.domain.BuildInfoType; +import org.apache.maven.caching.domain.CompletedExecutionType; +import org.apache.maven.caching.domain.DigestItemType; +import org.apache.maven.caching.domain.ProjectsInputInfoType; +import org.apache.maven.caching.domain.PropertyValueType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.XmlService; +import org.junit.Test; -import javax.xml.datatype.DatatypeFactory; import java.io.File; -import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.GregorianCalendar; - -import static org.apache.maven.caching.xml.BuildInfo.createGoals; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; public class BuildInfoTest { - // @Test + @Test public void name() throws Exception { XmlService xmlService = new XmlService(); @@ -64,16 +64,16 @@ public void name() throws Exception { artifact.setClassifier("c"); artifact.setScope("s"); artifact.setFileName("f"); - artifact.setFileSize(BigInteger.valueOf(123456)); + artifact.setFileSize(123456); artifact.setFileHash("456L"); BuildInfoType buildInfo = new BuildInfoType(); buildInfo.setCacheImplementationVersion("cacheImplementationVersion"); buildInfo.setBuildServer("server"); - buildInfo.setBuildTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar())); + buildInfo.setBuildTime(new Date()); buildInfo.setArtifact(artifact); buildInfo.setHashFunction("SHA-256"); - buildInfo.setGoals(createGoals(Lists.newArrayList("install"))); + buildInfo.setGoals(Lists.newArrayList("install")); final Artifact attachedArtifact = new DefaultArtifact("ag", "aa", "av", "as", "at", "ac", new DefaultArtifactHandler()); buildInfo.setAttachedArtifacts(BuildInfo.createAttachedArtifacts(Lists.newArrayList(attachedArtifact), HashFactory.XX.createAlgorithm())); buildInfo.setProjectsInputInfo(main); @@ -90,17 +90,14 @@ public void name() throws Exception { System.out.println(buildInfo1); } - private BuildInfoType.Executions createExecutions() { + private List createExecutions() { CompletedExecutionType execution = new CompletedExecutionType(); execution.setExecutionKey("execkey"); - execution.setConfiguration(new CompletedExecutionType.Configuration()); PropertyValueType property = new PropertyValueType(); property.setValue("value"); property.setName("key"); - execution.getConfiguration().getProperty().add(property); - BuildInfoType.Executions executions = new BuildInfoType.Executions(); - executions.getExecution().add(execution); - return executions; + execution.setConfiguration(new ArrayList<>(Arrays.asList(property))); + return new ArrayList<>(Arrays.asList(execution)); } private DigestItemType createItem(String pom, String s, String hash1) { From b6aab72d87105a47a60229dc597474f557c01fcb Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 5 Nov 2021 14:59:32 +0100 Subject: [PATCH 102/188] [MNG-7324] Use plurals in the schema, make sure it can read things correctly --- maven-core/pom.xml | 1 + .../maven/caching/PluginScanConfigImpl.java | 16 +- .../caching/checksum/MavenProjectInput.java | 6 +- .../maven/caching/hash/CloseableBuffer.java | 21 +- .../org/apache/maven/caching/hash/XXMM.java | 4 +- .../apache/maven/caching/xml/CacheConfig.java | 3 +- .../maven/caching/xml/CacheConfigImpl.java | 37 +- .../apache/maven/caching/xml/XmlService.java | 35 +- maven-core/src/main/mdo/cache-config.mdo | 61 +- maven-core/src/main/mdo/cache-diff.mdo | 2 +- maven-core/src/main/mdo/cache-report.mdo | 2 +- .../main/resources/cache-config-instance.xml | 112 --- .../src/main/resources/cache-config.xsd | 640 ------------------ .../src/main/resources/cache-domain.xsd | 187 ----- .../maven/caching/xml/CacheConfigTest.java | 8 +- .../caching/xml/cache-config-instance.xml | 160 +++++ .../caching/xml}/cache-domain-instance.xml | 0 17 files changed, 259 insertions(+), 1036 deletions(-) delete mode 100644 maven-core/src/main/resources/cache-config-instance.xml delete mode 100644 maven-core/src/main/resources/cache-config.xsd delete mode 100644 maven-core/src/main/resources/cache-domain.xsd create mode 100644 maven-core/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml rename maven-core/src/{main/resources => test/resources/org/apache/maven/caching/xml}/cache-domain-instance.xml (100%) diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 67a9bcb80922..e15a1ec8bbab 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -249,6 +249,7 @@ under the License. src/main/mdo/cache-diff.mdo src/main/mdo/cache-report.mdo + ${basedir}/target/generated-sources/modello diff --git a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java index e95342c2f1ed..1c5ea657ed0d 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java @@ -52,13 +52,13 @@ public boolean accept( String tagName ) // include or exclude is a choice element, could be only obe property set //noinspection ConstantConditions - final List includes = dto.getInclude(); + final List includes = dto.getIncludes(); if ( !includes.isEmpty() ) { return findTagScanProperties( tagName ) != null; } - return !contains( dto.getExclude(), tagName ); + return !contains( dto.getExcludes(), tagName ); } private boolean contains( List excludes, String tagName ) @@ -104,11 +104,11 @@ public PluginScanConfig mergeWith( final PluginScanConfig overrideConfig ) merged.setMode( dto.getMode() ); } - merged.getExclude().addAll( dto.getExclude() ); - merged.getExclude().addAll( override.getExclude() ); + merged.getExcludes().addAll( dto.getExcludes() ); + merged.getExcludes().addAll( override.getExcludes() ); - merged.getInclude().addAll( dto.getInclude() ); - merged.getInclude().addAll( override.getInclude() ); + merged.getIncludes().addAll( dto.getIncludes() ); + merged.getIncludes().addAll( override.getIncludes() ); return new PluginScanConfigImpl( merged ); } @@ -128,10 +128,10 @@ public DirScanConfigType dto() private ScanConfigProperties findTagScanProperties( String tagName ) { - ScanConfigProperties scanConfigProperties = findConfigByName( tagName, dto.getInclude() ); + ScanConfigProperties scanConfigProperties = findConfigByName( tagName, dto.getIncludes() ); if ( scanConfigProperties == null ) { - scanConfigProperties = findConfigByName( tagName, dto.getTagScanConfig() ); + scanConfigProperties = findConfigByName( tagName, dto.getTagScanConfigs() ); } return scanConfigProperties; } diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index ca78adaba6b0..56fbaedbdd26 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -33,6 +33,7 @@ import org.apache.maven.caching.ProjectUtils; import org.apache.maven.caching.RemoteArtifactsRepository; import org.apache.maven.caching.ScanConfigProperties; +import org.apache.maven.caching.domain.Exclude; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashChecksum; import org.apache.maven.caching.hash.HashFactory; @@ -179,9 +180,10 @@ public MavenProjectInput( MavenProject project, filteredOutPaths = new ArrayList<>( Arrays.asList( normalizedPath( build.getDirectory() ), // target by default normalizedPath( build.getOutputDirectory() ), normalizedPath( build.getTestOutputDirectory() ) ) ); - for ( String excludePath : config.getGlobalExcludePaths() ) + List excludes = config.getGlobalExcludePaths(); + for ( Exclude excludePath : excludes ) { - filteredOutPaths.add( Paths.get( excludePath ) ); + filteredOutPaths.add( Paths.get( excludePath.getValue() ) ); } for ( String propertyName : properties.stringPropertyNames() ) diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java b/maven-core/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java index 0fec3646ffa4..91acdf27b6d3 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java @@ -35,22 +35,21 @@ */ public class CloseableBuffer implements AutoCloseable { - /* Java 8 - private static final Cleaner CLEANER = doPrivileged((PrivilegedAction) () -> { - final boolean isOldJava = System.getProperty("java.specification.version", "9").startsWith("1."); - if (isOldJava) { - return DirectCleaner.isSupported() ? new DirectCleaner() : new NoopCleaner(); - } else { - return UnsafeCleaner.isSupported() ? new UnsafeCleaner() : new NoopCleaner(); - } - }); - */ + private static final Cleaner CLEANER = doPrivileged( new PrivilegedAction() { @Override public Cleaner run() { - return DirectCleaner.isSupported() ? new DirectCleaner() : new NoopCleaner(); + final String jsv = System.getProperty( "java.specification.version", "9" ); + if ( jsv.startsWith( "1." ) ) + { + return DirectCleaner.isSupported() ? new DirectCleaner() : new NoopCleaner(); + } + else + { + return UnsafeCleaner.isSupported() ? new UnsafeCleaner() : new NoopCleaner(); + } } } ); diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/XXMM.java b/maven-core/src/main/java/org/apache/maven/caching/hash/XXMM.java index 8e09299c247e..7afe2403ffbe 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/hash/XXMM.java +++ b/maven-core/src/main/java/org/apache/maven/caching/hash/XXMM.java @@ -57,8 +57,8 @@ private static class Algorithm extends XX.Algorithm @Override public byte[] hash( Path path ) throws IOException { - try ( FileChannel channel = FileChannel.open( path, - READ ); CloseableBuffer buffer = CloseableBuffer.mappedBuffer( channel, READ_ONLY ) ) + try ( FileChannel channel = FileChannel.open( path, READ ); + CloseableBuffer buffer = CloseableBuffer.mappedBuffer( channel, READ_ONLY ) ) { return toByteArray( XX.INSTANCE.hashBytes( buffer.getBuffer() ) ); } diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java index e07ce6a9b74e..a9dd950652eb 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java @@ -21,6 +21,7 @@ import org.apache.maven.caching.PluginScanConfig; import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; +import org.apache.maven.caching.domain.Exclude; import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.domain.Include; import org.apache.maven.caching.domain.PropertyNameType; @@ -65,7 +66,7 @@ public interface CacheConfig List getGlobalIncludePaths(); @Nonnull - List getGlobalExcludePaths(); + List getGlobalExcludePaths(); @Nonnull PluginScanConfig getPluginDirScanConfig( Plugin plugin ); diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 7946942aee63..137bcc669de4 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -27,6 +27,7 @@ import org.apache.maven.caching.PluginScanConfigImpl; import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; import org.apache.maven.caching.domain.AttachedOutputs; +import org.apache.maven.caching.domain.Exclude; import org.apache.maven.caching.domain.Include; import org.apache.maven.caching.domain.Local; import org.apache.maven.caching.domain.ProjectDiscoveryStrategy; @@ -190,7 +191,7 @@ public List getTrackedProperties( MojoExecution mojoExecuti final GoalReconciliationType reconciliationConfig = findReconciliationConfig( mojoExecution ); if ( reconciliationConfig != null ) { - return reconciliationConfig.getReconcile(); + return reconciliationConfig.getReconciles(); } else { @@ -224,7 +225,7 @@ private GoalReconciliationType findReconciliationConfig( MojoExecution mojoExecu return null; } - final List reconciliation = executionControl.getReconcile().getPlugin(); + final List reconciliation = executionControl.getReconcile().getPlugins(); for ( GoalReconciliationType goalReconciliationConfig : reconciliation ) { @@ -249,7 +250,7 @@ public List getLoggedProperties( MojoExecution mojoExecution ) final GoalReconciliationType reconciliationConfig = findReconciliationConfig( mojoExecution ); if ( reconciliationConfig != null ) { - return reconciliationConfig.getLog(); + return reconciliationConfig.getLogs(); } else { @@ -265,7 +266,7 @@ public List getNologProperties( MojoExecution mojoExecution ) final GoalReconciliationType reconciliationConfig = findReconciliationConfig( mojoExecution ); if ( reconciliationConfig != null ) { - return reconciliationConfig.getNolog(); + return reconciliationConfig.getNologs(); } else { @@ -282,7 +283,7 @@ public List getEffectivePomExcludeProperties( Plugin plugin ) if ( pluginConfig != null && pluginConfig.getEffectivePom() != null ) { - return pluginConfig.getEffectivePom().getExcludeProperty(); + return pluginConfig.getEffectivePom().getExcludeProperties(); } return Collections.emptyList(); } @@ -295,7 +296,7 @@ private PluginConfigurationScanType findPluginScanConfig( Plugin plugin ) return null; } - final List pluginConfigs = cacheConfig.getInput().getPlugin(); + final List pluginConfigs = cacheConfig.getInput().getPlugins(); for ( PluginConfigurationScanType pluginConfig : pluginConfigs ) { if ( isPluginMatch( plugin, pluginConfig ) ) @@ -338,7 +339,7 @@ public PluginScanConfig getExecutionDirScanConfig( Plugin plugin, PluginExecutio if ( pluginScanConfig != null ) { final ExecutionConfigurationScanType executionScanConfig = findExecutionScanConfig( exec, - pluginScanConfig.getExecution() ); + pluginScanConfig.getExecutions() ); if ( executionScanConfig != null && executionScanConfig.getDirScan() != null ) { return new PluginScanConfigImpl( executionScanConfig.getDirScan() ); @@ -353,7 +354,7 @@ private ExecutionConfigurationScanType findExecutionScanConfig( PluginExecution { for ( ExecutionConfigurationScanType executionScanConfig : scanConfigs ) { - if ( executionScanConfig.getExecId().contains( execution.getId() ) ) + if ( executionScanConfig.getExecIds().contains( execution.getId() ) ) { return executionScanConfig; } @@ -380,15 +381,15 @@ public String getDefaultGlob() public List getGlobalIncludePaths() { checkInitializedState(); - return cacheConfig.getInput().getGlobal().getInclude(); + return cacheConfig.getInput().getGlobal().getIncludes(); } @Nonnull @Override - public List getGlobalExcludePaths() + public List getGlobalExcludePaths() { checkInitializedState(); - return cacheConfig.getInput().getGlobal().getExclude(); + return cacheConfig.getInput().getGlobal().getExcludes(); } @Nonnull @@ -439,7 +440,7 @@ public boolean isForcedExecution( MojoExecution execution ) private boolean executionMatches( MojoExecution execution, ExecutablesType executablesType ) { - final List pluginConfigs = executablesType.getPlugin(); + final List pluginConfigs = executablesType.getPlugins(); for ( PluginSetType pluginConfig : pluginConfigs ) { if ( isPluginMatch( execution.getPlugin(), pluginConfig ) ) @@ -448,20 +449,20 @@ private boolean executionMatches( MojoExecution execution, ExecutablesType execu } } - final List executionIds = executablesType.getExecution(); + final List executionIds = executablesType.getExecutions(); for ( ExecutionIdsListType executionConfig : executionIds ) { - if ( isPluginMatch( execution.getPlugin(), executionConfig ) && executionConfig.getExecId().contains( + if ( isPluginMatch( execution.getPlugin(), executionConfig ) && executionConfig.getExecIds().contains( execution.getExecutionId() ) ) { return true; } } - final List pluginsGoalsList = executablesType.getGoals(); + final List pluginsGoalsList = executablesType.getGoalsLists(); for ( GoalsListType pluginGoals : pluginsGoalsList ) { - if ( isPluginMatch( execution.getPlugin(), pluginGoals ) && pluginGoals.getGoal().contains( + if ( isPluginMatch( execution.getPlugin(), pluginGoals ) && pluginGoals.getGoals().contains( execution.getGoal() ) ) { return true; @@ -536,7 +537,7 @@ public List getAttachedOutputs() { checkInitializedState(); final AttachedOutputs attachedOutputs = getConfiguration().getAttachedOutputs(); - return attachedOutputs == null ? Collections.emptyList() : attachedOutputs.getDirName(); + return attachedOutputs == null ? Collections.emptyList() : attachedOutputs.getDirNames(); } @Nonnull @@ -552,7 +553,7 @@ private List compileExcludePatterns() if ( cacheConfig.getOutput() != null && cacheConfig.getOutput().getExclude() != null ) { List patterns = new ArrayList<>(); - for ( String pattern : cacheConfig.getOutput().getExclude().getPattern() ) + for ( String pattern : cacheConfig.getOutput().getExclude().getPatterns() ) { patterns.add( Pattern.compile( pattern ) ); } diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java b/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java index f63ffe6c9cb5..6419c8f6ed75 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java @@ -38,6 +38,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; /** @@ -85,47 +86,33 @@ public byte[] toBytes( CacheReportType cacheReportType ) throws IOException public T fromFile( Class clazz, File file ) throws IOException, XmlPullParserException { - if ( clazz == BuildInfoType.class ) - { - return clazz.cast( new CacheDomainXpp3Reader().read( Files.newInputStream( file.toPath() ) ) ); - } - else if ( clazz == CacheType.class ) - { - return clazz.cast( new CacheConfigXpp3Reader().read( Files.newInputStream( file.toPath() ) ) ); - } - else if ( clazz == BuildDiffType.class ) - { - return clazz.cast( new CacheDiffXpp3Reader().read( Files.newInputStream( file.toPath() ) ) ); - } - else if ( clazz == CacheReportType.class ) - { - return clazz.cast( new CacheReportXpp3Reader().read( Files.newInputStream( file.toPath() ) ) ); - } - else - { - throw new IllegalArgumentException( "Unsupported type " + clazz ); - } + return fromInputStream( clazz, Files.newInputStream( file.toPath() ) ); } public T fromBytes( Class clazz, byte[] bytes ) + { + return fromInputStream( clazz, new ByteArrayInputStream( bytes ) ); + } + + public T fromInputStream( Class clazz, InputStream inputStream ) { try { if ( clazz == BuildInfoType.class ) { - return clazz.cast( new CacheDomainXpp3Reader().read( new ByteArrayInputStream( bytes ) ) ); + return clazz.cast( new CacheDomainXpp3Reader().read( inputStream ) ); } else if ( clazz == CacheType.class ) { - return clazz.cast( new CacheConfigXpp3Reader().read( new ByteArrayInputStream( bytes ) ) ); + return clazz.cast( new CacheConfigXpp3Reader().read( inputStream ) ); } else if ( clazz == BuildDiffType.class ) { - return clazz.cast( new CacheDiffXpp3Reader().read( new ByteArrayInputStream( bytes ) ) ); + return clazz.cast( new CacheDiffXpp3Reader().read( inputStream ) ); } else if ( clazz == CacheReportType.class ) { - return clazz.cast( new CacheReportXpp3Reader().read( new ByteArrayInputStream( bytes ) ) ); + return clazz.cast( new CacheReportXpp3Reader().read( inputStream ) ); } else { diff --git a/maven-core/src/main/mdo/cache-config.mdo b/maven-core/src/main/mdo/cache-config.mdo index dfd4bf651863..5160bb88a6db 100644 --- a/maven-core/src/main/mdo/cache-config.mdo +++ b/maven-core/src/main/mdo/cache-config.mdo @@ -76,7 +76,7 @@ under the License. --> - + CacheType @@ -320,7 +320,7 @@ under the License. - debug + debugs String * @@ -376,7 +376,7 @@ under the License. AttachedOutputs - dirName + dirNames String * @@ -445,7 +445,7 @@ under the License. Global input calculation rules applicable to all projects and plugins in the build - plugin + plugins PluginConfigurationScanType * @@ -520,7 +520,7 @@ under the License. Specifies plugin level rules of configuration processing in search of referenced source files - execution + executions ExecutionConfigurationScanType * @@ -548,7 +548,7 @@ under the License. EffectivePom - excludeProperty + excludeProperties String * @@ -583,7 +583,7 @@ under the License. ExecutionConfigurationScanType - execId + execIds String * @@ -694,7 +694,7 @@ under the License. DirScanConfigType - include + includes TagScanConfigType * @@ -703,7 +703,7 @@ under the License. properties will be takein in calculation (whitelist) - exclude + excludes TagNameType * @@ -711,7 +711,7 @@ under the License. Tag to exclude when scanning plugin configuration for input files (blacklist) - tagScanConfig + tagScanConfigs TagScanConfigType * @@ -769,7 +769,7 @@ under the License. OutputTypeExclude - pattern + patterns String * @@ -804,21 +804,30 @@ under the License. * - include + includes Include * - exclude + excludes - String + Exclude * + + Exclude + + + value + String + + + Include @@ -901,14 +910,14 @@ under the License. GoalIdType - reconcile + reconciles TrackedPropertyType * - log + logs PropertyNameType * @@ -916,7 +925,7 @@ under the License. Specify property which should be logged to build metadata for exploration - nolog + nologs PropertyNameType * @@ -1057,7 +1066,7 @@ under the License. Reconcile - plugin + plugins GoalReconciliationType * @@ -1113,7 +1122,7 @@ under the License. ExecutablesType - plugin + plugins PluginSetType * @@ -1121,7 +1130,7 @@ under the License. Specify which executions should run always if present in build regardless of cached status - execution + executions ExecutionIdsListType * @@ -1129,7 +1138,7 @@ under the License. Specify which executions should run always if present in build regardless of cached status - goals + goalsLists GoalsListType * @@ -1162,7 +1171,7 @@ under the License. CoordinatesBaseType - goal + goals String * @@ -1217,7 +1226,7 @@ under the License. CoordinatesBaseType - execId + execIds String * @@ -1250,11 +1259,11 @@ under the License. CoordinatesBaseType - + groupId String - + artifactId String @@ -1274,7 +1283,7 @@ under the License. TagNameType - + tagName String true diff --git a/maven-core/src/main/mdo/cache-diff.mdo b/maven-core/src/main/mdo/cache-diff.mdo index e2a9cfec34c9..d9c3d182ed1e 100644 --- a/maven-core/src/main/mdo/cache-diff.mdo +++ b/maven-core/src/main/mdo/cache-diff.mdo @@ -19,7 +19,7 @@ under the License. + xsd.namespace="org:apache:maven:cache:diff"> cache-diff CacheDiff + xsd.namespace="org:apache:maven:cache:report"> cache-report CacheReport - - - - - - - true - SHA-256 - true - - http://host:port - - - 3 - - - - - - - {*.java,*.groovy,*.yaml,*.svcd,*.proto,*assembly.xml,assembly*.xml,*logback.xml,*.vm,*.ini,*.jks,*.properties,*.sh,*.bat} - - src/ - pom.xml - - - - 111 - - - - - - - - 1 - 2 - - - - - - - - - .*-processes.*\.zip - - - - - - - aaa - - - install - - - deploy - - - deploy-local - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/maven-core/src/main/resources/cache-config.xsd b/maven-core/src/main/resources/cache-config.xsd deleted file mode 100644 index 69437d993300..000000000000 --- a/maven-core/src/main/resources/cache-config.xsd +++ /dev/null @@ -1,640 +0,0 @@ - - - - - - - - - - - - - - - - - - - Cached build metadata - - - - - - - - - - Configuration of major cache properties - - - - - - - Configuration for source code input files participating in checksum calculation - - - - - - - Configuration for output artifacts, it's needed if you want to explicitly include/exclude something from caching - - - - - - - Execution rules for plugins in cached mode. Defines which plugins should run always - - - - - - - - - - - - - - - - 64 bit XX family hashing. Fast, but higher probability of collisions - - - - - - - 64 bit XX family hashing, with usage of Memory Mapped Buffer - - - - - - - - - - - - - - Validate cache config and builds metadata against xsd. - - - - - - - Specifies how to identify belonging to a cached project then submodule is being build. - - - - - - - - Any project dependency this this version will be considered cache eligible and will - be processed cache aware - - - - - - - - - - - - - address of remote cache - - - - - - - - - Save output to remote cache. Recommended to enable on CI agents only. - - - - - - - - - - - - Directory name in build output directory to attach to cached artifacts - - - - - - - - - - - - - Maximum number of cached build per artifact in local cache. First created cache (the - oldest) is - evicted if breached. - - - - - - - - - - - - - Causes file hash is saved in build metadata - - - - - - - Causes effective pom info is saved in build metadata - - - - - - - - - - - - - - - Global input calculation rules applicable to all projects and plugins in the build - - - - - - - Plugin specific input calculation rules - - - - - - - - - - - - - - Effective pom calculation rules - - - - - - - - Plugin configuration property should be excluded from effective pom - calculation - - - - - - - - - - Specifies plugin level rules of configuration processing in search of referenced source - files - - - - - - - Specifies execution specific configuration processing in search of referenced source - files - - - - - - - - - - - - - - - Specifies rules of configuration processing in search of referenced source files - - - - - - - - ignore parent config or inherit/merge - - - - - - - - - Common attributes for scanning paths - - - - - - Should walk directory specified in property recursively or not - - - - - - - Glob to apply when scanning dir denoted by this property - - - - - - - - - - - - - - - - - - - Forces cache to treat property value as input and include in calculation. If set, only included - properties will be takein in calculation (whitelist) - - - - - - - - Tag to exclude when scanning plugin configuration for input files (blacklist) - - - - - - - Additional processing rules for non-blacklisted tags - - - - - - - - - - Ignore parent settings or inherit and merge - - - - - - - - - - - Scan directory accordingly to cache implementation - - - - - - - Skip directory - - - - - - - - - - - - - - Patterns to exclude output artifacts applicable to all projects in the build - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Specify property which should be reconciled against running build - - - - - - - Specify property which should be logged to build metadata for exploration - - - - - - - Specify property which should not be logged - - - - - - - - Controls if all plugin properties to be logged (true is default). All the properties logged - with respect to log/nolog children: - * true: logged all if no blacklists () and whitelists () specified on plugin - level - * false: logged only tracked and included by whitelists () on plugin level - - - - - - - - - - - - - Specify which plugin should run always if present in build regardless of cached status - - - - - - - Specify which executions/plugins/goals do not affect generated artifacts and do not affect build correctness. - If cached build lacks of ignorable executions only, it still could be reused. - Typically case is then cached build is produced with 'verify' and you locally you run 'install'. - Strictly speaking these are different builds but in most of cases you want this difference to be ignored - - - - - - - Specify which plugin should run always if present in build regardless of cached status - - - - - - - - Reconciliation rules for plugin properties which might be affected by command line - flags, etc - - - - - - - - Controls if all plugin properties to be logged (true is default). All the properties - logged with respect to children: - * logAll on plugin level overrides global value - * true: logged all if no blacklists () and whitelists () specified on - plugin level - * false: logged only tracked and included by whitelists () on plugin level - - - - - - - - - - - - - - - Specify which plugin should run always if present in build regardless of cached status - - - - - - - Specify which executions should run always if present in build regardless of cached status - - - - - - - Specify which goals should run always if present in build regardless of cached status - - - - - - - - - - - - - - Goals identification - - - - - - - - - - - - - - - - - - - - - - - - - Executions ids list with plugin identifier - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Specify which value denotes skipped execution in plugin config. - If active build skips execution (property set to skipValue) cache will allow such - discrepancy. - - - - - - - Manual value for reconciliation. Required to reconcile runtime only properties - - - - - - - - diff --git a/maven-core/src/main/resources/cache-domain.xsd b/maven-core/src/main/resources/cache-domain.xsd deleted file mode 100644 index c233ed46e463..000000000000 --- a/maven-core/src/main/resources/cache-domain.xsd +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java b/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java index b18752fd0594..c589181cf066 100644 --- a/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java +++ b/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java @@ -19,8 +19,10 @@ * under the License. */ +import org.apache.maven.caching.domain.CacheType; import org.junit.Test; +import java.io.InputStream; import java.nio.file.Path; import java.nio.file.Paths; @@ -28,8 +30,8 @@ public class CacheConfigTest { @Test public void testMU() { -// final Path path = Paths.get("W:\\dev\\abfx\\maven-cache-config.xml"); -// final CacheConfig cacheConfig = CacheConfig.fromFile(path.toFile()); -// System.out.println(cacheConfig.toString()); + InputStream is = getClass().getResourceAsStream( "cache-config-instance.xml" ); + final CacheType cacheConfig = new XmlService().fromInputStream( CacheType.class, is ); + System.out.println(cacheConfig.toString()); } } \ No newline at end of file diff --git a/maven-core/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml b/maven-core/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml new file mode 100644 index 000000000000..92e3ce767fa0 --- /dev/null +++ b/maven-core/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml @@ -0,0 +1,160 @@ + + + + + + + + true + SHA-256 + true + + http://host:port + + + 3 + + + + + + + {*.java,*.groovy,*.yaml,*.svcd,*.proto,*assembly.xml,assembly*.xml,*logback.xml,*.vm,*.ini,*.jks,*.properties,*.sh,*.bat} + + + src/ + + + pom.xml + + + + + + + 111 + + + + + + + + + + + + + + + 1 + 2 + + + + + + + + + + + + + + + .*-processes.*\.zip + + + + + + + + + + + + aaa + + + + + + + install + + + + + deploy + + + + + deploy-local + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-core/src/main/resources/cache-domain-instance.xml b/maven-core/src/test/resources/org/apache/maven/caching/xml/cache-domain-instance.xml similarity index 100% rename from maven-core/src/main/resources/cache-domain-instance.xml rename to maven-core/src/test/resources/org/apache/maven/caching/xml/cache-domain-instance.xml From 7c0c6173ddbaf2ce424a8dc52a3d2ac059bc6a21 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 5 Nov 2021 15:21:05 +0100 Subject: [PATCH 103/188] [MNG-7324] Allow more minimal config --- .../main/java/org/apache/maven/caching/xml/CacheConfigImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 137bcc669de4..df8eb26003fe 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -399,7 +399,7 @@ public MultimoduleDiscoveryStrategy getMultimoduleDiscoveryStrategy() checkInitializedState(); final ProjectDiscoveryStrategy projectDiscoveryStrategy = cacheConfig.getConfiguration().getProjectDiscoveryStrategy(); - if ( projectDiscoveryStrategy.getSpecificVersion() != null ) + if ( projectDiscoveryStrategy != null && projectDiscoveryStrategy.getSpecificVersion() != null ) { return new SentinelVersionStartegy( projectDiscoveryStrategy.getSpecificVersion() ); } From b145fd9add43eb454083662351cd18082a77953d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sat, 6 Nov 2021 18:39:53 +0100 Subject: [PATCH 104/188] [MNG-7324] remove now unused JAXB dependencies --- .../appended-resources/licenses/EDL-1.0.txt | 23 ------------- maven-core/pom.xml | 33 ------------------- pom.xml | 6 +++- 3 files changed, 5 insertions(+), 57 deletions(-) delete mode 100644 apache-maven/src/main/appended-resources/licenses/EDL-1.0.txt diff --git a/apache-maven/src/main/appended-resources/licenses/EDL-1.0.txt b/apache-maven/src/main/appended-resources/licenses/EDL-1.0.txt deleted file mode 100644 index 259e0377f30f..000000000000 --- a/apache-maven/src/main/appended-resources/licenses/EDL-1.0.txt +++ /dev/null @@ -1,23 +0,0 @@ -Eclipse Distribution License - v 1.0 -Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. - -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided -that the following conditions are met: - -- Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -- Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation and/or other materials provided -with the distribution. -- Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse -or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/maven-core/pom.xml b/maven-core/pom.xml index e15a1ec8bbab..45fa47a5af9d 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -159,17 +159,6 @@ under the License. zero-allocation-hashing 0.9 - - jakarta.xml.bind - jakarta.xml.bind-api - 2.3.3 - - - com.sun.xml.bind - jaxb-impl - 2.3.3 - runtime - com.github.albfernandez juniversalchardet @@ -284,28 +273,6 @@ under the License. - diff --git a/pom.xml b/pom.xml index d2bf50e677fc..e722bab36258 100644 --- a/pom.xml +++ b/pom.xml @@ -553,8 +553,12 @@ under the License. + src/main/appended-resources/licenses/CDDL-1.0.txt src/main/appended-resources/licenses/EPL-1.0.txt - src/main/appended-resources/licenses/unrecognized-javax.annotation-api-1.2.txt + src/main/appended-resources/licenses/MPL-1.1.txt + src/main/appended-resources/licenses/LGPL-3.0.txt + .editorconfig + **/*.iml From 3794fd92466156a0a53861ae419fa8f9dfac6d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Mon, 8 Nov 2021 21:43:03 +0100 Subject: [PATCH 105/188] [MNG-7324] update documentation --- Documentation/CACHE-HOWTO.md | 19 +++++----- Documentation/CACHE-PARAMETERS.md | 4 +-- Documentation/CACHE-REMOTE.md | 8 ++--- Documentation/CACHE.md | 44 ++++++++++++------------ Documentation/maven-cache-config.xml | 5 ++- maven-core/src/main/mdo/cache-config.mdo | 2 ++ maven-core/src/main/mdo/cache-domain.mdo | 4 ++- 7 files changed, 44 insertions(+), 42 deletions(-) diff --git a/Documentation/CACHE-HOWTO.md b/Documentation/CACHE-HOWTO.md index aa15f626af65..77d03ba07f19 100644 --- a/Documentation/CACHE-HOWTO.md +++ b/Documentation/CACHE-HOWTO.md @@ -17,18 +17,17 @@ ### Overview -Cache configuration provides you additional control over incremental maven behavior. Follow it step by step to +Cache configuration provides you additional control over incremental Maven behavior. Follow it step by step to understand how it works and figure out your optimal config ### Minimal config -Absolutely minimal config which enables incremental maven with local cache +Absolutely minimal config which enables incremental Maven with local cache ```xml - + true @@ -73,7 +72,7 @@ Add all the project specific source code files in ``. Scala in this case: ### Adding source directory for bespoke project layouts -In most of the cases incremental maven will recognize directories automatically by build introspection. If not, you can +In most of the cases incremental Maven will recognize directories automatically by build introspection. If not, you can add additional directories with ``. Also you can filter out undesirable dirs and files by using exclude tag ```xml @@ -134,7 +133,7 @@ Add `executionControl/runAlways` section ```xml + xsi:schemaLocation="org:apache:maven:cache:config:v1 http://maven.apache.org/xsd/cache-config-1.0.0.xsd"> ... @@ -157,7 +156,7 @@ Add `executionControl/runAlways` section ### I occasionally cached build with `-DskipTests=true` and tests do not run now -If you add command line flags to your build, they do not participate in effective pom - maven defers final value +If you add command line flags to your build, they do not participate in effective pom - Maven defers final value resolution to plugin runtime. To invalidate build if filed value is different in runtime, add reconciliation section to `executionControl`: @@ -180,7 +179,7 @@ to `executionControl`: Please notice `skipValue` attribute. It denotes value which forces skipped execution. Read `propertyName="skipTests" skipValue="true"` as if property skipTests has value true, plugin will skip execution If -you declare such value incremental maven will reuse appropriate full-build though technically they are different, but +you declare such value incremental Maven will reuse appropriate full-build though technically they are different, but because full-build is better it is safe to reuse ### How to renormalize line endings in working copy after committing .gitattributes (git 2.16+) @@ -201,4 +200,4 @@ git reset --hard ### I want to cache interim build and override it later with final version Solution: set `-Dremote.cache.save.final=true` to nodes which produce final builds. Such builds will not be overridden -and eventually will replace all interim builds \ No newline at end of file +and eventually will replace all interim builds diff --git a/Documentation/CACHE-PARAMETERS.md b/Documentation/CACHE-PARAMETERS.md index 7633ddbea158..12042c634076 100644 --- a/Documentation/CACHE-PARAMETERS.md +++ b/Documentation/CACHE-PARAMETERS.md @@ -26,8 +26,8 @@ This documents contains various configuration parameters supported by cache engi | `-Dremote.cache.configPath=true/false` | Location of cache configuration file | Cache config is not in default location | | `-Dremote.cache.enabled=true/false` | Remote cache and associated features disabled/enabled | To remove noise from logs then remote cache is not available | | `-Dremote.cache.save.enabled=true/false` | Remote cache save allowed or not | To designate nodes which allowed to push in remote shared cache | -| `-Dremote.cache.save.final=true/false` | Is it allowed or not to override produced cache | To ensure that reference build is not overriden by interim build | -| `-Dremote.cache.failFast=true/false` | Fail on the first module whcih cannot be restored from cache | Remote cache setup/tuning/troubleshooting | +| `-Dremote.cache.save.final=true/false` | Is it allowed or not to override produced cache | To ensure that reference build is not overridden by interim build | +| `-Dremote.cache.failFast=true/false` | Fail on the first module which cannot be restored from cache | Remote cache setup/tuning/troubleshooting | | `-Dremote.cache.baselineUrl=` | Location of baseline build for comparison | Remote cache setup/tuning/troubleshooting | ## Project level properties diff --git a/Documentation/CACHE-REMOTE.md b/Documentation/CACHE-REMOTE.md index f5fe38721d70..c89e5de19818 100644 --- a/Documentation/CACHE-REMOTE.md +++ b/Documentation/CACHE-REMOTE.md @@ -17,7 +17,7 @@ # Overview -This document describes generic approach to cache setup. The process require expertise in maven equivalent to expertise +This document describes generic approach to cache setup. The process require expertise in Maven equivalent to expertise required to author and Maven your project build, it implies good knowledge of both Maven and the project. Due to Maven model limitation the process is manual, but allows you to achieve sufficient control and transparency over caching logic. @@ -113,8 +113,8 @@ Once discrepancy between remote and local builds detected cache will fail with d in `target/incremental-maven` directory: ``` -* buildinfo-baseline-3c64673e23259e6f.xml - build specficiation from baseline build -* buildinfo-db43936e0666ce7.xml - build specification of locall build +* buildinfo-baseline-3c64673e23259e6f.xml - build specification from baseline build +* buildinfo-db43936e0666ce7.xml - build specification of local build * buildsdiff.xml - comparison report with list of discrepancies ``` @@ -242,7 +242,7 @@ relax consistency rules in favor of compatibility, remove property from tracked Current implementation doesn't support version changes between cache entries. It will result in cache invalidation for each new version. -To mitigate the issue please consider migrating off traditional maven release approach - try to use single version id in +To mitigate the issue please consider migrating off traditional Maven release approach - try to use single version id in project (eg `MY-PROJECT-LOCAL`). Such approach simplifies git branching workflow significantly. Deployment of artifacts with specific version from builds with cache is not supported yet. diff --git a/Documentation/CACHE.md b/Documentation/CACHE.md index 391becc7b5f7..7449ef5cc7ec 100644 --- a/Documentation/CACHE.md +++ b/Documentation/CACHE.md @@ -17,19 +17,19 @@ ## Overview -Idea of Incremental Maven is to specify module inputs and outputs and make them known to standard maven core. This +Idea of Incremental Maven is to specify module inputs and outputs and make them known to standard Maven core. This allows accurate analysis and determination of out-of-date build artifacts in the build dependencies graph. Making the dependency graph analysis deterministic leads to improvements in build times by avoiding re-building unnecessary modules. -Cache does not make any low-level interventions to build process and delegates actual build work to maven core. This -guarantees that build results are identical to results produced by standard maven and are fully reproducible. -To achieve accurate input and outputs calculation incremental maven combines automatic introspection +Cache does not make any low-level interventions to build process and delegates actual build work to Maven core. This +guarantees that build results are identical to results produced by standard Maven and are fully reproducible. +To achieve accurate input and outputs calculation incremental Maven combines automatic introspection of [project object model](https://maven.apache.org/pom.html#What_is_the_POM) in conjunction with configuration-driven rules for fine-grained content and execution control. For content analysis it digests based approach which is more reliable over widely used file timestamps in tools like Make or Apache Ant. Deterministic build state allows reliably cache even intermediate outputs of build and share them between teams using remote cache. Deterministic inputs calculation allows distributed and parallel builds running in heterogeneous environments (like cloud of build agents) -could efficiently reuse cached build artifacts. Therefore incremental maven is particularly well-suited for large maven +could efficiently reuse cached build artifacts. Therefore incremental Maven is particularly well-suited for large Maven projects that have significant number of small modules. Remote cache in conjunction with precise input identification effectively enables "change once - build once" approach. @@ -51,7 +51,7 @@ of today build with some tolerance (implementation, configuration and environmen ### Implementation insights -At very simple form, the incremental maven is essentially a hash function which takes maven project and produces hash +At very simple form, the incremental Maven is essentially a hash function which takes Maven project and produces hash code (checksum). Then hash value is used to fetch and restore build result. As with any hash, there could be collisions and instabilities. Collision could happen if the same hash produced from the different build states and will result in unintended reuse. Instability means that same input yields different hash sums @@ -79,7 +79,7 @@ verification it's still consumer's responsibility to verify final product qualit Given all the information above, the Incremental Maven is recommended to use in scenarios when productivity and performance are in priority. Typical cases are: -* Speedup CI. In conjunction with remote cache incremental maven could drastically reduce build times, validate pull +* Speedup CI. In conjunction with remote cache incremental Maven could drastically reduce build times, validate pull requests faster and reduce load on CI nodes * Speedup developer builds. By reusing cached builds developers could verify changes much faster and be more productive. No more `-DskipTests` and similar. @@ -92,35 +92,35 @@ This also allows you to validate cache correctness and reconcile cache outcomes ## Getting Started -To on-board incremental maven you need to complete several steps: +To on-board incremental Maven you need to complete several steps: -* Get incremental maven distribution -* Add cache config in .mvn +* Get incremental Maven distribution +* Add cache config in `.mvn` * Validate build results and iteratively adjust config to project specifics -* Migrate CI to incremental maven with remote cache (to get full benefit) - optional +* Migrate CI to incremental Maven with remote cache (to get full benefit) - optional -### Get incremental maven distribution +### Get incremental Maven distribution The recommended way is to add [Takari Maven Wrapper](https://github.com/takari/maven-wrapper) to your project. In that -case `maven-wrapper.properties` should reference the latest incremental maven distribution: +case `maven-wrapper.properties` should reference the latest incremental Maven distribution: ```properties distributionUrl=https://your-server/maven-incremental.zip wrapperUrl=https://your-server/maven-wrapper-0.5.5.jar ``` -Benefits of using maven wrapper are following: +Benefits of using Maven wrapper are following: * simple distribution across workstations and CI envs -* maven stays compatible to your branch +* Maven stays compatible to your branch * further upgrades are simplified significantly - If you refuse wrapper - then download, unzip and install it just as usual maven. Further it will be assumed you use - maven wrapper (`mvnw`) + If you refuse wrapper - then download, unzip and install it just as usual Maven. Further it will be assumed you use + Maven wrapper (`mvnw`) ### Adding cache config -Copy [default config](maven-cache-config.xml) and [xml schema](../maven-core/src/main/resources/cache-config.xsd) -to [.mvn](https://maven.apache.org/configure.html) dir of yor project. +Copy [default config `maven-cache-config.xml`](maven-cache-config.xml) +to [`.mvn/`](https://maven.apache.org/configure.html) dir of your project. To get overall understanding of cache machinery it is recommended to review the config and read comments. In typical scenario you need to adjust: @@ -135,15 +135,15 @@ See also: * [Remote cache setup](CACHE-REMOTE.md) - instruction how to setup shared cache * [Cache How-To](CACHE-HOWTO.md) - cookbook for frequently encountered questions * [Cache Parameters](CACHE-PARAMETERS.md) - description of supported parameters -* Attached [sample config file](maven-cache-config.xml) and elements annotations in xsd schema. (Ctrl+Q in idea should +* Attached [sample `maven-cache-config.xml` config file](maven-cache-config.xml) and elements annotations in xsd schema. (Ctrl+Q in idea should show annotations in popup) ### Adjusting cache config -Having incremental maven and the config in place you're all set. To run first cacheable build just +Having incremental Maven and the config in place you're all set. To run first cacheable build just execute: `mvnw clean install` -* Ensure that the config is picked up and incremental maven is picked up. Just check log output - you will notice cache +* Ensure that the config is picked up and incremental Maven is picked up. Just check log output - you will notice cache related output or initialization error message. * Navigate to your local repo directory - there should be sibling next to your local repo named `cache` * Find `buildinfo.xml` for typical module and review it. Ensure that diff --git a/Documentation/maven-cache-config.xml b/Documentation/maven-cache-config.xml index a2a7ad8ee1c3..12425fdf8939 100644 --- a/Documentation/maven-cache-config.xml +++ b/Documentation/maven-cache-config.xml @@ -15,9 +15,8 @@ See the License for the specific language governing permissions and limitations under the License. --> - + true diff --git a/maven-core/src/main/mdo/cache-config.mdo b/maven-core/src/main/mdo/cache-config.mdo index 5160bb88a6db..99cbec071149 100644 --- a/maven-core/src/main/mdo/cache-config.mdo +++ b/maven-core/src/main/mdo/cache-config.mdo @@ -19,6 +19,8 @@ under the License. cache-config CacheConfig diff --git a/maven-core/src/main/mdo/cache-domain.mdo b/maven-core/src/main/mdo/cache-domain.mdo index 43c353041ba8..44ccdd67ca6d 100644 --- a/maven-core/src/main/mdo/cache-domain.mdo +++ b/maven-core/src/main/mdo/cache-domain.mdo @@ -19,6 +19,8 @@ under the License. cache-domain CacheDomain @@ -35,7 +37,7 @@ under the License. BuildInfoType 1.0.0+ - extension.xml file.]]> + From f51f9147f762744d616700a4e644f5fc6683cee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Mon, 8 Nov 2021 22:02:06 +0100 Subject: [PATCH 106/188] [MNG-7324] split config/domain/diff/report to separate xml.* packages --- maven-core/pom.xml | 3 ++ .../maven/caching/ArtifactsRepository.java | 2 +- .../apache/maven/caching/CacheContext.java | 2 +- .../maven/caching/CacheControllerImpl.java | 20 +++++----- .../org/apache/maven/caching/CacheDiff.java | 14 +++---- .../caching/DefaultPluginScanConfig.java | 2 +- .../maven/caching/HttpRepositoryImpl.java | 8 ++-- .../caching/LocalArtifactsRepository.java | 2 +- .../maven/caching/LocalRepositoryImpl.java | 8 ++-- .../maven/caching/MojoExecutionManager.java | 4 +- .../maven/caching/PluginScanConfig.java | 2 +- .../maven/caching/PluginScanConfigImpl.java | 6 +-- .../apache/maven/caching/ProjectUtils.java | 2 +- .../caching/RemoteArtifactsRepository.java | 2 +- .../maven/caching/checksum/DigestUtils.java | 2 +- .../maven/caching/checksum/KeyUtils.java | 2 +- .../caching/checksum/MavenProjectInput.java | 11 +++--- .../apache/maven/caching/xml/BuildInfo.java | 10 ++--- .../apache/maven/caching/xml/CacheConfig.java | 8 ++-- .../maven/caching/xml/CacheConfigImpl.java | 38 +++++++++---------- .../apache/maven/caching/xml/DtoUtils.java | 10 ++--- .../apache/maven/caching/xml/XmlService.java | 24 ++++++------ maven-core/src/main/mdo/cache-config.mdo | 4 +- maven-core/src/main/mdo/cache-diff.mdo | 2 +- maven-core/src/main/mdo/cache-domain.mdo | 2 +- maven-core/src/main/mdo/cache-report.mdo | 2 +- .../apache/maven/caching/BuildInfoTest.java | 13 +++---- .../maven/caching/xml/CacheConfigTest.java | 4 +- 28 files changed, 104 insertions(+), 105 deletions(-) diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 45fa47a5af9d..b7105a410a50 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -218,7 +218,10 @@ under the License. 1.0.0 + src/main/mdo/cache-config.mdo src/main/mdo/cache-domain.mdo + src/main/mdo/cache-diff.mdo + src/main/mdo/cache-report.mdo diff --git a/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java b/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java index 968bae24b759..c72781d35407 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java +++ b/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java @@ -20,7 +20,7 @@ */ import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.domain.CacheReportType; +import org.apache.maven.caching.xml.report.CacheReportType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.execution.MavenSession; diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java b/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java index 49b552ea8742..39ed14cac74e 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.domain.ProjectsInputInfoType; +import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 05e56a5b9828..7d2137243260 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -31,18 +31,18 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.caching.checksum.KeyUtils; import org.apache.maven.caching.checksum.MavenProjectInput; -import org.apache.maven.caching.domain.Scm; +import org.apache.maven.caching.xml.config.PropertyNameType; +import org.apache.maven.caching.xml.config.TrackedPropertyType; +import org.apache.maven.caching.xml.diff.BuildDiffType; +import org.apache.maven.caching.xml.domain.ArtifactType; +import org.apache.maven.caching.xml.domain.CompletedExecutionType; +import org.apache.maven.caching.xml.domain.DigestItemType; +import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; +import org.apache.maven.caching.xml.domain.Scm; +import org.apache.maven.caching.xml.report.CacheReportType; +import org.apache.maven.caching.xml.report.ProjectReportType; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.domain.ArtifactType; -import org.apache.maven.caching.domain.BuildDiffType; -import org.apache.maven.caching.domain.CacheReportType; -import org.apache.maven.caching.domain.CompletedExecutionType; -import org.apache.maven.caching.domain.DigestItemType; -import org.apache.maven.caching.domain.ProjectReportType; -import org.apache.maven.caching.domain.ProjectsInputInfoType; -import org.apache.maven.caching.domain.PropertyNameType; -import org.apache.maven.caching.domain.TrackedPropertyType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java b/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java index 5808e1807426..a37872bed00e 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java @@ -22,13 +22,13 @@ import com.google.common.base.Optional; import com.google.common.collect.Sets; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.domain.BuildDiffType; -import org.apache.maven.caching.domain.BuildInfoType; -import org.apache.maven.caching.domain.CompletedExecutionType; -import org.apache.maven.caching.domain.DigestItemType; -import org.apache.maven.caching.domain.MismatchType; -import org.apache.maven.caching.domain.ProjectsInputInfoType; -import org.apache.maven.caching.domain.PropertyValueType; +import org.apache.maven.caching.xml.diff.BuildDiffType; +import org.apache.maven.caching.xml.diff.MismatchType; +import org.apache.maven.caching.xml.domain.BuildInfoType; +import org.apache.maven.caching.xml.domain.CompletedExecutionType; +import org.apache.maven.caching.xml.domain.DigestItemType; +import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; +import org.apache.maven.caching.xml.domain.PropertyValueType; import org.apache.maven.caching.xml.CacheConfig; import java.util.ArrayList; diff --git a/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java b/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java index 8229435ce65d..cff0375d3d1a 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java +++ b/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.domain.DirScanConfigType; +import org.apache.maven.caching.xml.config.DirScanConfigType; import javax.annotation.Nonnull; diff --git a/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java index 6747532bff42..09b5187b1da6 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java @@ -33,10 +33,10 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.maven.artifact.Artifact; import org.apache.maven.caching.checksum.MavenProjectInput; -import org.apache.maven.caching.domain.ArtifactType; -import org.apache.maven.caching.domain.BuildInfoType; -import org.apache.maven.caching.domain.CacheReportType; -import org.apache.maven.caching.domain.ProjectReportType; +import org.apache.maven.caching.xml.domain.ArtifactType; +import org.apache.maven.caching.xml.domain.BuildInfoType; +import org.apache.maven.caching.xml.report.CacheReportType; +import org.apache.maven.caching.xml.report.ProjectReportType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; diff --git a/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java b/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java index 280c2be5943c..8e9cb93b2dcc 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java +++ b/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java @@ -20,9 +20,9 @@ */ import com.google.common.base.Optional; -import org.apache.maven.caching.domain.ArtifactType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheSource; +import org.apache.maven.caching.xml.domain.ArtifactType; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; diff --git a/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java index 78d1d1ac994d..df7385fb04e5 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java @@ -31,14 +31,14 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.domain.ArtifactType; -import org.apache.maven.caching.domain.BuildInfoType; -import org.apache.maven.caching.domain.CacheReportType; -import org.apache.maven.caching.domain.Scm; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; import org.apache.maven.caching.xml.XmlService; +import org.apache.maven.caching.xml.domain.ArtifactType; +import org.apache.maven.caching.xml.domain.BuildInfoType; +import org.apache.maven.caching.xml.domain.Scm; +import org.apache.maven.caching.xml.report.CacheReportType; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.LegacySupport; diff --git a/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java b/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java index a6e193695b30..8d0daa843bbf 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java +++ b/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java @@ -20,11 +20,11 @@ */ import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.domain.CompletedExecutionType; -import org.apache.maven.caching.domain.TrackedPropertyType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; +import org.apache.maven.caching.xml.config.TrackedPropertyType; +import org.apache.maven.caching.xml.domain.CompletedExecutionType; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.MojoCheker; diff --git a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java index a3af7b6cda96..08ea117a4cb7 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java +++ b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.domain.DirScanConfigType; +import org.apache.maven.caching.xml.config.DirScanConfigType; import javax.annotation.Nonnull; diff --git a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java index 1c5ea657ed0d..c7031fa3f866 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java @@ -20,9 +20,9 @@ */ import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.domain.DirScanConfigType; -import org.apache.maven.caching.domain.TagNameType; -import org.apache.maven.caching.domain.TagScanConfigType; +import org.apache.maven.caching.xml.config.DirScanConfigType; +import org.apache.maven.caching.xml.config.TagNameType; +import org.apache.maven.caching.xml.config.TagScanConfigType; import javax.annotation.Nonnull; import java.util.List; diff --git a/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java b/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java index dbf9251ea61a..c3ea8643051f 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java @@ -25,7 +25,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.caching.domain.Scm; +import org.apache.maven.caching.xml.domain.Scm; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.internal.ProjectIndex; import org.apache.maven.lifecycle.internal.builder.BuilderCommon; diff --git a/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java b/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java index 826faf38ab8a..0112f79ff2d6 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java +++ b/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java @@ -20,8 +20,8 @@ */ import com.google.common.base.Optional; -import org.apache.maven.caching.domain.ArtifactType; import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.domain.ArtifactType; import org.apache.maven.project.MavenProject; import java.io.IOException; diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java index 0a156e2296a9..94fad20b1b3f 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java @@ -22,7 +22,7 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.maven.caching.hash.HashChecksum; -import org.apache.maven.caching.domain.DigestItemType; +import org.apache.maven.caching.xml.domain.DigestItemType; import org.mozilla.universalchardet.UniversalDetector; import java.io.IOException; diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java index 90da23e90f6d..355670c3b83e 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java @@ -21,7 +21,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.domain.ArtifactType; +import org.apache.maven.caching.xml.domain.ArtifactType; import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 56fbaedbdd26..1e5b56ab821c 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -19,7 +19,6 @@ * under the License. */ - import com.google.common.base.Optional; import com.google.common.collect.Iterables; import org.apache.commons.lang3.StringUtils; @@ -33,16 +32,16 @@ import org.apache.maven.caching.ProjectUtils; import org.apache.maven.caching.RemoteArtifactsRepository; import org.apache.maven.caching.ScanConfigProperties; -import org.apache.maven.caching.domain.Exclude; +import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashChecksum; -import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.domain.DigestItemType; -import org.apache.maven.caching.domain.Include; -import org.apache.maven.caching.domain.ProjectsInputInfoType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; +import org.apache.maven.caching.xml.config.Exclude; +import org.apache.maven.caching.xml.config.Include; +import org.apache.maven.caching.xml.domain.DigestItemType; +import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.internal.ProjectIndex; import org.apache.maven.model.Build; diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java b/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java index 452811e6f79c..45cd1a708fcb 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java @@ -24,11 +24,11 @@ import org.apache.maven.caching.ProjectUtils; import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.hash.HashAlgorithm; -import org.apache.maven.caching.domain.ArtifactType; -import org.apache.maven.caching.domain.BuildInfoType; -import org.apache.maven.caching.domain.CompletedExecutionType; -import org.apache.maven.caching.domain.DigestItemType; -import org.apache.maven.caching.domain.ProjectsInputInfoType; +import org.apache.maven.caching.xml.domain.ArtifactType; +import org.apache.maven.caching.xml.domain.BuildInfoType; +import org.apache.maven.caching.xml.domain.CompletedExecutionType; +import org.apache.maven.caching.xml.domain.DigestItemType; +import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecution; import org.codehaus.plexus.logging.Logger; diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java index a9dd950652eb..7d90cc1fea73 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java @@ -21,11 +21,11 @@ import org.apache.maven.caching.PluginScanConfig; import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; -import org.apache.maven.caching.domain.Exclude; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.domain.Include; -import org.apache.maven.caching.domain.PropertyNameType; -import org.apache.maven.caching.domain.TrackedPropertyType; +import org.apache.maven.caching.xml.config.Exclude; +import org.apache.maven.caching.xml.config.Include; +import org.apache.maven.caching.xml.config.PropertyNameType; +import org.apache.maven.caching.xml.config.TrackedPropertyType; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index df8eb26003fe..398ef511dd0a 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -26,26 +26,26 @@ import org.apache.maven.caching.PluginScanConfig; import org.apache.maven.caching.PluginScanConfigImpl; import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; -import org.apache.maven.caching.domain.AttachedOutputs; -import org.apache.maven.caching.domain.Exclude; -import org.apache.maven.caching.domain.Include; -import org.apache.maven.caching.domain.Local; -import org.apache.maven.caching.domain.ProjectDiscoveryStrategy; -import org.apache.maven.caching.domain.Remote; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.domain.CacheType; -import org.apache.maven.caching.domain.ConfigurationType; -import org.apache.maven.caching.domain.CoordinatesBaseType; -import org.apache.maven.caching.domain.ExecutablesType; -import org.apache.maven.caching.domain.ExecutionConfigurationScanType; -import org.apache.maven.caching.domain.ExecutionControlType; -import org.apache.maven.caching.domain.ExecutionIdsListType; -import org.apache.maven.caching.domain.GoalReconciliationType; -import org.apache.maven.caching.domain.GoalsListType; -import org.apache.maven.caching.domain.PluginConfigurationScanType; -import org.apache.maven.caching.domain.PluginSetType; -import org.apache.maven.caching.domain.PropertyNameType; -import org.apache.maven.caching.domain.TrackedPropertyType; +import org.apache.maven.caching.xml.config.AttachedOutputs; +import org.apache.maven.caching.xml.config.Exclude; +import org.apache.maven.caching.xml.config.Include; +import org.apache.maven.caching.xml.config.Local; +import org.apache.maven.caching.xml.config.ProjectDiscoveryStrategy; +import org.apache.maven.caching.xml.config.Remote; +import org.apache.maven.caching.xml.config.CacheType; +import org.apache.maven.caching.xml.config.ConfigurationType; +import org.apache.maven.caching.xml.config.CoordinatesBaseType; +import org.apache.maven.caching.xml.config.ExecutablesType; +import org.apache.maven.caching.xml.config.ExecutionConfigurationScanType; +import org.apache.maven.caching.xml.config.ExecutionControlType; +import org.apache.maven.caching.xml.config.ExecutionIdsListType; +import org.apache.maven.caching.xml.config.GoalReconciliationType; +import org.apache.maven.caching.xml.config.GoalsListType; +import org.apache.maven.caching.xml.config.PluginConfigurationScanType; +import org.apache.maven.caching.xml.config.PluginSetType; +import org.apache.maven.caching.xml.config.PropertyNameType; +import org.apache.maven.caching.xml.config.TrackedPropertyType; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java b/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java index 7bd2d2b2dc2f..7938d9bfe99e 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java @@ -23,11 +23,11 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.caching.ProjectUtils; -import org.apache.maven.caching.domain.ArtifactType; -import org.apache.maven.caching.domain.CompletedExecutionType; -import org.apache.maven.caching.domain.DigestItemType; -import org.apache.maven.caching.domain.PropertyValueType; -import org.apache.maven.caching.domain.TrackedPropertyType; +import org.apache.maven.caching.xml.config.TrackedPropertyType; +import org.apache.maven.caching.xml.domain.ArtifactType; +import org.apache.maven.caching.xml.domain.CompletedExecutionType; +import org.apache.maven.caching.xml.domain.DigestItemType; +import org.apache.maven.caching.xml.domain.PropertyValueType; import org.apache.maven.model.Dependency; import javax.annotation.Nonnull; diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java b/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java index 6419c8f6ed75..5d62ecbd68a0 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java @@ -19,18 +19,18 @@ * under the License. */ -import org.apache.maven.caching.domain.CacheType; -import org.apache.maven.caching.domain.io.xpp3.CacheConfigXpp3Reader; -import org.apache.maven.caching.domain.io.xpp3.CacheConfigXpp3Writer; -import org.apache.maven.caching.domain.io.xpp3.CacheDiffXpp3Reader; -import org.apache.maven.caching.domain.io.xpp3.CacheDiffXpp3Writer; -import org.apache.maven.caching.domain.io.xpp3.CacheDomainXpp3Reader; -import org.apache.maven.caching.domain.BuildDiffType; -import org.apache.maven.caching.domain.BuildInfoType; -import org.apache.maven.caching.domain.CacheReportType; -import org.apache.maven.caching.domain.io.xpp3.CacheDomainXpp3Writer; -import org.apache.maven.caching.domain.io.xpp3.CacheReportXpp3Reader; -import org.apache.maven.caching.domain.io.xpp3.CacheReportXpp3Writer; +import org.apache.maven.caching.xml.config.CacheType; +import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Reader; +import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Writer; +import org.apache.maven.caching.xml.diff.BuildDiffType; +import org.apache.maven.caching.xml.diff.io.xpp3.CacheDiffXpp3Reader; +import org.apache.maven.caching.xml.diff.io.xpp3.CacheDiffXpp3Writer; +import org.apache.maven.caching.xml.domain.BuildInfoType; +import org.apache.maven.caching.xml.domain.io.xpp3.CacheDomainXpp3Reader; +import org.apache.maven.caching.xml.domain.io.xpp3.CacheDomainXpp3Writer; +import org.apache.maven.caching.xml.report.CacheReportType; +import org.apache.maven.caching.xml.report.io.xpp3.CacheReportXpp3Reader; +import org.apache.maven.caching.xml.report.io.xpp3.CacheReportXpp3Writer; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; diff --git a/maven-core/src/main/mdo/cache-config.mdo b/maven-core/src/main/mdo/cache-config.mdo index 99cbec071149..a9e9f92bf208 100644 --- a/maven-core/src/main/mdo/cache-config.mdo +++ b/maven-core/src/main/mdo/cache-config.mdo @@ -24,13 +24,13 @@ under the License. xsd.namespace="org:apache:maven:cache:config"> cache-config CacheConfig - .mvn/maven-cache-config.xml ]]> package - org.apache.maven.caching.domain + org.apache.maven.caching.xml.config diff --git a/maven-core/src/main/mdo/cache-diff.mdo b/maven-core/src/main/mdo/cache-diff.mdo index d9c3d182ed1e..5265c54ae11a 100644 --- a/maven-core/src/main/mdo/cache-diff.mdo +++ b/maven-core/src/main/mdo/cache-diff.mdo @@ -27,7 +27,7 @@ under the License. package - org.apache.maven.caching.domain + org.apache.maven.caching.xml.diff diff --git a/maven-core/src/main/mdo/cache-domain.mdo b/maven-core/src/main/mdo/cache-domain.mdo index 44ccdd67ca6d..428f5288c11d 100644 --- a/maven-core/src/main/mdo/cache-domain.mdo +++ b/maven-core/src/main/mdo/cache-domain.mdo @@ -29,7 +29,7 @@ under the License. package - org.apache.maven.caching.domain + org.apache.maven.caching.xml.domain diff --git a/maven-core/src/main/mdo/cache-report.mdo b/maven-core/src/main/mdo/cache-report.mdo index 3e7b8f3b9a1e..474683d8d2f1 100644 --- a/maven-core/src/main/mdo/cache-report.mdo +++ b/maven-core/src/main/mdo/cache-report.mdo @@ -27,7 +27,7 @@ under the License. package - org.apache.maven.caching.domain + org.apache.maven.caching.xml.report diff --git a/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java b/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java index 19c1de408a16..aa6708b36538 100644 --- a/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java +++ b/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java @@ -19,18 +19,17 @@ * under the License. */ - import com.google.common.collect.Lists; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.domain.ArtifactType; -import org.apache.maven.caching.domain.BuildInfoType; -import org.apache.maven.caching.domain.CompletedExecutionType; -import org.apache.maven.caching.domain.DigestItemType; -import org.apache.maven.caching.domain.ProjectsInputInfoType; -import org.apache.maven.caching.domain.PropertyValueType; +import org.apache.maven.caching.xml.domain.ArtifactType; +import org.apache.maven.caching.xml.domain.BuildInfoType; +import org.apache.maven.caching.xml.domain.CompletedExecutionType; +import org.apache.maven.caching.xml.domain.DigestItemType; +import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; +import org.apache.maven.caching.xml.domain.PropertyValueType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.XmlService; import org.junit.Test; diff --git a/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java b/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java index c589181cf066..8b81a78dfdbc 100644 --- a/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java +++ b/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java @@ -19,12 +19,10 @@ * under the License. */ -import org.apache.maven.caching.domain.CacheType; +import org.apache.maven.caching.xml.config.CacheType; import org.junit.Test; import java.io.InputStream; -import java.nio.file.Path; -import java.nio.file.Paths; public class CacheConfigTest { From 2c11bbff79f6d1e97ccb2308288e9fe5a3c9f1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Mon, 8 Nov 2021 23:38:59 +0100 Subject: [PATCH 107/188] [MNG-7324] rename domain to buildinfo and diff to buildsdiff --- maven-core/pom.xml | 8 ++++---- .../apache/maven/caching/CacheContext.java | 2 +- .../maven/caching/CacheControllerImpl.java | 12 +++++------ .../org/apache/maven/caching/CacheDiff.java | 14 ++++++------- .../maven/caching/HttpRepositoryImpl.java | 4 ++-- .../caching/LocalArtifactsRepository.java | 2 +- .../maven/caching/LocalRepositoryImpl.java | 6 +++--- .../maven/caching/MojoExecutionManager.java | 2 +- .../apache/maven/caching/ProjectUtils.java | 2 +- .../caching/RemoteArtifactsRepository.java | 2 +- .../maven/caching/checksum/DigestUtils.java | 2 +- .../maven/caching/checksum/KeyUtils.java | 2 +- .../caching/checksum/MavenProjectInput.java | 4 ++-- .../apache/maven/caching/xml/BuildInfo.java | 10 +++++----- .../apache/maven/caching/xml/DtoUtils.java | 8 ++++---- .../apache/maven/caching/xml/XmlService.java | 20 +++++++++---------- .../{cache-domain.mdo => cache-buildinfo.mdo} | 12 +++++------ .../{cache-diff.mdo => cache-buildsdiff.mdo} | 10 +++++----- maven-core/src/main/mdo/cache-report.mdo | 2 +- .../apache/maven/caching/BuildInfoTest.java | 12 +++++------ 20 files changed, 67 insertions(+), 69 deletions(-) rename maven-core/src/main/mdo/{cache-domain.mdo => cache-buildinfo.mdo} (97%) rename maven-core/src/main/mdo/{cache-diff.mdo => cache-buildsdiff.mdo} (92%) diff --git a/maven-core/pom.xml b/maven-core/pom.xml index b7105a410a50..56e585d70933 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -218,9 +218,9 @@ under the License. 1.0.0 + src/main/mdo/cache-buildinfo.mdo + src/main/mdo/cache-buildsdiff.mdo src/main/mdo/cache-config.mdo - src/main/mdo/cache-domain.mdo - src/main/mdo/cache-diff.mdo src/main/mdo/cache-report.mdo @@ -236,9 +236,9 @@ under the License. 1.0.0 + src/main/mdo/cache-buildinfo.mdo + src/main/mdo/cache-buildsdiff.mdo src/main/mdo/cache-config.mdo - src/main/mdo/cache-domain.mdo - src/main/mdo/cache-diff.mdo src/main/mdo/cache-report.mdo ${basedir}/target/generated-sources/modello diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java b/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java index 39ed14cac74e..d485687178d0 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; +import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfoType; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 7d2137243260..eac5feb2662a 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -31,14 +31,14 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.caching.checksum.KeyUtils; import org.apache.maven.caching.checksum.MavenProjectInput; +import org.apache.maven.caching.xml.buildinfo.ArtifactType; +import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; +import org.apache.maven.caching.xml.buildinfo.DigestItemType; +import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfoType; +import org.apache.maven.caching.xml.buildinfo.Scm; +import org.apache.maven.caching.xml.buildsdiff.BuildDiffType; import org.apache.maven.caching.xml.config.PropertyNameType; import org.apache.maven.caching.xml.config.TrackedPropertyType; -import org.apache.maven.caching.xml.diff.BuildDiffType; -import org.apache.maven.caching.xml.domain.ArtifactType; -import org.apache.maven.caching.xml.domain.CompletedExecutionType; -import org.apache.maven.caching.xml.domain.DigestItemType; -import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; -import org.apache.maven.caching.xml.domain.Scm; import org.apache.maven.caching.xml.report.CacheReportType; import org.apache.maven.caching.xml.report.ProjectReportType; import org.apache.maven.caching.hash.HashAlgorithm; diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java b/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java index a37872bed00e..29e18d2fea4a 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java @@ -22,13 +22,13 @@ import com.google.common.base.Optional; import com.google.common.collect.Sets; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.xml.diff.BuildDiffType; -import org.apache.maven.caching.xml.diff.MismatchType; -import org.apache.maven.caching.xml.domain.BuildInfoType; -import org.apache.maven.caching.xml.domain.CompletedExecutionType; -import org.apache.maven.caching.xml.domain.DigestItemType; -import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; -import org.apache.maven.caching.xml.domain.PropertyValueType; +import org.apache.maven.caching.xml.buildinfo.BuildInfoType; +import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; +import org.apache.maven.caching.xml.buildinfo.DigestItemType; +import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfoType; +import org.apache.maven.caching.xml.buildinfo.PropertyValueType; +import org.apache.maven.caching.xml.buildsdiff.BuildDiffType; +import org.apache.maven.caching.xml.buildsdiff.MismatchType; import org.apache.maven.caching.xml.CacheConfig; import java.util.ArrayList; diff --git a/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java index 09b5187b1da6..d32460da07fd 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java @@ -33,8 +33,8 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.maven.artifact.Artifact; import org.apache.maven.caching.checksum.MavenProjectInput; -import org.apache.maven.caching.xml.domain.ArtifactType; -import org.apache.maven.caching.xml.domain.BuildInfoType; +import org.apache.maven.caching.xml.buildinfo.ArtifactType; +import org.apache.maven.caching.xml.buildinfo.BuildInfoType; import org.apache.maven.caching.xml.report.CacheReportType; import org.apache.maven.caching.xml.report.ProjectReportType; import org.apache.maven.caching.xml.BuildInfo; diff --git a/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java b/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java index 8e9cb93b2dcc..c646aa76c0f7 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java +++ b/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java @@ -22,7 +22,7 @@ import com.google.common.base.Optional; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheSource; -import org.apache.maven.caching.xml.domain.ArtifactType; +import org.apache.maven.caching.xml.buildinfo.ArtifactType; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; diff --git a/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java index df7385fb04e5..a0fbcbe1e528 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java +++ b/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java @@ -35,9 +35,9 @@ import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.caching.xml.domain.ArtifactType; -import org.apache.maven.caching.xml.domain.BuildInfoType; -import org.apache.maven.caching.xml.domain.Scm; +import org.apache.maven.caching.xml.buildinfo.ArtifactType; +import org.apache.maven.caching.xml.buildinfo.BuildInfoType; +import org.apache.maven.caching.xml.buildinfo.Scm; import org.apache.maven.caching.xml.report.CacheReportType; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; diff --git a/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java b/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java index 8d0daa843bbf..84efff4c5945 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java +++ b/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java @@ -24,7 +24,7 @@ import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; import org.apache.maven.caching.xml.config.TrackedPropertyType; -import org.apache.maven.caching.xml.domain.CompletedExecutionType; +import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.MojoCheker; diff --git a/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java b/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java index c3ea8643051f..a6bdd7a6b958 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java @@ -25,7 +25,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.caching.xml.domain.Scm; +import org.apache.maven.caching.xml.buildinfo.Scm; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.internal.ProjectIndex; import org.apache.maven.lifecycle.internal.builder.BuilderCommon; diff --git a/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java b/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java index 0112f79ff2d6..551c27d0b557 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java +++ b/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java @@ -21,7 +21,7 @@ import com.google.common.base.Optional; import org.apache.maven.caching.xml.BuildInfo; -import org.apache.maven.caching.xml.domain.ArtifactType; +import org.apache.maven.caching.xml.buildinfo.ArtifactType; import org.apache.maven.project.MavenProject; import java.io.IOException; diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java index 94fad20b1b3f..6973f82e9542 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java @@ -22,7 +22,7 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.maven.caching.hash.HashChecksum; -import org.apache.maven.caching.xml.domain.DigestItemType; +import org.apache.maven.caching.xml.buildinfo.DigestItemType; import org.mozilla.universalchardet.UniversalDetector; import java.io.IOException; diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java index 355670c3b83e..a0075e071589 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java @@ -21,7 +21,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.xml.domain.ArtifactType; +import org.apache.maven.caching.xml.buildinfo.ArtifactType; import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 1e5b56ab821c..089e02de9988 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -38,10 +38,10 @@ import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; +import org.apache.maven.caching.xml.buildinfo.DigestItemType; +import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfoType; import org.apache.maven.caching.xml.config.Exclude; import org.apache.maven.caching.xml.config.Include; -import org.apache.maven.caching.xml.domain.DigestItemType; -import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.internal.ProjectIndex; import org.apache.maven.model.Build; diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java b/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java index 45cd1a708fcb..f0cf3c7c7b6d 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java @@ -24,11 +24,11 @@ import org.apache.maven.caching.ProjectUtils; import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.hash.HashAlgorithm; -import org.apache.maven.caching.xml.domain.ArtifactType; -import org.apache.maven.caching.xml.domain.BuildInfoType; -import org.apache.maven.caching.xml.domain.CompletedExecutionType; -import org.apache.maven.caching.xml.domain.DigestItemType; -import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; +import org.apache.maven.caching.xml.buildinfo.ArtifactType; +import org.apache.maven.caching.xml.buildinfo.BuildInfoType; +import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; +import org.apache.maven.caching.xml.buildinfo.DigestItemType; +import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfoType; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecution; import org.codehaus.plexus.logging.Logger; diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java b/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java index 7938d9bfe99e..d44ab3753584 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java @@ -23,11 +23,11 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.caching.ProjectUtils; +import org.apache.maven.caching.xml.buildinfo.ArtifactType; +import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; +import org.apache.maven.caching.xml.buildinfo.DigestItemType; +import org.apache.maven.caching.xml.buildinfo.PropertyValueType; import org.apache.maven.caching.xml.config.TrackedPropertyType; -import org.apache.maven.caching.xml.domain.ArtifactType; -import org.apache.maven.caching.xml.domain.CompletedExecutionType; -import org.apache.maven.caching.xml.domain.DigestItemType; -import org.apache.maven.caching.xml.domain.PropertyValueType; import org.apache.maven.model.Dependency; import javax.annotation.Nonnull; diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java b/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java index 5d62ecbd68a0..44bd917cc7da 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java +++ b/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java @@ -22,12 +22,12 @@ import org.apache.maven.caching.xml.config.CacheType; import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Reader; import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Writer; -import org.apache.maven.caching.xml.diff.BuildDiffType; -import org.apache.maven.caching.xml.diff.io.xpp3.CacheDiffXpp3Reader; -import org.apache.maven.caching.xml.diff.io.xpp3.CacheDiffXpp3Writer; -import org.apache.maven.caching.xml.domain.BuildInfoType; -import org.apache.maven.caching.xml.domain.io.xpp3.CacheDomainXpp3Reader; -import org.apache.maven.caching.xml.domain.io.xpp3.CacheDomainXpp3Writer; +import org.apache.maven.caching.xml.buildinfo.BuildInfoType; +import org.apache.maven.caching.xml.buildinfo.io.xpp3.CacheBuildInfoXpp3Reader; +import org.apache.maven.caching.xml.buildinfo.io.xpp3.CacheBuildInfoXpp3Writer; +import org.apache.maven.caching.xml.buildsdiff.BuildDiffType; +import org.apache.maven.caching.xml.buildsdiff.io.xpp3.CacheBuildsDiffXpp3Reader; +import org.apache.maven.caching.xml.buildsdiff.io.xpp3.CacheBuildsDiffXpp3Writer; import org.apache.maven.caching.xml.report.CacheReportType; import org.apache.maven.caching.xml.report.io.xpp3.CacheReportXpp3Reader; import org.apache.maven.caching.xml.report.io.xpp3.CacheReportXpp3Writer; @@ -61,7 +61,7 @@ public byte[] toBytes( BuildInfoType buildInfo ) throws IOException { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { - new CacheDomainXpp3Writer().write( baos, buildInfo ); + new CacheBuildInfoXpp3Writer().write( baos, buildInfo ); return baos.toByteArray(); } } @@ -70,7 +70,7 @@ public byte[] toBytes( BuildDiffType diff ) throws IOException { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { - new CacheDiffXpp3Writer().write( baos, diff ); + new CacheBuildsDiffXpp3Writer().write( baos, diff ); return baos.toByteArray(); } } @@ -100,7 +100,7 @@ public T fromInputStream( Class clazz, InputStream inputStream ) { if ( clazz == BuildInfoType.class ) { - return clazz.cast( new CacheDomainXpp3Reader().read( inputStream ) ); + return clazz.cast( new CacheBuildInfoXpp3Reader().read( inputStream ) ); } else if ( clazz == CacheType.class ) { @@ -108,7 +108,7 @@ else if ( clazz == CacheType.class ) } else if ( clazz == BuildDiffType.class ) { - return clazz.cast( new CacheDiffXpp3Reader().read( inputStream ) ); + return clazz.cast( new CacheBuildsDiffXpp3Reader().read( inputStream ) ); } else if ( clazz == CacheReportType.class ) { diff --git a/maven-core/src/main/mdo/cache-domain.mdo b/maven-core/src/main/mdo/cache-buildinfo.mdo similarity index 97% rename from maven-core/src/main/mdo/cache-domain.mdo rename to maven-core/src/main/mdo/cache-buildinfo.mdo index 428f5288c11d..0659d76256d1 100644 --- a/maven-core/src/main/mdo/cache-domain.mdo +++ b/maven-core/src/main/mdo/cache-buildinfo.mdo @@ -19,17 +19,15 @@ under the License. - cache-domain - CacheDomain - + cache-buildinfo + CacheBuildInfo + lookupinfo.xml or remote buildinfo.xml ]]> package - org.apache.maven.caching.xml.domain + org.apache.maven.caching.xml.buildinfo diff --git a/maven-core/src/main/mdo/cache-diff.mdo b/maven-core/src/main/mdo/cache-buildsdiff.mdo similarity index 92% rename from maven-core/src/main/mdo/cache-diff.mdo rename to maven-core/src/main/mdo/cache-buildsdiff.mdo index 5265c54ae11a..45bdfe1d0a8d 100644 --- a/maven-core/src/main/mdo/cache-diff.mdo +++ b/maven-core/src/main/mdo/cache-buildsdiff.mdo @@ -19,15 +19,15 @@ under the License. - cache-diff - CacheDiff - + cache-buildsdiff + CacheBuildsDiff + buildsdiff-${checksum}.xml ]]> package - org.apache.maven.caching.xml.diff + org.apache.maven.caching.xml.buildsdiff diff --git a/maven-core/src/main/mdo/cache-report.mdo b/maven-core/src/main/mdo/cache-report.mdo index 474683d8d2f1..fed8d24f5472 100644 --- a/maven-core/src/main/mdo/cache-report.mdo +++ b/maven-core/src/main/mdo/cache-report.mdo @@ -22,7 +22,7 @@ under the License. xsd.namespace="org:apache:maven:cache:report"> cache-report CacheReport - cache-report.xml ]]> diff --git a/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java b/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java index aa6708b36538..e05516884877 100644 --- a/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java +++ b/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java @@ -24,12 +24,12 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.xml.domain.ArtifactType; -import org.apache.maven.caching.xml.domain.BuildInfoType; -import org.apache.maven.caching.xml.domain.CompletedExecutionType; -import org.apache.maven.caching.xml.domain.DigestItemType; -import org.apache.maven.caching.xml.domain.ProjectsInputInfoType; -import org.apache.maven.caching.xml.domain.PropertyValueType; +import org.apache.maven.caching.xml.buildinfo.ArtifactType; +import org.apache.maven.caching.xml.buildinfo.BuildInfoType; +import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; +import org.apache.maven.caching.xml.buildinfo.DigestItemType; +import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfoType; +import org.apache.maven.caching.xml.buildinfo.PropertyValueType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.XmlService; import org.junit.Test; From 0a6f1d3d2e864b1eb0d84e3bbb929560aba6d483 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 8 Nov 2021 17:32:20 +0100 Subject: [PATCH 108/188] [MNG-7321] Move caching in its own module --- maven-caching/pom.xml | 104 +++ .../maven/caching/ArtifactsRepository.java | 0 .../apache/maven/caching/CacheContext.java | 0 .../apache/maven/caching/CacheController.java | 0 .../maven/caching/CacheControllerImpl.java | 0 .../org/apache/maven/caching/CacheDiff.java | 0 .../apache/maven/caching/CacheEventSpy.java | 0 .../org/apache/maven/caching/CacheResult.java | 0 .../maven/caching/CachingMojoExecutor.java | 595 ++++++++++++++++++ .../java/org/apache/maven/caching/Clock.java | 0 .../caching/DefaultPluginScanConfig.java | 0 .../maven/caching/HttpRepositoryImpl.java | 0 .../caching/LocalArtifactsRepository.java | 0 .../maven/caching/LocalRepositoryImpl.java | 5 +- .../maven/caching/MojoExecutionManager.java | 0 .../maven/caching/MojoParametersListener.java | 0 .../maven/caching/PluginScanConfig.java | 0 .../maven/caching/PluginScanConfigImpl.java | 0 .../apache/maven/caching/ProjectUtils.java | 0 .../caching/RemoteArtifactsRepository.java | 0 .../apache/maven/caching/RestoreStatus.java | 0 .../maven/caching/ScanConfigProperties.java | 0 .../org/apache/maven/caching/ZipUtils.java | 0 .../DependencyNotResolvedException.java | 0 .../maven/caching/checksum/DigestUtils.java | 0 .../maven/caching/checksum/KeyUtils.java | 0 .../caching/checksum/MavenProjectInput.java | 0 .../MultimoduleDiscoveryStrategy.java | 0 .../maven/caching/checksum/WalkKey.java | 0 .../maven/caching/hash/CloseableBuffer.java | 0 .../org/apache/maven/caching/hash/Hash.java | 0 .../maven/caching/hash/HashAlgorithm.java | 0 .../maven/caching/hash/HashChecksum.java | 0 .../maven/caching/hash/HashFactory.java | 0 .../apache/maven/caching/hash/HexUtils.java | 0 .../maven/caching/hash/ReflectionUtils.java | 0 .../org/apache/maven/caching/hash/SHA.java | 0 .../maven/caching/hash/ThreadLocalBuffer.java | 0 .../maven/caching/hash/ThreadLocalDigest.java | 0 .../org/apache/maven/caching/hash/XX.java | 0 .../org/apache/maven/caching/hash/XXMM.java | 0 .../maven/caching/xml/AllExternalSrategy.java | 0 .../apache/maven/caching/xml/BuildInfo.java | 0 .../apache/maven/caching/xml/CacheConfig.java | 0 .../maven/caching/xml/CacheConfigImpl.java | 0 .../apache/maven/caching/xml/CacheSource.java | 0 .../apache/maven/caching/xml/CacheState.java | 0 .../apache/maven/caching/xml/DtoUtils.java | 0 .../caching/xml/SentinelVersionStartegy.java | 0 .../apache/maven/caching/xml/XmlService.java | 0 .../src/main/mdo/cache-buildinfo.mdo | 0 .../src/main/mdo/cache-buildsdiff.mdo | 0 .../src/main/mdo/cache-config.mdo | 70 +-- .../src/main/mdo/cache-report.mdo | 0 .../apache/maven/caching/BuildInfoTest.java | 21 +- .../checksum/MavenProjectInputTest.java | 14 +- .../maven/caching/checksum/SHAHashTest.java | 4 +- .../maven/caching/checksum/XXHashTest.java | 6 +- .../maven/caching/hash/HexUtilsTest.java | 0 .../maven/caching/xml/CacheConfigTest.java | 0 .../caching/xml/cache-buildinfo-instance.xml | 8 +- .../caching/xml/cache-config-instance.xml | 0 .../test/resources/test-folder/test-pom.xml | 52 ++ maven-core/pom.xml | 38 +- .../maven/graph/DefaultGraphBuilder.java | 73 --- .../internal/DefaultMojoExecutor.java | 385 ++++++++++++ .../lifecycle/internal/MojoExecutor.java | 567 +---------------- .../internal/stub/MojoExecutorStub.java | 11 +- pom.xml | 1 + 69 files changed, 1191 insertions(+), 763 deletions(-) create mode 100644 maven-caching/pom.xml rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/ArtifactsRepository.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/CacheContext.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/CacheController.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/CacheControllerImpl.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/CacheDiff.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/CacheEventSpy.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/CacheResult.java (100%) create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/Clock.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java (99%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/MojoExecutionManager.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/MojoParametersListener.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/PluginScanConfig.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/ProjectUtils.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/RestoreStatus.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/ScanConfigProperties.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/ZipUtils.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/checksum/WalkKey.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/Hash.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/HashChecksum.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/HashFactory.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/HexUtils.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/SHA.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/XX.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/hash/XXMM.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/xml/BuildInfo.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/xml/CacheConfig.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/xml/CacheSource.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/xml/CacheState.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/xml/DtoUtils.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java (100%) rename {maven-core => maven-caching}/src/main/java/org/apache/maven/caching/xml/XmlService.java (100%) rename {maven-core => maven-caching}/src/main/mdo/cache-buildinfo.mdo (100%) rename {maven-core => maven-caching}/src/main/mdo/cache-buildsdiff.mdo (100%) rename {maven-core => maven-caching}/src/main/mdo/cache-config.mdo (94%) rename {maven-core => maven-caching}/src/main/mdo/cache-report.mdo (100%) rename {maven-core => maven-caching}/src/test/java/org/apache/maven/caching/BuildInfoTest.java (99%) rename {maven-core => maven-caching}/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java (94%) rename {maven-core => maven-caching}/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java (100%) rename {maven-core => maven-caching}/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java (100%) rename {maven-core => maven-caching}/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java (100%) rename {maven-core => maven-caching}/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java (100%) rename maven-core/src/test/resources/org/apache/maven/caching/xml/cache-domain-instance.xml => maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildinfo-instance.xml (90%) rename {maven-core => maven-caching}/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml (100%) create mode 100644 maven-caching/src/test/resources/test-folder/test-pom.xml create mode 100644 maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutor.java diff --git a/maven-caching/pom.xml b/maven-caching/pom.xml new file mode 100644 index 000000000000..1cc41ab7207e --- /dev/null +++ b/maven-caching/pom.xml @@ -0,0 +1,104 @@ + + + + + + 4.0.0 + + + org.apache.maven + maven + 3.8.3-SNAPSHOT + + + maven-caching + + Maven Caching + Maven Caching classes. + + + + + org.apache.maven + maven-core + + + + + + + src/main/resources + true + + + + + + org.apache.rat + apache-rat-plugin + + + lifecycle-executor.txt + plugin-manager.txt + project-builder.txt + src/site/resources/design/** + + + + + + + + org.codehaus.plexus + plexus-component-metadata + + + org.eclipse.sisu + sisu-maven-plugin + + + org.codehaus.modello + modello-maven-plugin + + 1.1.0 + + src/main/mdo/cache-config.mdo + src/main/mdo/cache-buildinfo.mdo + src/main/mdo/cache-buildsdiff.mdo + src/main/mdo/cache-report.mdo + + 1.0.0 + ${basedir}/target/generated-sources/modello + + + + modello-cache + + java + xpp3-reader + xpp3-writer + xsd + + + + + + + diff --git a/maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/ArtifactsRepository.java rename to maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheContext.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/CacheContext.java rename to maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheController.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheController.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/CacheController.java rename to maven-caching/src/main/java/org/apache/maven/caching/CacheController.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/CacheControllerImpl.java rename to maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/CacheDiff.java rename to maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java rename to maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheResult.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheResult.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/CacheResult.java rename to maven-caching/src/main/java/org/apache/maven/caching/CacheResult.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java new file mode 100644 index 000000000000..49ee294bead9 --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java @@ -0,0 +1,595 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.concurrent.atomic.AtomicBoolean; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.CacheState; +import org.apache.maven.execution.ExecutionEvent; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.MojoExecutionEvent; +import org.apache.maven.lifecycle.LifecycleExecutionException; +import org.apache.maven.lifecycle.MissingProjectException; +import org.apache.maven.lifecycle.internal.DependencyContext; +import org.apache.maven.lifecycle.internal.ExecutionEventCatapult; +import org.apache.maven.lifecycle.internal.IDependencyContext; +import org.apache.maven.lifecycle.internal.LifecycleDependencyResolver; +import org.apache.maven.lifecycle.internal.MojoExecutor; +import org.apache.maven.lifecycle.internal.NoResolutionContext; +import org.apache.maven.lifecycle.internal.PhaseRecorder; +import org.apache.maven.lifecycle.internal.ProjectIndex; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MavenPluginManager; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.MojoExecution.Source; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.PluginConfigurationException; +import org.apache.maven.plugin.PluginIncompatibleException; +import org.apache.maven.plugin.PluginManagerException; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.util.StringUtils; +import org.eclipse.sisu.Priority; + +import static org.apache.maven.caching.ProjectUtils.isLaterPhase; +import static org.apache.maven.caching.checksum.KeyUtils.getVersionlessProjectKey; +import static org.apache.maven.caching.xml.CacheState.DISABLED; +import static org.apache.maven.caching.xml.CacheState.INITIALIZED; + + +/** + *

    + * Cache-enabled version of the MojoExecutor + *

    + */ +@Singleton +@Named +@Priority( 10 ) +public class CachingMojoExecutor implements MojoExecutor +{ + + @Inject + private Logger logger; + + @Inject + private BuildPluginManager pluginManager; + + @Inject + private MavenPluginManager mavenPluginManager; + + @Inject + private LifecycleDependencyResolver lifeCycleDependencyResolver; + + @Inject + private ExecutionEventCatapult eventCatapult; + + @Inject + private CacheController cacheController; + + @Inject + private CacheConfig cacheConfig; + + @Inject + private MojoParametersListener mojoListener; + + public CachingMojoExecutor() + { + } + + public DependencyContext newDependencyContext( MavenSession session, List mojoExecutions ) + { + Set scopesToCollect = new TreeSet<>(); + Set scopesToResolve = new TreeSet<>(); + + collectDependencyRequirements( scopesToResolve, scopesToCollect, mojoExecutions ); + + return new DependencyContext( session.getCurrentProject(), scopesToCollect, scopesToResolve ); + } + + private void collectDependencyRequirements( Set scopesToResolve, Set scopesToCollect, + Collection mojoExecutions ) + { + for ( MojoExecution mojoExecution : mojoExecutions ) + { + MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); + + scopesToResolve.addAll( toScopes( mojoDescriptor.getDependencyResolutionRequired() ) ); + + scopesToCollect.addAll( toScopes( mojoDescriptor.getDependencyCollectionRequired() ) ); + } + } + + private Collection toScopes( String classpath ) + { + Collection scopes = Collections.emptyList(); + + if ( StringUtils.isNotEmpty( classpath ) ) + { + if ( Artifact.SCOPE_COMPILE.equals( classpath ) ) + { + scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED ); + } + else if ( Artifact.SCOPE_RUNTIME.equals( classpath ) ) + { + scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME ); + } + else if ( Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals( classpath ) ) + { + scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED, + Artifact.SCOPE_RUNTIME ); + } + else if ( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals( classpath ) ) + { + scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_RUNTIME ); + } + else if ( Artifact.SCOPE_TEST.equals( classpath ) ) + { + scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED, + Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST ); + } + } + return Collections.unmodifiableCollection( scopes ); + } + + public void execute( MavenSession session, List mojoExecutions, ProjectIndex projectIndex ) + throws LifecycleExecutionException + { + DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); + + PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); + + final MavenProject project = session.getCurrentProject(); + final Source source = getSource( mojoExecutions ); + + // execute clean bound goals before restoring to not interfere/slowdown clean + CacheState cacheState = DISABLED; + CacheResult result = CacheResult.empty(); + if ( source == Source.LIFECYCLE ) + { + List cleanPhase = getCleanPhase( mojoExecutions ); + for ( MojoExecution mojoExecution : cleanPhase ) + { + execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); + } + cacheState = cacheConfig.initialize( project, session ); + if ( cacheState == INITIALIZED ) + { + result = cacheController.findCachedBuild( session, project, projectIndex, mojoExecutions ); + } + } + + boolean restorable = result.isSuccess() || result.isPartialSuccess(); + boolean restored = result.isSuccess(); // if partially restored need to save increment + if ( restorable ) + { + restored &= restoreProject( result, mojoExecutions, projectIndex, dependencyContext, phaseRecorder ); + } + else + { + for ( MojoExecution mojoExecution : mojoExecutions ) + { + if ( source == Source.CLI || isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) + { + execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); + } + } + } + + if ( cacheState == INITIALIZED && ( !restorable || !restored ) ) + { + final Map executionEvents = mojoListener.getProjectExecutions( project ); + cacheController.save( result, mojoExecutions, executionEvents ); + } + + if ( cacheConfig.isFailFast() && !result.isSuccess() ) + { + throw new LifecycleExecutionException( + "Failed to restore project[" + getVersionlessProjectKey( project ) + "] from cache, failing build.", + project ); + } + } + + private Source getSource( List mojoExecutions ) + { + if ( mojoExecutions == null || mojoExecutions.isEmpty() ) + { + return null; + } + for ( MojoExecution mojoExecution : mojoExecutions ) + { + if ( mojoExecution.getSource() == Source.CLI ) + { + return Source.CLI; + } + } + return Source.LIFECYCLE; + } + + private boolean restoreProject( CacheResult cacheResult, + List mojoExecutions, + ProjectIndex projectIndex, + DependencyContext dependencyContext, + PhaseRecorder phaseRecorder ) throws LifecycleExecutionException + { + + final BuildInfo buildInfo = cacheResult.getBuildInfo(); + final MavenProject project = cacheResult.getContext().getProject(); + final MavenSession session = cacheResult.getContext().getSession(); + final List cachedSegment = buildInfo.getCachedSegment( mojoExecutions ); + + boolean restored = cacheController.restoreProjectArtifacts( cacheResult ); + if ( !restored ) + { + logger.info( + "[CACHE][" + project.getArtifactId() + + "] Cannot restore project artifacts, continuing with non cached build" ); + return false; + } + + for ( MojoExecution cacheCandidate : cachedSegment ) + { + + if ( cacheController.isForcedExecution( project, cacheCandidate ) ) + { + logger.info( + "[CACHE][" + project.getArtifactId() + "] Mojo execution is forced by project property: " + + cacheCandidate.getMojoDescriptor().getFullGoalName() ); + execute( session, cacheCandidate, projectIndex, dependencyContext, phaseRecorder ); + } + else + { + restored = verifyCacheConsistency( cacheCandidate, buildInfo, project, session, projectIndex, + dependencyContext, phaseRecorder ); + if ( !restored ) + { + break; + } + } + } + + if ( !restored ) + { + // cleanup partial state + project.getArtifact().setFile( null ); + project.getArtifact().setResolved( false ); + project.getAttachedArtifacts().clear(); + mojoListener.remove( project ); + // build as usual + for ( MojoExecution mojoExecution : cachedSegment ) + { + execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); + } + } + + for ( MojoExecution mojoExecution : buildInfo.getPostCachedSegment( mojoExecutions ) ) + { + execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); + } + return restored; + } + + private boolean verifyCacheConsistency( MojoExecution cacheCandidate, + BuildInfo cachedBuildInfo, + MavenProject project, + MavenSession session, + ProjectIndex projectIndex, + DependencyContext dependencyContext, + PhaseRecorder phaseRecorder ) throws LifecycleExecutionException + { + + AtomicBoolean consistent = new AtomicBoolean( true ); + final MojoExecutionManager mojoChecker = new MojoExecutionManager( project, cacheController, cachedBuildInfo, + consistent, logger, cacheConfig ); + + if ( mojoChecker.needCheck( cacheCandidate, session ) ) + { + try + { + // actual execution will not happen (if not forced). decision delayed to execution time + // then all properties are resolved. + cacheCandidate.setMojoExecutionManager( mojoChecker ); + IDependencyContext nop = new NoResolutionContext( dependencyContext ); + execute( session, cacheCandidate, projectIndex, nop, phaseRecorder ); + } + finally + { + cacheCandidate.setMojoExecutionManager( null ); + } + } + else + { + logger.info( + "[CACHE][" + project.getArtifactId() + "] Skipping plugin execution (cached): " + + cacheCandidate.getMojoDescriptor().getFullGoalName() ); + } + + return consistent.get(); + } + + private List getCleanPhase( List mojoExecutions ) + { + List list = new ArrayList<>(); + for ( MojoExecution mojoExecution : mojoExecutions ) + { + if ( isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) + { + break; + } + list.add( mojoExecution ); + } + return list; + } + + public void execute( MavenSession session, + MojoExecution mojoExecution, + ProjectIndex projectIndex, + IDependencyContext dependencyContext, + PhaseRecorder phaseRecorder ) throws LifecycleExecutionException + { + execute( session, mojoExecution, projectIndex, dependencyContext ); + phaseRecorder.observeExecution( mojoExecution ); + } + + private void execute( MavenSession session, + MojoExecution mojoExecution, + ProjectIndex projectIndex, + IDependencyContext dependencyContext ) throws LifecycleExecutionException + { + MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); + + try + { + mavenPluginManager.checkRequiredMavenVersion( mojoDescriptor.getPluginDescriptor() ); + } + catch ( PluginIncompatibleException e ) + { + throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), e ); + } + + if ( mojoDescriptor.isProjectRequired() && !session.getRequest().isProjectPresent() ) + { + Throwable cause = new MissingProjectException( + "Goal requires a project to execute" + " but there is no POM in this directory (" + + session.getExecutionRootDirectory() + ")." + + " Please verify you invoked Maven from the correct directory." ); + throw new LifecycleExecutionException( mojoExecution, null, cause ); + } + + if ( mojoDescriptor.isOnlineRequired() && session.isOffline() ) + { + if ( Source.CLI.equals( mojoExecution.getSource() ) ) + { + Throwable cause = new IllegalStateException( + "Goal requires online mode for execution" + " but Maven is currently offline." ); + throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), cause ); + } + else + { + eventCatapult.fire( ExecutionEvent.Type.MojoSkipped, session, mojoExecution ); + + return; + } + } + + List forkedProjects = executeForkedExecutions( mojoExecution, session, projectIndex ); + + ensureDependenciesAreResolved( mojoDescriptor, session, dependencyContext ); + + eventCatapult.fire( ExecutionEvent.Type.MojoStarted, session, mojoExecution ); + + try + { + try + { + pluginManager.executeMojo( session, mojoExecution ); + } + catch ( MojoFailureException + | PluginManagerException + | PluginConfigurationException + | MojoExecutionException e ) + { + throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), e ); + } + + eventCatapult.fire( ExecutionEvent.Type.MojoSucceeded, session, mojoExecution ); + } + catch ( LifecycleExecutionException e ) + { + eventCatapult.fire( ExecutionEvent.Type.MojoFailed, session, mojoExecution, e ); + + throw e; + } + finally + { + for ( MavenProject forkedProject : forkedProjects ) + { + forkedProject.setExecutionProject( null ); + } + } + } + + public void ensureDependenciesAreResolved( MojoDescriptor mojoDescriptor, + MavenSession session, + IDependencyContext dependencyContext ) throws LifecycleExecutionException + + { + MavenProject project = dependencyContext.getProject(); + boolean aggregating = mojoDescriptor.isAggregator(); + + if ( dependencyContext.isResolutionRequiredForCurrentProject() ) + { + Collection scopesToCollect = dependencyContext.getScopesToCollectForCurrentProject(); + Collection scopesToResolve = dependencyContext.getScopesToResolveForCurrentProject(); + + lifeCycleDependencyResolver.resolveProjectDependencies( project, scopesToCollect, scopesToResolve, session, + aggregating, Collections.emptySet() ); + + dependencyContext.synchronizeWithProjectState(); + } + + if ( aggregating ) + { + Collection scopesToCollect = toScopes( mojoDescriptor.getDependencyCollectionRequired() ); + Collection scopesToResolve = toScopes( mojoDescriptor.getDependencyResolutionRequired() ); + + if ( dependencyContext.isResolutionRequiredForAggregatedProjects( scopesToCollect, scopesToResolve ) ) + { + for ( MavenProject aggregatedProject : session.getProjects() ) + { + if ( aggregatedProject != project ) + { + lifeCycleDependencyResolver.resolveProjectDependencies( aggregatedProject, scopesToCollect, + scopesToResolve, session, aggregating, Collections.emptySet() ); + } + } + } + } + + ArtifactFilter artifactFilter = getArtifactFilter( mojoDescriptor ); + List projectsToResolve = LifecycleDependencyResolver.getProjects( session.getCurrentProject(), + session, mojoDescriptor.isAggregator() ); + for ( MavenProject projectToResolve : projectsToResolve ) + { + projectToResolve.setArtifactFilter( artifactFilter ); + } + } + + private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor ) + { + String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired(); + String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired(); + + List scopes = new ArrayList<>( 2 ); + if ( StringUtils.isNotEmpty( scopeToCollect ) ) + { + scopes.add( scopeToCollect ); + } + if ( StringUtils.isNotEmpty( scopeToResolve ) ) + { + scopes.add( scopeToResolve ); + } + + if ( scopes.isEmpty() ) + { + return null; + } + else + { + return new CumulativeScopeArtifactFilter( scopes ); + } + } + + public List executeForkedExecutions( MojoExecution mojoExecution, + MavenSession session, + ProjectIndex projectIndex ) throws LifecycleExecutionException + { + List forkedProjects = Collections.emptyList(); + + Map> forkedExecutions = mojoExecution.getForkedExecutions(); + + if ( !forkedExecutions.isEmpty() ) + { + eventCatapult.fire( ExecutionEvent.Type.ForkStarted, session, mojoExecution ); + + MavenProject project = session.getCurrentProject(); + + forkedProjects = new ArrayList<>( forkedExecutions.size() ); + + try + { + for ( Map.Entry> fork : forkedExecutions.entrySet() ) + { + String projectId = fork.getKey(); + + int index = projectIndex.getIndices().get( projectId ); + + MavenProject forkedProject = projectIndex.getProjects().get( projectId ); + + forkedProjects.add( forkedProject ); + + MavenProject executedProject = forkedProject.clone(); + + forkedProject.setExecutionProject( executedProject ); + + List mojoExecutions = fork.getValue(); + + if ( mojoExecutions.isEmpty() ) + { + continue; + } + + try + { + session.setCurrentProject( executedProject ); + session.getProjects().set( index, executedProject ); + projectIndex.getProjects().put( projectId, executedProject ); + + eventCatapult.fire( ExecutionEvent.Type.ForkedProjectStarted, session, mojoExecution ); + + execute( session, mojoExecutions, projectIndex ); + + eventCatapult.fire( ExecutionEvent.Type.ForkedProjectSucceeded, session, mojoExecution ); + } + catch ( LifecycleExecutionException e ) + { + eventCatapult.fire( ExecutionEvent.Type.ForkedProjectFailed, session, mojoExecution, e ); + + throw e; + } + finally + { + projectIndex.getProjects().put( projectId, forkedProject ); + session.getProjects().set( index, forkedProject ); + session.setCurrentProject( project ); + } + } + + eventCatapult.fire( ExecutionEvent.Type.ForkSucceeded, session, mojoExecution ); + } + catch ( LifecycleExecutionException e ) + { + eventCatapult.fire( ExecutionEvent.Type.ForkFailed, session, mojoExecution, e ); + + throw e; + } + } + + return forkedProjects; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/caching/Clock.java b/maven-caching/src/main/java/org/apache/maven/caching/Clock.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/Clock.java rename to maven-caching/src/main/java/org/apache/maven/caching/Clock.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java rename to maven-caching/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java rename to maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java rename to maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java rename to maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java index a0fbcbe1e528..7b7d465d04e2 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java @@ -243,10 +243,11 @@ public void clearCache( CacheContext context ) cacheDirs.add( dir ); } } - if ( cacheDirs.size() > cacheConfig.getMaxLocalBuildsCached() ) + int maxLocalBuildsCached = cacheConfig.getMaxLocalBuildsCached() - 1; + if ( cacheDirs.size() > maxLocalBuildsCached ) { Collections.sort( cacheDirs, LAST_MODIFIED_COMPARATOR ); - for ( Path dir : cacheDirs.subList( 0, cacheDirs.size() - cacheConfig.getMaxLocalBuildsCached() ) ) + for ( Path dir : cacheDirs.subList( 0, cacheDirs.size() - maxLocalBuildsCached ) ) { FileUtils.deleteDirectory( dir.toFile() ); } diff --git a/maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/MojoExecutionManager.java rename to maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/MojoParametersListener.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/MojoParametersListener.java rename to maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfig.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/PluginScanConfig.java rename to maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfig.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java rename to maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/ProjectUtils.java rename to maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java rename to maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/RestoreStatus.java b/maven-caching/src/main/java/org/apache/maven/caching/RestoreStatus.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/RestoreStatus.java rename to maven-caching/src/main/java/org/apache/maven/caching/RestoreStatus.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/ScanConfigProperties.java b/maven-caching/src/main/java/org/apache/maven/caching/ScanConfigProperties.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/ScanConfigProperties.java rename to maven-caching/src/main/java/org/apache/maven/caching/ScanConfigProperties.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/ZipUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/ZipUtils.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/ZipUtils.java rename to maven-caching/src/main/java/org/apache/maven/caching/ZipUtils.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java rename to maven-caching/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java rename to maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java rename to maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java rename to maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java rename to maven-caching/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/checksum/WalkKey.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/WalkKey.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/checksum/WalkKey.java rename to maven-caching/src/main/java/org/apache/maven/caching/checksum/WalkKey.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/Hash.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/Hash.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/Hash.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/Hash.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/HashChecksum.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/HashChecksum.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/HashChecksum.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/HashChecksum.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/HashFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/HashFactory.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/HashFactory.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/HashFactory.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/HexUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/HexUtils.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/HexUtils.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/HexUtils.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/SHA.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/SHA.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/SHA.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/SHA.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/XX.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/XX.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/XX.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/XX.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/hash/XXMM.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/XXMM.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/hash/XXMM.java rename to maven-caching/src/main/java/org/apache/maven/caching/hash/XXMM.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/BuildInfo.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/xml/BuildInfo.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/BuildInfo.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfig.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheSource.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheSource.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/xml/CacheSource.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/CacheSource.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/CacheState.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheState.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/xml/CacheState.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/CacheState.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/xml/DtoUtils.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java diff --git a/maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/caching/xml/XmlService.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java diff --git a/maven-core/src/main/mdo/cache-buildinfo.mdo b/maven-caching/src/main/mdo/cache-buildinfo.mdo similarity index 100% rename from maven-core/src/main/mdo/cache-buildinfo.mdo rename to maven-caching/src/main/mdo/cache-buildinfo.mdo diff --git a/maven-core/src/main/mdo/cache-buildsdiff.mdo b/maven-caching/src/main/mdo/cache-buildsdiff.mdo similarity index 100% rename from maven-core/src/main/mdo/cache-buildsdiff.mdo rename to maven-caching/src/main/mdo/cache-buildsdiff.mdo diff --git a/maven-core/src/main/mdo/cache-config.mdo b/maven-caching/src/main/mdo/cache-config.mdo similarity index 94% rename from maven-core/src/main/mdo/cache-config.mdo rename to maven-caching/src/main/mdo/cache-config.mdo index a9e9f92bf208..05d80546289a 100644 --- a/maven-core/src/main/mdo/cache-config.mdo +++ b/maven-caching/src/main/mdo/cache-config.mdo @@ -36,48 +36,6 @@ under the License. - CacheType @@ -86,56 +44,40 @@ under the License. ConfigurationType + Configuration of main cache properties input InputType + Configuration for source code input files participating in checksum calculation output OutputType + Configuration for output artifacts, it's needed if you want to explicitly include/exclude something from caching executionControl ExecutionControlType + Execution rules for plugins in cached mode. Defines which plugins should run always + Cache build metadata - Remote url String - address of remote cache + Address of remote cache enabled diff --git a/maven-core/src/main/mdo/cache-report.mdo b/maven-caching/src/main/mdo/cache-report.mdo similarity index 100% rename from maven-core/src/main/mdo/cache-report.mdo rename to maven-caching/src/main/mdo/cache-report.mdo diff --git a/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java b/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java similarity index 99% rename from maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java rename to maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java index e05516884877..18a62753c873 100644 --- a/maven-core/src/test/java/org/apache/maven/caching/BuildInfoTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java @@ -19,6 +19,17 @@ * under the License. */ + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + import com.google.common.collect.Lists; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; @@ -34,16 +45,6 @@ import org.apache.maven.caching.xml.XmlService; import org.junit.Test; -import java.io.File; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - public class BuildInfoTest { @Test diff --git a/maven-core/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java b/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java similarity index 94% rename from maven-core/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java rename to maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java index d420134e6746..6366d9269459 100644 --- a/maven-core/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java @@ -19,15 +19,15 @@ * under the License. */ -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import static org.junit.Assert.assertEquals; public class MavenProjectInputTest { @@ -72,14 +72,14 @@ public void testGlobInput() { @Test public void testGetDirectoryFiles() { List directoryFiles = new ArrayList<>(); - MavenProjectInput.walkDirectoryFiles(Paths.get("src/test/resources"), directoryFiles, MavenProjectInput.DEFAULT_GLOB); + MavenProjectInput.walkDirectoryFiles(Paths.get("src/test/resources/test-folder"), directoryFiles, MavenProjectInput.DEFAULT_GLOB); assertEquals(0, directoryFiles.size()); // pom is filtered out by hardcoded if } @Test public void testGetDirectoryFiles2() { List directoryFiles = new ArrayList<>(); - MavenProjectInput.walkDirectoryFiles(Paths.get("src/test/resources"), directoryFiles, GLOB); - assertEquals(4, directoryFiles.size()); // pom is filtered out by hardcoded if + MavenProjectInput.walkDirectoryFiles(Paths.get("src/test/resources/test-folder"), directoryFiles, GLOB); + assertEquals(1, directoryFiles.size()); // pom is filtered out by hardcoded if } } diff --git a/maven-core/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java b/maven-caching/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java similarity index 100% rename from maven-core/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java rename to maven-caching/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java index 9cf5bb405f91..c3782e1a75fc 100644 --- a/maven-core/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java @@ -19,12 +19,12 @@ * under the License. */ +import java.nio.charset.StandardCharsets; + import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashChecksum; import org.junit.Test; -import java.nio.charset.StandardCharsets; - import static org.apache.maven.caching.hash.HashFactory.SHA256; import static org.junit.Assert.assertEquals; diff --git a/maven-core/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java b/maven-caching/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java similarity index 100% rename from maven-core/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java rename to maven-caching/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java index 3a1a46ecf492..164f2b2966ac 100644 --- a/maven-core/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java @@ -19,13 +19,13 @@ * under the License. */ +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; + import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashChecksum; import org.junit.Test; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; - import static org.apache.maven.caching.hash.HashFactory.XX; import static org.apache.maven.caching.hash.HashFactory.XXMM; import static org.junit.Assert.assertEquals; diff --git a/maven-core/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java b/maven-caching/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java similarity index 100% rename from maven-core/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java rename to maven-caching/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java diff --git a/maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java b/maven-caching/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java similarity index 100% rename from maven-core/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java rename to maven-caching/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java diff --git a/maven-core/src/test/resources/org/apache/maven/caching/xml/cache-domain-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildinfo-instance.xml similarity index 90% rename from maven-core/src/test/resources/org/apache/maven/caching/xml/cache-domain-instance.xml rename to maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildinfo-instance.xml index 101a011430e0..9dd0c7cc054b 100644 --- a/maven-core/src/test/resources/org/apache/maven/caching/xml/cache-domain-instance.xml +++ b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildinfo-instance.xml @@ -19,9 +19,9 @@ specific language governing permissions and limitations under the License. --> - + xsi:schemaLocation="org:apache:maven:cache:buildinfo ../../../../../../../../target/generated-sources/modello/cache-buildinfo-1.0.0.xsd"> v3 1980-03-23T10:20:15 my-server.com @@ -39,13 +39,13 @@ under the License. 123456 - + com.my.shared my-server java-source sources my-server-sources.jar - + diff --git a/maven-core/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml similarity index 100% rename from maven-core/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml rename to maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml diff --git a/maven-caching/src/test/resources/test-folder/test-pom.xml b/maven-caching/src/test/resources/test-folder/test-pom.xml new file mode 100644 index 000000000000..b5e89715a9cd --- /dev/null +++ b/maven-caching/src/test/resources/test-folder/test-pom.xml @@ -0,0 +1,52 @@ + + + + 4.0.0 + + org.apache.maven + maven-core + 2.0-SNAPSHOT + jar + + Maven + 2001 + + + + org.apache.maven + maven-model + 2.0-SNAPSHOT + jar + compile + + + org.apache.maven + maven-plugin + 2.0-SNAPSHOT + jar + compile + + + + + scm-connection + + diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 56e585d70933..2d2ab31eb003 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -208,43 +208,7 @@ under the License. - - modello-site-docs-cache - pre-site - - xdoc - xsd - - - 1.0.0 - - src/main/mdo/cache-buildinfo.mdo - src/main/mdo/cache-buildsdiff.mdo - src/main/mdo/cache-config.mdo - src/main/mdo/cache-report.mdo - - - - - modello-cache - - java - xpp3-reader - xpp3-writer - xsd - - - 1.0.0 - - src/main/mdo/cache-buildinfo.mdo - src/main/mdo/cache-buildsdiff.mdo - src/main/mdo/cache-config.mdo - src/main/mdo/cache-report.mdo - - ${basedir}/target/generated-sources/modello - - - + modello-site-docs-extension pre-site diff --git a/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java b/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java index 5a7db543f80b..fb7a9f45064d 100644 --- a/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java @@ -34,11 +34,9 @@ import org.apache.maven.MavenExecutionException; import org.apache.maven.ProjectCycleException; import org.apache.maven.artifact.ArtifactUtils; -import org.apache.maven.caching.checksum.KeyUtils; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ProjectDependencyGraph; -import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.model.building.DefaultModelProblem; import org.apache.maven.model.building.ModelProblem; @@ -58,8 +56,6 @@ import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.dag.CycleDetectedException; -import static org.apache.maven.artifact.versioning.VersionRange.createFromVersion; - /** * Builds the {@link ProjectDependencyGraph inter-dependencies graph} between projects in the reactor. */ @@ -68,8 +64,6 @@ public class DefaultGraphBuilder implements GraphBuilder { - public static final String PROJECT_VERSION_PROP_NAME = "org.maven.project.version"; - @Requirement private Logger logger; @@ -87,11 +81,6 @@ public Result build( MavenSession session ) { final List projects = getProjectsForMavenReactor( session ); validateProjects( projects ); - - if ( System.getProperties().containsKey( PROJECT_VERSION_PROP_NAME ) ) - { - overrideReactorVersions( projects, session ); - } result = reactorDependencyGraph( session, projects ); } @@ -111,68 +100,6 @@ public Result build( MavenSession session ) } } - private void overrideReactorVersions( List projects, MavenSession session ) - { - String injectedVersion = System.getProperty( PROJECT_VERSION_PROP_NAME ); - logger.info( "Overriding reactor projects version to " + injectedVersion ); - - Map reactorProjects = new HashMap<>( projects.size() ); - - for ( MavenProject project : projects ) - { - String projectKey = KeyUtils.getVersionlessProjectKey( project ); - logger.debug( - "[" + projectKey + "] Overriding version from " + project.getVersion() + " to " + injectedVersion ); - reactorProjects.put( projectKey, project.getVersion() ); - project.setVersion( injectedVersion ); - project.getArtifact().setVersionRange( createFromVersion( injectedVersion ) ); - project.getArtifact().updateVersion( injectedVersion, session.getLocalRepository() ); - } - - for ( MavenProject project : projects ) - { - String projectKey = KeyUtils.getVersionlessProjectKey( project ); - MavenProject parent = project.getParent(); - String parentKey = KeyUtils.getVersionlessProjectKey( parent ); - String overriddenParentVersion = reactorProjects.get( parentKey ); - if ( overriddenParentVersion != null && overriddenParentVersion.equals( - project.getParentArtifact().getVersion() ) ) - { - logger.debug( - "[" + projectKey + "] Parent " + parentKey + " overriding artefact version from " - + parent.getVersion() + " to " + injectedVersion ); - project.getParentArtifact().setVersionRange( createFromVersion( injectedVersion ) ); - project.getParentArtifact().updateVersion( injectedVersion, session.getLocalRepository() ); - } - - for ( Dependency dependency : project.getDependencies() ) - { - String dependencyKey = KeyUtils.getVersionlessDependencyKey( dependency ); - String overriddenReactorVersion = reactorProjects.get( dependencyKey ); - if ( overriddenReactorVersion != null && overriddenReactorVersion.equals( dependency.getVersion() ) ) - { - logger.debug( - "[" + projectKey + "] Dependency " + dependencyKey + " overriding version from " - + dependency.getVersion() + " to " + injectedVersion ); - dependency.setVersion( injectedVersion ); - } - } - - for ( Dependency dependency : project.getDependencyManagement().getDependencies() ) - { - String dependencyKey = KeyUtils.getVersionlessDependencyKey( dependency ); - String overriddenReactorVersion = reactorProjects.get( dependencyKey ); - if ( overriddenReactorVersion != null && overriddenReactorVersion.equals( dependency.getVersion() ) ) - { - logger.debug( - "[" + projectKey + "] Dependency management " + dependencyKey - + " overriding version from " + dependency.getVersion() + " to " + injectedVersion ); - dependency.setVersion( injectedVersion ); - } - } - } - } - private Result sessionDependencyGraph( final MavenSession session ) throws CycleDetectedException, DuplicateProjectException { diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutor.java new file mode 100644 index 000000000000..16af887fbd14 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultMojoExecutor.java @@ -0,0 +1,385 @@ +package org.apache.maven.lifecycle.internal; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter; +import org.apache.maven.execution.ExecutionEvent; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.LifecycleExecutionException; +import org.apache.maven.lifecycle.MissingProjectException; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MavenPluginManager; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.PluginConfigurationException; +import org.apache.maven.plugin.PluginIncompatibleException; +import org.apache.maven.plugin.PluginManagerException; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.util.StringUtils; + +/** + *

    + * Executes an individual mojo + *

    + * NOTE: This class is not part of any public api and can be changed or deleted without prior notice. + * + * @author Jason van Zyl + * @author Benjamin Bentmann + * @author Kristian Rosenvold + * @since 3.0 + */ +@Component( role = MojoExecutor.class ) +public class DefaultMojoExecutor implements MojoExecutor +{ + + @Requirement + private BuildPluginManager pluginManager; + + @Requirement + private MavenPluginManager mavenPluginManager; + + @Requirement + private LifecycleDependencyResolver lifeCycleDependencyResolver; + + @Requirement + private ExecutionEventCatapult eventCatapult; + + public DefaultMojoExecutor() + { + } + + public DependencyContext newDependencyContext( MavenSession session, List mojoExecutions ) + { + Set scopesToCollect = new TreeSet<>(); + Set scopesToResolve = new TreeSet<>(); + + collectDependencyRequirements( scopesToResolve, scopesToCollect, mojoExecutions ); + + return new DependencyContext( session.getCurrentProject(), scopesToCollect, scopesToResolve ); + } + + private void collectDependencyRequirements( Set scopesToResolve, Set scopesToCollect, + Collection mojoExecutions ) + { + for ( MojoExecution mojoExecution : mojoExecutions ) + { + MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); + + scopesToResolve.addAll( toScopes( mojoDescriptor.getDependencyResolutionRequired() ) ); + + scopesToCollect.addAll( toScopes( mojoDescriptor.getDependencyCollectionRequired() ) ); + } + } + + private Collection toScopes( String classpath ) + { + Collection scopes = Collections.emptyList(); + + if ( StringUtils.isNotEmpty( classpath ) ) + { + if ( Artifact.SCOPE_COMPILE.equals( classpath ) ) + { + scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED ); + } + else if ( Artifact.SCOPE_RUNTIME.equals( classpath ) ) + { + scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME ); + } + else if ( Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals( classpath ) ) + { + scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED, + Artifact.SCOPE_RUNTIME ); + } + else if ( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals( classpath ) ) + { + scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_RUNTIME ); + } + else if ( Artifact.SCOPE_TEST.equals( classpath ) ) + { + scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED, + Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST ); + } + } + return Collections.unmodifiableCollection( scopes ); + } + + public void execute( MavenSession session, List mojoExecutions, ProjectIndex projectIndex ) + throws LifecycleExecutionException + + { + DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); + + PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); + + for ( MojoExecution mojoExecution : mojoExecutions ) + { + execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); + } + } + + public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, + DependencyContext dependencyContext, PhaseRecorder phaseRecorder ) + throws LifecycleExecutionException + { + execute( session, mojoExecution, projectIndex, dependencyContext ); + phaseRecorder.observeExecution( mojoExecution ); + } + + private void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, + DependencyContext dependencyContext ) + throws LifecycleExecutionException + { + MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); + + try + { + mavenPluginManager.checkRequiredMavenVersion( mojoDescriptor.getPluginDescriptor() ); + } + catch ( PluginIncompatibleException e ) + { + throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), e ); + } + + if ( mojoDescriptor.isProjectRequired() && !session.getRequest().isProjectPresent() ) + { + Throwable cause = new MissingProjectException( + "Goal requires a project to execute" + " but there is no POM in this directory (" + + session.getExecutionRootDirectory() + ")." + + " Please verify you invoked Maven from the correct directory." ); + throw new LifecycleExecutionException( mojoExecution, null, cause ); + } + + if ( mojoDescriptor.isOnlineRequired() && session.isOffline() ) + { + if ( MojoExecution.Source.CLI.equals( mojoExecution.getSource() ) ) + { + Throwable cause = new IllegalStateException( + "Goal requires online mode for execution" + " but Maven is currently offline." ); + throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), cause ); + } + else + { + eventCatapult.fire( ExecutionEvent.Type.MojoSkipped, session, mojoExecution ); + + return; + } + } + + List forkedProjects = executeForkedExecutions( mojoExecution, session, projectIndex ); + + ensureDependenciesAreResolved( mojoDescriptor, session, dependencyContext ); + + eventCatapult.fire( ExecutionEvent.Type.MojoStarted, session, mojoExecution ); + + try + { + try + { + pluginManager.executeMojo( session, mojoExecution ); + } + catch ( MojoFailureException | PluginManagerException | PluginConfigurationException + | MojoExecutionException e ) + { + throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), e ); + } + + eventCatapult.fire( ExecutionEvent.Type.MojoSucceeded, session, mojoExecution ); + } + catch ( LifecycleExecutionException e ) + { + eventCatapult.fire( ExecutionEvent.Type.MojoFailed, session, mojoExecution, e ); + + throw e; + } + finally + { + for ( MavenProject forkedProject : forkedProjects ) + { + forkedProject.setExecutionProject( null ); + } + } + } + + public void ensureDependenciesAreResolved( MojoDescriptor mojoDescriptor, MavenSession session, + DependencyContext dependencyContext ) + throws LifecycleExecutionException + + { + MavenProject project = dependencyContext.getProject(); + boolean aggregating = mojoDescriptor.isAggregator(); + + if ( dependencyContext.isResolutionRequiredForCurrentProject() ) + { + Collection scopesToCollect = dependencyContext.getScopesToCollectForCurrentProject(); + Collection scopesToResolve = dependencyContext.getScopesToResolveForCurrentProject(); + + lifeCycleDependencyResolver.resolveProjectDependencies( project, scopesToCollect, scopesToResolve, session, + aggregating, Collections.emptySet() ); + + dependencyContext.synchronizeWithProjectState(); + } + + if ( aggregating ) + { + Collection scopesToCollect = toScopes( mojoDescriptor.getDependencyCollectionRequired() ); + Collection scopesToResolve = toScopes( mojoDescriptor.getDependencyResolutionRequired() ); + + if ( dependencyContext.isResolutionRequiredForAggregatedProjects( scopesToCollect, scopesToResolve ) ) + { + for ( MavenProject aggregatedProject : session.getProjects() ) + { + if ( aggregatedProject != project ) + { + lifeCycleDependencyResolver.resolveProjectDependencies( aggregatedProject, scopesToCollect, + scopesToResolve, session, aggregating, + Collections.emptySet() ); + } + } + } + } + + ArtifactFilter artifactFilter = getArtifactFilter( mojoDescriptor ); + List projectsToResolve = + LifecycleDependencyResolver.getProjects( session.getCurrentProject(), session, + mojoDescriptor.isAggregator() ); + for ( MavenProject projectToResolve : projectsToResolve ) + { + projectToResolve.setArtifactFilter( artifactFilter ); + } + } + + private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor ) + { + String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired(); + String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired(); + + List scopes = new ArrayList<>( 2 ); + if ( StringUtils.isNotEmpty( scopeToCollect ) ) + { + scopes.add( scopeToCollect ); + } + if ( StringUtils.isNotEmpty( scopeToResolve ) ) + { + scopes.add( scopeToResolve ); + } + + if ( scopes.isEmpty() ) + { + return null; + } + else + { + return new CumulativeScopeArtifactFilter( scopes ); + } + } + + public List executeForkedExecutions( MojoExecution mojoExecution, MavenSession session, + ProjectIndex projectIndex ) + throws LifecycleExecutionException + { + List forkedProjects = Collections.emptyList(); + + Map> forkedExecutions = mojoExecution.getForkedExecutions(); + + if ( !forkedExecutions.isEmpty() ) + { + eventCatapult.fire( ExecutionEvent.Type.ForkStarted, session, mojoExecution ); + + MavenProject project = session.getCurrentProject(); + + forkedProjects = new ArrayList<>( forkedExecutions.size() ); + + try + { + for ( Map.Entry> fork : forkedExecutions.entrySet() ) + { + String projectId = fork.getKey(); + + int index = projectIndex.getIndices().get( projectId ); + + MavenProject forkedProject = projectIndex.getProjects().get( projectId ); + + forkedProjects.add( forkedProject ); + + MavenProject executedProject = forkedProject.clone(); + + forkedProject.setExecutionProject( executedProject ); + + List mojoExecutions = fork.getValue(); + + if ( mojoExecutions.isEmpty() ) + { + continue; + } + + try + { + session.setCurrentProject( executedProject ); + session.getProjects().set( index, executedProject ); + projectIndex.getProjects().put( projectId, executedProject ); + + eventCatapult.fire( ExecutionEvent.Type.ForkedProjectStarted, session, mojoExecution ); + + execute( session, mojoExecutions, projectIndex ); + + eventCatapult.fire( ExecutionEvent.Type.ForkedProjectSucceeded, session, mojoExecution ); + } + catch ( LifecycleExecutionException e ) + { + eventCatapult.fire( ExecutionEvent.Type.ForkedProjectFailed, session, mojoExecution, e ); + + throw e; + } + finally + { + projectIndex.getProjects().put( projectId, forkedProject ); + session.getProjects().set( index, forkedProject ); + session.setCurrentProject( project ); + } + } + + eventCatapult.fire( ExecutionEvent.Type.ForkSucceeded, session, mojoExecution ); + } + catch ( LifecycleExecutionException e ) + { + eventCatapult.fire( ExecutionEvent.Type.ForkFailed, session, mojoExecution, e ); + + throw e; + } + } + + return forkedProjects; + } +} \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java index 59f384983d9e..78aaedd3b298 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java @@ -19,575 +19,26 @@ * under the License. */ -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter; -import org.apache.maven.caching.CacheController; -import org.apache.maven.caching.CacheResult; -import org.apache.maven.caching.MojoExecutionManager; -import org.apache.maven.caching.MojoParametersListener; -import org.apache.maven.caching.xml.BuildInfo; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.CacheState; -import org.apache.maven.execution.ExecutionEvent; +import java.util.List; + import org.apache.maven.execution.MavenSession; -import org.apache.maven.execution.MojoExecutionEvent; -import org.apache.maven.execution.MojoExecutionListener; import org.apache.maven.lifecycle.LifecycleExecutionException; -import org.apache.maven.lifecycle.MissingProjectException; -import org.apache.maven.plugin.BuildPluginManager; -import org.apache.maven.plugin.MavenPluginManager; import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.MojoExecution.Source; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugin.PluginConfigurationException; -import org.apache.maven.plugin.PluginIncompatibleException; -import org.apache.maven.plugin.PluginManagerException; -import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.util.StringUtils; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.apache.maven.caching.ProjectUtils.isLaterPhase; -import static org.apache.maven.caching.checksum.KeyUtils.getVersionlessProjectKey; -import static org.apache.maven.caching.xml.CacheState.DISABLED; -import static org.apache.maven.caching.xml.CacheState.INITIALIZED; - /** *

    * Executes an individual mojo *

    - * NOTE: This class is not part of any public api and can be changed or deleted without prior notice. - * - * @author Jason van Zyl - * @author Benjamin Bentmann - * @author Kristian Rosenvold - * @since 3.0 */ -@Component( role = MojoExecutor.class ) -public class MojoExecutor +public interface MojoExecutor { - @Requirement - private Logger logger; - - @Requirement - private BuildPluginManager pluginManager; - - @Requirement - private MavenPluginManager mavenPluginManager; - - @Requirement - private LifecycleDependencyResolver lifeCycleDependencyResolver; - - @Requirement - private ExecutionEventCatapult eventCatapult; - - @Requirement - private CacheController cacheController; - - @Requirement - private CacheConfig cacheConfig; - - @Requirement( role = MojoExecutionListener.class, hint = "MojoParametersListener" ) - private MojoParametersListener mojoListener; - - public MojoExecutor() - { - } - - public DependencyContext newDependencyContext( MavenSession session, List mojoExecutions ) - { - Set scopesToCollect = new TreeSet<>(); - Set scopesToResolve = new TreeSet<>(); - - collectDependencyRequirements( scopesToResolve, scopesToCollect, mojoExecutions ); - - return new DependencyContext( session.getCurrentProject(), scopesToCollect, scopesToResolve ); - } - - private void collectDependencyRequirements( Set scopesToResolve, Set scopesToCollect, - Collection mojoExecutions ) - { - for ( MojoExecution mojoExecution : mojoExecutions ) - { - MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); - - scopesToResolve.addAll( toScopes( mojoDescriptor.getDependencyResolutionRequired() ) ); - - scopesToCollect.addAll( toScopes( mojoDescriptor.getDependencyCollectionRequired() ) ); - } - } - - private Collection toScopes( String classpath ) - { - Collection scopes = Collections.emptyList(); - - if ( StringUtils.isNotEmpty( classpath ) ) - { - if ( Artifact.SCOPE_COMPILE.equals( classpath ) ) - { - scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED ); - } - else if ( Artifact.SCOPE_RUNTIME.equals( classpath ) ) - { - scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME ); - } - else if ( Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals( classpath ) ) - { - scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED, - Artifact.SCOPE_RUNTIME ); - } - else if ( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals( classpath ) ) - { - scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_RUNTIME ); - } - else if ( Artifact.SCOPE_TEST.equals( classpath ) ) - { - scopes = Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED, - Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST ); - } - } - return Collections.unmodifiableCollection( scopes ); - } - - public void execute( MavenSession session, List mojoExecutions, ProjectIndex projectIndex ) - throws LifecycleExecutionException - { - DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); - - PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); - - final MavenProject project = session.getCurrentProject(); - final Source source = getSource( mojoExecutions ); - - // execute clean bound goals before restoring to not interfere/slowdown clean - CacheState cacheState = DISABLED; - CacheResult result = CacheResult.empty(); - if ( source == Source.LIFECYCLE ) - { - List cleanPhase = getCleanPhase( mojoExecutions ); - for ( MojoExecution mojoExecution : cleanPhase ) - { - execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); - } - cacheState = cacheConfig.initialize( project, session ); - if ( cacheState == INITIALIZED ) - { - result = cacheController.findCachedBuild( session, project, projectIndex, mojoExecutions ); - } - } - - boolean restorable = result.isSuccess() || result.isPartialSuccess(); - boolean restored = result.isSuccess(); // if partially restored need to save increment - if ( restorable ) - { - restored &= restoreProject( result, mojoExecutions, projectIndex, dependencyContext, phaseRecorder ); - } - else - { - for ( MojoExecution mojoExecution : mojoExecutions ) - { - if ( source == Source.CLI || isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) - { - execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); - } - } - } - - if ( cacheState == INITIALIZED && ( !restorable || !restored ) ) - { - final Map executionEvents = mojoListener.getProjectExecutions( project ); - cacheController.save( result, mojoExecutions, executionEvents ); - } - - if ( cacheConfig.isFailFast() && !result.isSuccess() ) - { - throw new LifecycleExecutionException( - "Failed to restore project[" + getVersionlessProjectKey( project ) + "] from cache, failing build.", - project ); - } - } - - private Source getSource( List mojoExecutions ) - { - if ( mojoExecutions == null || mojoExecutions.isEmpty() ) - { - return null; - } - for ( MojoExecution mojoExecution : mojoExecutions ) - { - if ( mojoExecution.getSource() == Source.CLI ) - { - return Source.CLI; - } - } - return Source.LIFECYCLE; - } - - private boolean restoreProject( CacheResult cacheResult, - List mojoExecutions, - ProjectIndex projectIndex, - DependencyContext dependencyContext, - PhaseRecorder phaseRecorder ) throws LifecycleExecutionException - { - - final BuildInfo buildInfo = cacheResult.getBuildInfo(); - final MavenProject project = cacheResult.getContext().getProject(); - final MavenSession session = cacheResult.getContext().getSession(); - final List cachedSegment = buildInfo.getCachedSegment( mojoExecutions ); - - boolean restored = cacheController.restoreProjectArtifacts( cacheResult ); - if ( !restored ) - { - logger.info( - "[CACHE][" + project.getArtifactId() - + "] Cannot restore project artifacts, continuing with non cached build" ); - return false; - } - - for ( MojoExecution cacheCandidate : cachedSegment ) - { - - if ( cacheController.isForcedExecution( project, cacheCandidate ) ) - { - logger.info( - "[CACHE][" + project.getArtifactId() + "] Mojo execution is forced by project property: " - + cacheCandidate.getMojoDescriptor().getFullGoalName() ); - execute( session, cacheCandidate, projectIndex, dependencyContext, phaseRecorder ); - } - else - { - restored = verifyCacheConsistency( cacheCandidate, buildInfo, project, session, projectIndex, - dependencyContext, phaseRecorder ); - if ( !restored ) - { - break; - } - } - } - - if ( !restored ) - { - // cleanup partial state - project.getArtifact().setFile( null ); - project.getArtifact().setResolved( false ); - project.getAttachedArtifacts().clear(); - mojoListener.remove( project ); - // build as usual - for ( MojoExecution mojoExecution : cachedSegment ) - { - execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); - } - } - - for ( MojoExecution mojoExecution : buildInfo.getPostCachedSegment( mojoExecutions ) ) - { - execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); - } - return restored; - } - - private boolean verifyCacheConsistency( MojoExecution cacheCandidate, - BuildInfo cachedBuildInfo, - MavenProject project, - MavenSession session, - ProjectIndex projectIndex, - DependencyContext dependencyContext, - PhaseRecorder phaseRecorder ) throws LifecycleExecutionException - { - - AtomicBoolean consistent = new AtomicBoolean( true ); - final MojoExecutionManager mojoChecker = new MojoExecutionManager( project, cacheController, cachedBuildInfo, - consistent, logger, cacheConfig ); - - if ( mojoChecker.needCheck( cacheCandidate, session ) ) - { - try - { - // actual execution will not happen (if not forced). decision delayed to execution time - // then all properties are resolved. - cacheCandidate.setMojoExecutionManager( mojoChecker ); - IDependencyContext nop = new NoResolutionContext( dependencyContext ); - execute( session, cacheCandidate, projectIndex, nop, phaseRecorder ); - } - finally - { - cacheCandidate.setMojoExecutionManager( null ); - } - } - else - { - logger.info( - "[CACHE][" + project.getArtifactId() + "] Skipping plugin execution (cached): " - + cacheCandidate.getMojoDescriptor().getFullGoalName() ); - } - - return consistent.get(); - } - - private List getCleanPhase( List mojoExecutions ) - { - List list = new ArrayList<>(); - for ( MojoExecution mojoExecution : mojoExecutions ) - { - if ( isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) - { - break; - } - list.add( mojoExecution ); - } - return list; - } - - public void execute( MavenSession session, - MojoExecution mojoExecution, - ProjectIndex projectIndex, - IDependencyContext dependencyContext, - PhaseRecorder phaseRecorder ) throws LifecycleExecutionException - { - execute( session, mojoExecution, projectIndex, dependencyContext ); - phaseRecorder.observeExecution( mojoExecution ); - } - - private void execute( MavenSession session, - MojoExecution mojoExecution, - ProjectIndex projectIndex, - IDependencyContext dependencyContext ) throws LifecycleExecutionException - { - MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); - - try - { - mavenPluginManager.checkRequiredMavenVersion( mojoDescriptor.getPluginDescriptor() ); - } - catch ( PluginIncompatibleException e ) - { - throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), e ); - } - - if ( mojoDescriptor.isProjectRequired() && !session.getRequest().isProjectPresent() ) - { - Throwable cause = new MissingProjectException( - "Goal requires a project to execute" + " but there is no POM in this directory (" - + session.getExecutionRootDirectory() + ")." - + " Please verify you invoked Maven from the correct directory." ); - throw new LifecycleExecutionException( mojoExecution, null, cause ); - } - - if ( mojoDescriptor.isOnlineRequired() && session.isOffline() ) - { - if ( Source.CLI.equals( mojoExecution.getSource() ) ) - { - Throwable cause = new IllegalStateException( - "Goal requires online mode for execution" + " but Maven is currently offline." ); - throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), cause ); - } - else - { - eventCatapult.fire( ExecutionEvent.Type.MojoSkipped, session, mojoExecution ); - - return; - } - } - - List forkedProjects = executeForkedExecutions( mojoExecution, session, projectIndex ); - - ensureDependenciesAreResolved( mojoDescriptor, session, dependencyContext ); - - eventCatapult.fire( ExecutionEvent.Type.MojoStarted, session, mojoExecution ); - - try - { - try - { - pluginManager.executeMojo( session, mojoExecution ); - } - catch ( MojoFailureException - | PluginManagerException - | PluginConfigurationException - | MojoExecutionException e ) - { - throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), e ); - } - - eventCatapult.fire( ExecutionEvent.Type.MojoSucceeded, session, mojoExecution ); - } - catch ( LifecycleExecutionException e ) - { - eventCatapult.fire( ExecutionEvent.Type.MojoFailed, session, mojoExecution, e ); - - throw e; - } - finally - { - for ( MavenProject forkedProject : forkedProjects ) - { - forkedProject.setExecutionProject( null ); - } - } - } - - public void ensureDependenciesAreResolved( MojoDescriptor mojoDescriptor, - MavenSession session, - IDependencyContext dependencyContext ) throws LifecycleExecutionException - - { - MavenProject project = dependencyContext.getProject(); - boolean aggregating = mojoDescriptor.isAggregator(); - - if ( dependencyContext.isResolutionRequiredForCurrentProject() ) - { - Collection scopesToCollect = dependencyContext.getScopesToCollectForCurrentProject(); - Collection scopesToResolve = dependencyContext.getScopesToResolveForCurrentProject(); - - lifeCycleDependencyResolver.resolveProjectDependencies( project, scopesToCollect, scopesToResolve, session, - aggregating, Collections.emptySet() ); - - dependencyContext.synchronizeWithProjectState(); - } - - if ( aggregating ) - { - Collection scopesToCollect = toScopes( mojoDescriptor.getDependencyCollectionRequired() ); - Collection scopesToResolve = toScopes( mojoDescriptor.getDependencyResolutionRequired() ); - - if ( dependencyContext.isResolutionRequiredForAggregatedProjects( scopesToCollect, scopesToResolve ) ) - { - for ( MavenProject aggregatedProject : session.getProjects() ) - { - if ( aggregatedProject != project ) - { - lifeCycleDependencyResolver.resolveProjectDependencies( aggregatedProject, scopesToCollect, - scopesToResolve, session, aggregating, Collections.emptySet() ); - } - } - } - } - - ArtifactFilter artifactFilter = getArtifactFilter( mojoDescriptor ); - List projectsToResolve = LifecycleDependencyResolver.getProjects( session.getCurrentProject(), - session, mojoDescriptor.isAggregator() ); - for ( MavenProject projectToResolve : projectsToResolve ) - { - projectToResolve.setArtifactFilter( artifactFilter ); - } - } - - private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor ) - { - String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired(); - String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired(); - - List scopes = new ArrayList<>( 2 ); - if ( StringUtils.isNotEmpty( scopeToCollect ) ) - { - scopes.add( scopeToCollect ); - } - if ( StringUtils.isNotEmpty( scopeToResolve ) ) - { - scopes.add( scopeToResolve ); - } - - if ( scopes.isEmpty() ) - { - return null; - } - else - { - return new CumulativeScopeArtifactFilter( scopes ); - } - } - - public List executeForkedExecutions( MojoExecution mojoExecution, - MavenSession session, - ProjectIndex projectIndex ) throws LifecycleExecutionException - { - List forkedProjects = Collections.emptyList(); - - Map> forkedExecutions = mojoExecution.getForkedExecutions(); - - if ( !forkedExecutions.isEmpty() ) - { - eventCatapult.fire( ExecutionEvent.Type.ForkStarted, session, mojoExecution ); - - MavenProject project = session.getCurrentProject(); - - forkedProjects = new ArrayList<>( forkedExecutions.size() ); - - try - { - for ( Map.Entry> fork : forkedExecutions.entrySet() ) - { - String projectId = fork.getKey(); - - int index = projectIndex.getIndices().get( projectId ); - - MavenProject forkedProject = projectIndex.getProjects().get( projectId ); - - forkedProjects.add( forkedProject ); - - MavenProject executedProject = forkedProject.clone(); - - forkedProject.setExecutionProject( executedProject ); - - List mojoExecutions = fork.getValue(); - - if ( mojoExecutions.isEmpty() ) - { - continue; - } - - try - { - session.setCurrentProject( executedProject ); - session.getProjects().set( index, executedProject ); - projectIndex.getProjects().put( projectId, executedProject ); - - eventCatapult.fire( ExecutionEvent.Type.ForkedProjectStarted, session, mojoExecution ); - - execute( session, mojoExecutions, projectIndex ); - - eventCatapult.fire( ExecutionEvent.Type.ForkedProjectSucceeded, session, mojoExecution ); - } - catch ( LifecycleExecutionException e ) - { - eventCatapult.fire( ExecutionEvent.Type.ForkedProjectFailed, session, mojoExecution, e ); - - throw e; - } - finally - { - projectIndex.getProjects().put( projectId, forkedProject ); - session.getProjects().set( index, forkedProject ); - session.setCurrentProject( project ); - } - } - - eventCatapult.fire( ExecutionEvent.Type.ForkSucceeded, session, mojoExecution ); - } - catch ( LifecycleExecutionException e ) - { - eventCatapult.fire( ExecutionEvent.Type.ForkFailed, session, mojoExecution, e ); + void execute( MavenSession session, List mojoExecutions, ProjectIndex projectIndex ) + throws LifecycleExecutionException; - throw e; - } - } + List executeForkedExecutions( MojoExecution mojoExecution, MavenSession session, + ProjectIndex projectIndex ) + throws LifecycleExecutionException; - return forkedProjects; - } -} +} \ No newline at end of file diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java index 1650e24eb681..a9cdb4a301db 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java @@ -21,6 +21,7 @@ import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.project.MavenProject; import java.util.ArrayList; import java.util.Collections; @@ -30,12 +31,11 @@ * @author Kristian Rosenvold */ public class MojoExecutorStub - extends MojoExecutor + implements MojoExecutor { // This is being lazy instead of making interface public List executions = Collections.synchronizedList( new ArrayList() ); - @Override public void execute(MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, IDependencyContext dependencyContext, PhaseRecorder phaseRecorder ) throws LifecycleExecutionException @@ -50,8 +50,13 @@ public void execute( MavenSession session, List mojoExecutions, P executions.addAll(mojoExecutions); } + @Override + public List executeForkedExecutions( MojoExecution mojoExecution, MavenSession session, ProjectIndex projectIndex ) throws LifecycleExecutionException + { + return null; + } - public static MojoDescriptor createMojoDescriptor( String mojoDescription ) + public static MojoDescriptor createMojoDescriptor(String mojoDescription ) { final PluginDescriptor descriptor = new PluginDescriptor(); descriptor.setArtifactId( mojoDescription ); diff --git a/pom.xml b/pom.xml index e722bab36258..4c1203adbd9c 100644 --- a/pom.xml +++ b/pom.xml @@ -86,6 +86,7 @@ under the License. maven-model maven-model-builder maven-core + maven-caching maven-settings maven-settings-builder maven-artifact From cf5566d5f64608c3164740ca073e4f37ddf04ac6 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 08:40:48 +0100 Subject: [PATCH 109/188] [MNG-7324] Use plural in lists, fix model --- .../maven/caching/CacheControllerImpl.java | 2 +- .../java/org/apache/maven/caching/CacheDiff.java | 16 ++++++++-------- .../apache/maven/caching/HttpRepositoryImpl.java | 2 +- .../caching/checksum/MavenProjectInput.java | 8 ++++---- .../org/apache/maven/caching/xml/DtoUtils.java | 16 +++++----------- maven-caching/src/main/mdo/cache-buildinfo.mdo | 4 ++-- maven-caching/src/main/mdo/cache-buildsdiff.mdo | 2 +- maven-caching/src/main/mdo/cache-report.mdo | 2 +- .../org/apache/maven/caching/BuildInfoTest.java | 6 +++--- 9 files changed, 26 insertions(+), 32 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index eac5feb2662a..a858456dd987 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -771,7 +771,7 @@ else if ( result.getSource() == CacheSource.BUILD && cacheConfig.isSaveToRemote( projectReport.setSharedToRemote( true ); projectReport.setUrl( remoteCache.getResourceUrl( context, BUILDINFO_XML ) ); } - cacheReport.getProject().add( projectReport ); + cacheReport.addProject( projectReport ); } String buildId = UUID.randomUUID().toString(); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java index 29e18d2fea4a..76c4dca548f6 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java @@ -75,7 +75,7 @@ public BuildDiffType compare() compareDependencies( current.getProjectsInputInfo(), baseline.getProjectsInputInfo() ); final BuildDiffType buildDiffType = new BuildDiffType(); - buildDiffType.getMismatch().addAll( report ); + buildDiffType.getMismatches().addAll( report ); return buildDiffType; } @@ -100,7 +100,7 @@ private void compareEffectivePoms( ProjectsInputInfoType current, ProjectsInputI public static Optional findPom( ProjectsInputInfoType projectInputs ) { - for ( DigestItemType digestItemType : projectInputs.getItem() ) + for ( DigestItemType digestItemType : projectInputs.getItems() ) { if ( "pom".equals( digestItemType.getType() ) ) { @@ -115,7 +115,7 @@ private void compareFiles( ProjectsInputInfoType current, ProjectsInputInfoType { final Map currentFiles = new HashMap<>(); - for ( DigestItemType item : current.getItem() ) + for ( DigestItemType item : current.getItems() ) { if ( "file".equals( item.getType() ) ) { @@ -124,7 +124,7 @@ private void compareFiles( ProjectsInputInfoType current, ProjectsInputInfoType } final Map baselineFiles = new HashMap<>(); - for ( DigestItemType item : baseline.getItem() ) + for ( DigestItemType item : baseline.getItems() ) { if ( "file".equals( item.getType() ) ) { @@ -181,7 +181,7 @@ private void compareFiles( ProjectsInputInfoType current, ProjectsInputInfoType private void compareDependencies( ProjectsInputInfoType current, ProjectsInputInfoType baseline ) { final Map currentDependencies = new HashMap<>(); - for ( DigestItemType digestItemType : current.getItem() ) + for ( DigestItemType digestItemType : current.getItems() ) { if ( "dependency".equals( digestItemType.getType() ) ) { @@ -189,7 +189,7 @@ private void compareDependencies( ProjectsInputInfoType current, ProjectsInputIn } } final Map baselineDependencies = new HashMap<>(); - for ( DigestItemType item : baseline.getItem() ) + for ( DigestItemType item : baseline.getItems() ) { if ( "dependency".equals( item.getType() ) ) { @@ -285,7 +285,7 @@ private void comparePlugins( CompletedExecutionType current, CompletedExecutionT { // TODO add support for skip values final List trackedProperties = new ArrayList<>(); - for ( PropertyValueType propertyValueType : current.getConfiguration() ) + for ( PropertyValueType propertyValueType : current.getProperties() ) { if ( propertyValueType.isTracked() ) { @@ -298,7 +298,7 @@ private void comparePlugins( CompletedExecutionType current, CompletedExecutionT } final Map baselinePropertiesByName = new HashMap<>(); - for ( PropertyValueType propertyValueType : baseline.getConfiguration() ) + for ( PropertyValueType propertyValueType : baseline.getProperties() ) { baselinePropertiesByName.put( propertyValueType.getName(), propertyValueType ); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java index d32460da07fd..48f30e911479 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java @@ -247,7 +247,7 @@ private void putToRemoteCache( InputStream instream, String url, String logRefer public Optional findBaselineBuild( MavenProject project ) { final Optional> cachedProjectsHolder = findCacheInfo() - .transform( CacheReportType::getProject ); + .transform( CacheReportType::getProjects ); if ( !cachedProjectsHolder.isPresent() ) { return Optional.absent(); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 089e02de9988..bbfe96076fbe 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -262,13 +262,13 @@ public ProjectsInputInfoType calculateChecksum( HashFactory hashFactory ) throws final ProjectsInputInfoType projectsInputInfoType = new ProjectsInputInfoType(); projectsInputInfoType.setChecksum( checksum.digest() ); - projectsInputInfoType.getItem().addAll( items ); + projectsInputInfoType.getItems().addAll( items ); final long checksumTime = Clock.elapsed( time ); if ( logger.isDebugEnabled() ) { - for ( DigestItemType item : projectsInputInfoType.getItem() ) + for ( DigestItemType item : projectsInputInfoType.getItems() ) { logger.debug( "Hash calculated, item: " + item.getType() + ", hash: " + item.getHash() ); } @@ -283,7 +283,7 @@ public ProjectsInputInfoType calculateChecksum( HashFactory hashFactory ) throws private void checkEffectivePomMatch( ProjectsInputInfoType baselineBuild, DigestItemType effectivePomChecksum ) { Optional pomHolder = Optional.absent(); - for ( DigestItemType it : baselineBuild.getItem() ) + for ( DigestItemType it : baselineBuild.getItems() ) { if ( it.getType().equals( "pom" ) ) { @@ -309,7 +309,7 @@ private void checkEffectivePomMatch( ProjectsInputInfoType baselineBuild, Digest private boolean checkItemMatchesBaseline( ProjectsInputInfoType baselineBuild, DigestItemType fileDigest ) { Optional baselineFileDigest = Optional.absent(); - for ( DigestItemType it : baselineBuild.getItem() ) + for ( DigestItemType it : baselineBuild.getItems() ) { if ( it.getType().equals( fileDigest.getType() ) && fileDigest.getValue().equals( it.getValue().trim() ) ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java index d44ab3753584..3754f34f4638 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java @@ -32,7 +32,6 @@ import javax.annotation.Nonnull; -import java.util.ArrayList; import java.util.List; import static org.apache.maven.caching.checksum.KeyUtils.getArtifactKey; @@ -45,12 +44,11 @@ public class DtoUtils public static String findPropertyValue( String propertyName, CompletedExecutionType completedExecution ) { - final List configuration = completedExecution.getConfiguration(); - if ( configuration == null ) + final List properties = completedExecution.getProperties(); + if ( properties == null ) { return null; } - final List properties = configuration; for ( PropertyValueType property : properties ) { if ( StringUtils.equals( propertyName, property.getName() ) ) @@ -124,10 +122,6 @@ public static void addProperty( CompletedExecutionType execution, String baseDirPath, boolean tracked ) { - if ( execution.getConfiguration() == null ) - { - execution.setConfiguration( new ArrayList<>() ); - } final PropertyValueType valueType = new PropertyValueType(); valueType.setName( propertyName ); if ( value != null && value.getClass().isArray() ) @@ -137,7 +131,7 @@ public static void addProperty( CompletedExecutionType execution, final String valueText = String.valueOf( value ); valueType.setValue( StringUtils.remove( valueText, baseDirPath ) ); valueType.setTracked( tracked ); - execution.getConfiguration().add( valueType ); + execution.addProperty( valueType ); } public static boolean containsAllProperties( @@ -149,12 +143,12 @@ public static boolean containsAllProperties( return true; } - if ( cachedExecution.getConfiguration() == null ) + if ( cachedExecution.getProperties() == null ) { return false; } - final List executionProperties = cachedExecution.getConfiguration(); + final List executionProperties = cachedExecution.getProperties(); for ( TrackedPropertyType trackedProperty : trackedProperties ) { if ( !contains( executionProperties, trackedProperty.getPropertyName() ) ) diff --git a/maven-caching/src/main/mdo/cache-buildinfo.mdo b/maven-caching/src/main/mdo/cache-buildinfo.mdo index 0659d76256d1..2c324e3a269f 100644 --- a/maven-caching/src/main/mdo/cache-buildinfo.mdo +++ b/maven-caching/src/main/mdo/cache-buildinfo.mdo @@ -269,7 +269,7 @@ under the License. String - configuration + properties PropertyValueType * @@ -320,7 +320,7 @@ under the License. String - item + items DigestItemType * diff --git a/maven-caching/src/main/mdo/cache-buildsdiff.mdo b/maven-caching/src/main/mdo/cache-buildsdiff.mdo index 45bdfe1d0a8d..3a67fb043091 100644 --- a/maven-caching/src/main/mdo/cache-buildsdiff.mdo +++ b/maven-caching/src/main/mdo/cache-buildsdiff.mdo @@ -42,7 +42,7 @@ under the License. BuildDiffType - mismatch + mismatches MismatchType * diff --git a/maven-caching/src/main/mdo/cache-report.mdo b/maven-caching/src/main/mdo/cache-report.mdo index fed8d24f5472..0ba3b1d21970 100644 --- a/maven-caching/src/main/mdo/cache-report.mdo +++ b/maven-caching/src/main/mdo/cache-report.mdo @@ -36,7 +36,7 @@ under the License. CacheReportType - project + projects ProjectReportType * diff --git a/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java b/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java index 18a62753c873..9c96fc21041b 100644 --- a/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java @@ -54,8 +54,8 @@ public void name() throws Exception { ProjectsInputInfoType main = new ProjectsInputInfoType(); main.setChecksum("dependencyChecksum"); - main.getItem().add(createItem("pom", "4.0.0", "hash1")); - main.getItem().add(createItem("file", Paths.get(".").toString(), "hash2")); + main.addItem(createItem("pom", "4.0.0", "hash1")); + main.addItem(createItem("file", Paths.get(".").toString(), "hash2")); ArtifactType artifact = new ArtifactType(); artifact.setGroupId("g"); @@ -96,7 +96,7 @@ private List createExecutions() { PropertyValueType property = new PropertyValueType(); property.setValue("value"); property.setName("key"); - execution.setConfiguration(new ArrayList<>(Arrays.asList(property))); + execution.addProperty(property); return new ArrayList<>(Arrays.asList(execution)); } From 063b4b1ddc09c0cb8790cc085cf6fe1cc4ac3623 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 09:42:25 +0100 Subject: [PATCH 110/188] [MNG-7321] Include the new module in the distribution, uses CDI for annotations --- apache-maven/pom.xml | 4 + .../maven/caching/CacheControllerImpl.java | 90 ++++++++++--------- .../apache/maven/caching/CacheEventSpy.java | 14 +-- .../maven/caching/HttpRepositoryImpl.java | 39 ++++---- .../maven/caching/LocalRepositoryImpl.java | 51 ++++++----- .../maven/caching/MojoParametersListener.java | 20 +++-- .../maven/caching/xml/CacheConfigImpl.java | 42 ++++----- .../apache/maven/caching/xml/XmlService.java | 27 +++--- pom.xml | 5 ++ 9 files changed, 160 insertions(+), 132 deletions(-) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index 5f713bb71c29..6bba99f3b193 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -47,6 +47,10 @@ under the License. org.apache.maven maven-core
    + + org.apache.maven + maven-caching + org.apache.maven maven-compat diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index a858456dd987..7a35bbeab444 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -19,6 +19,34 @@ * under the License. */ +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.regex.Pattern; + +import javax.annotation.Nonnull; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import com.google.common.base.Optional; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -31,6 +59,13 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.caching.checksum.KeyUtils; import org.apache.maven.caching.checksum.MavenProjectInput; +import org.apache.maven.caching.hash.HashAlgorithm; +import org.apache.maven.caching.hash.HashFactory; +import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.CacheSource; +import org.apache.maven.caching.xml.DtoUtils; +import org.apache.maven.caching.xml.XmlService; import org.apache.maven.caching.xml.buildinfo.ArtifactType; import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; import org.apache.maven.caching.xml.buildinfo.DigestItemType; @@ -41,13 +76,6 @@ import org.apache.maven.caching.xml.config.TrackedPropertyType; import org.apache.maven.caching.xml.report.CacheReportType; import org.apache.maven.caching.xml.report.ProjectReportType; -import org.apache.maven.caching.hash.HashAlgorithm; -import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.xml.BuildInfo; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.CacheSource; -import org.apache.maven.caching.xml.DtoUtils; -import org.apache.maven.caching.xml.XmlService; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MojoExecutionEvent; import org.apache.maven.lifecycle.internal.ProjectIndex; @@ -58,35 +86,9 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.apache.maven.repository.RepositorySystem; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.ReflectionUtils; -import javax.annotation.Nonnull; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.StandardCopyOption; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.TreeSet; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.regex.Pattern; - import static java.nio.file.StandardOpenOption.CREATE; import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -104,38 +106,40 @@ /** * CacheControllerImpl */ -@Component( role = CacheController.class ) +@Singleton +@Named public class CacheControllerImpl implements CacheController { public static final String FILE_SEPARATOR_SUBST = "_"; private static final String GENERATEDSOURCES = "generatedsources"; private static final String GENERATEDSOURCES_PREFIX = GENERATEDSOURCES + FILE_SEPARATOR_SUBST; - @Requirement + + @Inject private Logger logger; - @Requirement + @Inject private MavenPluginManager mavenPluginManager; - @Requirement + @Inject private MavenProjectHelper projectHelper; - @Requirement + @Inject private LocalArtifactsRepository localCache; - @Requirement + @Inject private RemoteArtifactsRepository remoteCache; - @Requirement + @Inject private CacheConfig cacheConfig; - @Requirement + @Inject private RepositorySystem repoSystem; - @Requirement + @Inject private ArtifactHandlerManager artifactHandlerManager; - @Requirement + @Inject private XmlService xmlService; private final ConcurrentMap artifactDigestByKey = new ConcurrentHashMap<>(); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java index 3cd5578d9be3..39b83d6b70a3 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java @@ -19,23 +19,25 @@ * under the License. */ +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.eventspy.AbstractEventSpy; -import org.apache.maven.eventspy.EventSpy; import org.apache.maven.execution.ExecutionEvent; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; /** * Triggers cache report generation on build completion */ -@Component( role = EventSpy.class ) +@Singleton +@Named public class CacheEventSpy extends AbstractEventSpy { - @Requirement + @Inject private CacheConfig cacheConfig; - @Requirement + @Inject private CacheController cacheController; @Override diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java index 48f30e911479..2f1604e18ce4 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java @@ -19,6 +19,17 @@ * under the License. */ +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import com.google.common.base.Optional; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; @@ -33,48 +44,40 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.maven.artifact.Artifact; import org.apache.maven.caching.checksum.MavenProjectInput; -import org.apache.maven.caching.xml.buildinfo.ArtifactType; -import org.apache.maven.caching.xml.buildinfo.BuildInfoType; -import org.apache.maven.caching.xml.report.CacheReportType; -import org.apache.maven.caching.xml.report.ProjectReportType; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; import org.apache.maven.caching.xml.XmlService; +import org.apache.maven.caching.xml.buildinfo.ArtifactType; +import org.apache.maven.caching.xml.buildinfo.BuildInfoType; +import org.apache.maven.caching.xml.report.CacheReportType; +import org.apache.maven.caching.xml.report.ProjectReportType; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.util.List; -import java.util.concurrent.atomic.AtomicReference; - /** * HttpRepositoryImpl */ -@Component( role = RemoteArtifactsRepository.class ) +@Singleton +@Named public class HttpRepositoryImpl implements RemoteArtifactsRepository { public static final String BUILDINFO_XML = "buildinfo.xml"; public static final String CACHE_REPORT_XML = "cache-report.xml"; - @Requirement + @Inject private Logger logger; - @Requirement + @Inject LegacySupport legacySupport; - @Requirement + @Inject XmlService xmlService; - @Requirement + @Inject private CacheConfig cacheConfig; @SuppressWarnings( {"checkstyle:constantname", "checkstyle:magicnumber"} ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java index 7b7d465d04e2..92737c55ba4f 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java @@ -19,6 +19,26 @@ * under the License. */ +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.cache.CacheBuilder; @@ -43,26 +63,8 @@ import org.apache.maven.model.Dependency; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; -import java.io.File; -import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.StandardCopyOption; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; - import static java.nio.file.StandardOpenOption.CREATE; import static java.nio.file.StandardOpenOption.CREATE_NEW; import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; @@ -76,7 +78,8 @@ /** * LocalRepositoryImpl */ -@Component( role = LocalArtifactsRepository.class ) +@Singleton +@Named public class LocalRepositoryImpl implements LocalArtifactsRepository { @@ -90,19 +93,19 @@ public class LocalRepositoryImpl implements LocalArtifactsRepository private static final Function, Long> GET_LAST_MODIFIED = pair -> pair.getRight().lastModified(); - @Requirement + @Inject private Logger logger; - @Requirement + @Inject private LegacySupport legacySupport; - @Requirement + @Inject private RemoteArtifactsRepository remoteRepository; - @Requirement + @Inject private XmlService xmlService; - @Requirement + @Inject private CacheConfig cacheConfig; private final LoadingCache, Optional> bestBuildCache = diff --git a/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java index 8750a8dcca67..78c81befdfdd 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java @@ -19,30 +19,32 @@ * under the License. */ +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.execution.MojoExecutionEvent; import org.apache.maven.execution.MojoExecutionListener; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - /** * MojoParametersListener */ -@Component( role = MojoExecutionListener.class, - hint = "MojoParametersListener" ) +@Singleton +@Named public class MojoParametersListener implements MojoExecutionListener { private final ConcurrentMap> projectExecutions = new ConcurrentHashMap<>(); - @Requirement + @Inject private Logger logger; @Override diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 398ef511dd0a..1177994e0f52 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -19,6 +19,19 @@ * under the License. */ +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.regex.Pattern; + +import javax.annotation.Nonnull; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import org.apache.commons.lang3.StringUtils; @@ -28,42 +41,31 @@ import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.xml.config.AttachedOutputs; -import org.apache.maven.caching.xml.config.Exclude; -import org.apache.maven.caching.xml.config.Include; -import org.apache.maven.caching.xml.config.Local; -import org.apache.maven.caching.xml.config.ProjectDiscoveryStrategy; -import org.apache.maven.caching.xml.config.Remote; import org.apache.maven.caching.xml.config.CacheType; import org.apache.maven.caching.xml.config.ConfigurationType; import org.apache.maven.caching.xml.config.CoordinatesBaseType; +import org.apache.maven.caching.xml.config.Exclude; import org.apache.maven.caching.xml.config.ExecutablesType; import org.apache.maven.caching.xml.config.ExecutionConfigurationScanType; import org.apache.maven.caching.xml.config.ExecutionControlType; import org.apache.maven.caching.xml.config.ExecutionIdsListType; import org.apache.maven.caching.xml.config.GoalReconciliationType; import org.apache.maven.caching.xml.config.GoalsListType; +import org.apache.maven.caching.xml.config.Include; +import org.apache.maven.caching.xml.config.Local; import org.apache.maven.caching.xml.config.PluginConfigurationScanType; import org.apache.maven.caching.xml.config.PluginSetType; +import org.apache.maven.caching.xml.config.ProjectDiscoveryStrategy; import org.apache.maven.caching.xml.config.PropertyNameType; +import org.apache.maven.caching.xml.config.Remote; import org.apache.maven.caching.xml.config.TrackedPropertyType; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; -import javax.annotation.Nonnull; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.regex.Pattern; - import static com.google.common.base.Preconditions.checkState; import static java.lang.Boolean.TRUE; import static java.lang.Boolean.parseBoolean; @@ -72,8 +74,8 @@ /** * CacheConfigImpl */ -@Component( role = CacheConfig.class, - instantiationStrategy = "singleton" ) +@Singleton +@Named public class CacheConfigImpl implements CacheConfig { @@ -84,10 +86,10 @@ public class CacheConfigImpl implements CacheConfig public static final String FAIL_FAST_PROPERTY_NAME = "remote.cache.failFast"; public static final String BASELINE_BUILD_URL_PROPERTY_NAME = "remote.cache.baselineUrl"; - @Requirement + @Inject private Logger logger; - @Requirement + @Inject private XmlService xmlService; private volatile CacheState state = CacheState.NOT_INITIALIZED; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java index 44bd917cc7da..0cfe506ee262 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java @@ -19,32 +19,35 @@ * under the License. */ -import org.apache.maven.caching.xml.config.CacheType; -import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Reader; -import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Writer; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; + +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.caching.xml.buildinfo.BuildInfoType; import org.apache.maven.caching.xml.buildinfo.io.xpp3.CacheBuildInfoXpp3Reader; import org.apache.maven.caching.xml.buildinfo.io.xpp3.CacheBuildInfoXpp3Writer; import org.apache.maven.caching.xml.buildsdiff.BuildDiffType; import org.apache.maven.caching.xml.buildsdiff.io.xpp3.CacheBuildsDiffXpp3Reader; import org.apache.maven.caching.xml.buildsdiff.io.xpp3.CacheBuildsDiffXpp3Writer; +import org.apache.maven.caching.xml.config.CacheType; +import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Reader; +import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Writer; import org.apache.maven.caching.xml.report.CacheReportType; import org.apache.maven.caching.xml.report.io.xpp3.CacheReportXpp3Reader; import org.apache.maven.caching.xml.report.io.xpp3.CacheReportXpp3Writer; -import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; - /** * XmlService */ -@Component( role = XmlService.class ) +@Singleton +@Named public class XmlService { diff --git a/pom.xml b/pom.xml index 4c1203adbd9c..e88bd7514cb4 100644 --- a/pom.xml +++ b/pom.xml @@ -198,6 +198,11 @@ under the License. maven-core ${project.version} + + org.apache.maven + maven-caching + ${project.version} + org.apache.maven maven-model-builder From 4694f6e44a48f59f92976e84036a4b9d4592fe60 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 10:19:58 +0100 Subject: [PATCH 111/188] [MNG-7322] Use maven session / project properties instead of System.getProperty() --- .../maven/caching/LocalRepositoryImpl.java | 2 +- .../apache/maven/caching/ProjectUtils.java | 7 ++- .../maven/caching/xml/CacheConfigImpl.java | 46 ++++++++++++------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java index 92737c55ba4f..e9985d42ecf9 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java @@ -409,7 +409,7 @@ public void saveBuildInfo( CacheResult cacheResult, BuildInfo buildInfo ) throws @Override public void saveCacheReport( String buildId, MavenSession session, CacheReportType cacheReport ) throws IOException { - Path path = Paths.get( getMultimoduleRoot( session ), "target", "maven-incremental" ); + Path path = getMultimoduleRoot( session ).resolve( "target" ).resolve( "maven-incremental" ); Files.createDirectories( path ); Files.write( path.resolve( "cache-report." + buildId + ".xml" ), xmlService.toBytes( cacheReport ), TRUNCATE_EXISTING, CREATE ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java index a6bdd7a6b958..49d2bb712400 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java @@ -38,7 +38,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import static com.google.common.base.Preconditions.checkArgument; @@ -150,15 +149,15 @@ public static String mojoExecutionKey( MojoExecution mojo ) StringUtils.defaultIfEmpty( mojo.getVersion(), "emptyVersion" ) ), ":" ); } - public static String getMultimoduleRoot( MavenSession session ) + public static Path getMultimoduleRoot( MavenSession session ) { - return System.getProperty( "maven.multiModuleProjectDirectory", session.getExecutionRootDirectory() ); + return session.getRequest().getMultiModuleProjectDirectory().toPath(); } public static Scm readGitInfo( MavenSession session ) throws IOException { final Scm scmCandidate = new Scm(); - final Path gitDir = Paths.get( getMultimoduleRoot( session ), ".git" ); + final Path gitDir = getMultimoduleRoot( session ).resolve( ".git" ); if ( Files.isDirectory( gitDir ) ) { final Path headFile = gitDir.resolve( "HEAD" ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 1177994e0f52..536bdffca350 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -95,6 +95,8 @@ public class CacheConfigImpl implements CacheConfig private volatile CacheState state = CacheState.NOT_INITIALIZED; private volatile CacheType cacheConfig; private volatile HashFactory hashFactory; + private MavenSession session; + private MavenProject project; private final Supplier> excludePatterns = Suppliers.memoize( new Supplier>() { @@ -115,7 +117,10 @@ public synchronized CacheState initialize( MavenProject project, MavenSession se return state; } - final String enabled = System.getProperty( CACHE_ENABLED_PROPERTY_NAME, "true" ); + this.project = project; + this.session = session; + + final String enabled = getProperty( CACHE_ENABLED_PROPERTY_NAME, "true" ); if ( !parseBoolean( enabled ) ) { logger.info( "Cache disabled by command line flag, project will be built fully and not cached" ); @@ -123,25 +128,16 @@ public synchronized CacheState initialize( MavenProject project, MavenSession se return state; } - Path configPath = null; + Path configPath; - String configPathText = System.getProperty( CONFIG_PATH_PROPERTY_NAME ); + String configPathText = getProperty( CONFIG_PATH_PROPERTY_NAME, null ); if ( StringUtils.isNotBlank( configPathText ) ) { configPath = Paths.get( configPathText ); } - if ( configPath == null ) - { - configPathText = project.getProperties().getProperty( CONFIG_PATH_PROPERTY_NAME ); - if ( StringUtils.isNotBlank( configPathText ) ) - { - configPath = Paths.get( configPathText ); - } - } - - if ( configPath == null ) + else { - configPath = Paths.get( getMultimoduleRoot( session ), ".mvn", "maven-cache-config.xml" ); + configPath = getMultimoduleRoot( session ).resolve( ".mvn" ).resolve( "maven-cache-config.xml" ); } if ( !Files.exists( configPath ) ) @@ -510,13 +506,13 @@ public boolean isFailFast() @Override public boolean isBaselineDiffEnabled() { - return System.getProperties().containsKey( BASELINE_BUILD_URL_PROPERTY_NAME ); + return getProperty( BASELINE_BUILD_URL_PROPERTY_NAME, null ) != null; } @Override public String getBaselineCacheUrl() { - return System.getProperty( BASELINE_BUILD_URL_PROPERTY_NAME ); + return getProperty( BASELINE_BUILD_URL_PROPERTY_NAME, null ); } @Override @@ -583,4 +579,22 @@ private void checkInitializedState() { checkState( state == CacheState.INITIALIZED, "Cache is not initialized. Actual state: " + state ); } + + private String getProperty( String key, String defaultValue ) + { + String value = session.getUserProperties().getProperty( key ); + if ( value == null ) + { + value = session.getSystemProperties().getProperty( key ); + if ( value == null ) + { + value = project.getProperties().getProperty( key ); + if ( value == null ) + { + value = defaultValue; + } + } + } + return value; + } } From 1716c48811544a7ef98c8387dbfd2f7de6a11654 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 10:20:41 +0100 Subject: [PATCH 112/188] [MNG-7321] Use a provided scope for maven-core --- maven-caching/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/maven-caching/pom.xml b/maven-caching/pom.xml index 1cc41ab7207e..c4ab8fd3cb67 100644 --- a/maven-caching/pom.xml +++ b/maven-caching/pom.xml @@ -38,6 +38,7 @@ under the License. org.apache.maven maven-core + provided From c2c9c926c2da1b84b8cfb593fc376ac520807b07 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 14:51:39 +0100 Subject: [PATCH 113/188] [MNG-7325] Rename namespaces, add more test for XmlService --- .../src/main/mdo/cache-buildinfo.mdo | 3 +- .../src/main/mdo/cache-buildsdiff.mdo | 3 +- maven-caching/src/main/mdo/cache-config.mdo | 5 +- maven-caching/src/main/mdo/cache-report.mdo | 3 +- .../maven/caching/xml/CacheConfigTest.java | 35 ------- .../maven/caching/xml/XmlServiceTest.java | 96 +++++++++++++++++++ .../caching/xml/cache-buildinfo-instance.xml | 14 +-- .../caching/xml/cache-buildsdiff-instance.xml | 31 ++++++ .../caching/xml/cache-config-instance.xml | 4 +- .../caching/xml/cache-report-instance.xml | 32 +++++++ 10 files changed, 177 insertions(+), 49 deletions(-) delete mode 100644 maven-caching/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java create mode 100644 maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java create mode 100644 maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildsdiff-instance.xml create mode 100644 maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-report-instance.xml diff --git a/maven-caching/src/main/mdo/cache-buildinfo.mdo b/maven-caching/src/main/mdo/cache-buildinfo.mdo index 2c324e3a269f..9dacce39b94c 100644 --- a/maven-caching/src/main/mdo/cache-buildinfo.mdo +++ b/maven-caching/src/main/mdo/cache-buildinfo.mdo @@ -19,7 +19,8 @@ under the License. + xml.namespace="http://maven.apache.org/CACHE-BUILDINFO/${version}" + xml.schemaLocation="http://maven.apache.org/xsd/cache-buildinfo-${version}.xsd"> cache-buildinfo CacheBuildInfo lookupinfo.xml or remote buildinfo.xml diff --git a/maven-caching/src/main/mdo/cache-buildsdiff.mdo b/maven-caching/src/main/mdo/cache-buildsdiff.mdo index 3a67fb043091..c9af0a9d8351 100644 --- a/maven-caching/src/main/mdo/cache-buildsdiff.mdo +++ b/maven-caching/src/main/mdo/cache-buildsdiff.mdo @@ -19,7 +19,8 @@ under the License. + xml.namespace="http://maven.apache.org/CACHE-BUILDSDIFF/${version}" + xml.schemaLocation="http://maven.apache.org/xsd/cache-buildsdiff-${version}.xsd"> cache-buildsdiff CacheBuildsDiff buildsdiff-${checksum}.xml diff --git a/maven-caching/src/main/mdo/cache-config.mdo b/maven-caching/src/main/mdo/cache-config.mdo index 05d80546289a..1e94cef5921f 100644 --- a/maven-caching/src/main/mdo/cache-config.mdo +++ b/maven-caching/src/main/mdo/cache-config.mdo @@ -19,9 +19,8 @@ under the License. + xml.namespace="http://maven.apache.org/CACHE-CONFIG/${version}" + xml.schemaLocation="http://maven.apache.org/xsd/cache-config-${version}.xsd"> cache-config CacheConfig .mvn/maven-cache-config.xml diff --git a/maven-caching/src/main/mdo/cache-report.mdo b/maven-caching/src/main/mdo/cache-report.mdo index 0ba3b1d21970..5d6375cd7dff 100644 --- a/maven-caching/src/main/mdo/cache-report.mdo +++ b/maven-caching/src/main/mdo/cache-report.mdo @@ -19,7 +19,8 @@ under the License. + xml.namespace="http://maven.apache.org/CACHE-REPORT/${version}" + xml.schemaLocation="http://maven.apache.org/xsd/cache-report-${version}.xsd"> cache-report CacheReport cache-report.xml diff --git a/maven-caching/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java b/maven-caching/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java deleted file mode 100644 index 8b81a78dfdbc..000000000000 --- a/maven-caching/src/test/java/org/apache/maven/caching/xml/CacheConfigTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.maven.caching.xml; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.caching.xml.config.CacheType; -import org.junit.Test; - -import java.io.InputStream; - -public class CacheConfigTest { - - @Test - public void testMU() { - InputStream is = getClass().getResourceAsStream( "cache-config-instance.xml" ); - final CacheType cacheConfig = new XmlService().fromInputStream( CacheType.class, is ); - System.out.println(cacheConfig.toString()); - } -} \ No newline at end of file diff --git a/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java b/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java new file mode 100644 index 000000000000..5a5e340fbc50 --- /dev/null +++ b/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java @@ -0,0 +1,96 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.caching.xml.buildinfo.BuildInfoType; +import org.apache.maven.caching.xml.buildinfo.io.xpp3.CacheBuildInfoXpp3Reader; +import org.apache.maven.caching.xml.buildsdiff.BuildDiffType; +import org.apache.maven.caching.xml.config.CacheType; +import org.apache.maven.caching.xml.report.CacheReportType; +import org.junit.Test; + +import java.io.InputStream; + +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.w3c.dom.Document; + +public class XmlServiceTest { + + @Test + public void testConfig() throws Exception { + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema schema = sf.newSchema(getClass().getResource("/cache-config-1.0.0.xsd")); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setSchema(schema); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse( getClass().getResource( "cache-config-instance.xml" ).toString() ); + + InputStream is = getClass().getResourceAsStream( "cache-config-instance.xml" ); + final CacheType cacheConfig = new XmlService().fromInputStream( CacheType.class, is ); + } + + @Test + public void testReport() throws Exception { + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema schema = sf.newSchema(getClass().getResource("/cache-report-1.0.0.xsd")); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setSchema(schema); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse( getClass().getResource( "cache-report-instance.xml" ).toString() ); + + InputStream is = getClass().getResourceAsStream( "cache-report-instance.xml" ); + final CacheReportType cacheReport = new XmlService().fromInputStream( CacheReportType.class, is ); + } + + @Test + public void testBuildInfo() throws Exception { + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema schema = sf.newSchema(getClass().getResource("/cache-buildinfo-1.0.0.xsd")); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setSchema(schema); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse( getClass().getResource( "cache-buildinfo-instance.xml" ).toString() ); + + InputStream is = getClass().getResourceAsStream( "cache-buildinfo-instance.xml" ); + final BuildInfoType buildInfo = new XmlService().fromInputStream( BuildInfoType.class, is ); + } + + @Test + public void testBuildsDiff() throws Exception { + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema schema = sf.newSchema(getClass().getResource("/cache-buildsdiff-1.0.0.xsd")); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setSchema(schema); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse( getClass().getResource( "cache-buildsdiff-instance.xml" ).toString() ); + + InputStream is = getClass().getResourceAsStream( "cache-buildsdiff-instance.xml" ); + final BuildDiffType buildInfo = new XmlService().fromInputStream( BuildDiffType.class, is ); + } +} \ No newline at end of file diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildinfo-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildinfo-instance.xml index 9dd0c7cc054b..94c129ded569 100644 --- a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildinfo-instance.xml +++ b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildinfo-instance.xml @@ -19,11 +19,11 @@ specific language governing permissions and limitations under the License. --> - + xsi:schemaLocation="http://maven.apache.org/CACHE-BUILDINFO/1.0.0 ../../../../../../../../target/generated-sources/modello/cache-buildinfo-1.0.0.xsd"> v3 - 1980-03-23T10:20:15 + 1980-03-23T10:20:15.000 my-server.com SHA-256 @@ -51,14 +51,16 @@ under the License. default:check:verify:duplicate-finder-maven-plugin:org.basepom.maven:1.3.0 org.basepom.mojo.duplicatefinder.DuplicateFinderMojo - + true false - + 0136171ac2c9d9b066805bd09904a25318cfb2037189b20c48e79b20b63b81ed - src/main/conf/my-context.xml + + src/main/conf/my-context.xml + diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildsdiff-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildsdiff-instance.xml new file mode 100644 index 000000000000..407cd36ccf2d --- /dev/null +++ b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildsdiff-instance.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml index 92e3ce767fa0..8451304e6606 100644 --- a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml +++ b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml @@ -19,9 +19,9 @@ specific language governing permissions and limitations under the License. --> - + xsi:schemaLocation="http://maven.apache.org/CACHE-CONFIG/1.0.0 ../../../../../../../../target/generated-sources/modello/cache-config-1.0.0.xsd"> true diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-report-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-report-instance.xml new file mode 100644 index 000000000000..9d685bae43ec --- /dev/null +++ b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-report-instance.xml @@ -0,0 +1,32 @@ + + + + + + + + + org.apache.maven + + + + From f1d0d76e14b95bb857d0dc868724958231ac41cb Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 16:26:38 +0100 Subject: [PATCH 114/188] [MNG-7328] Remove the `Type` suffix on the generated model classes --- .../maven/caching/ArtifactsRepository.java | 4 +- .../apache/maven/caching/CacheContext.java | 8 +- .../maven/caching/CacheControllerImpl.java | 109 +++++++++--------- .../org/apache/maven/caching/CacheDiff.java | 102 ++++++++-------- .../caching/DefaultPluginScanConfig.java | 4 +- .../maven/caching/HttpRepositoryImpl.java | 50 ++++---- .../caching/LocalArtifactsRepository.java | 4 +- .../maven/caching/LocalRepositoryImpl.java | 88 +++++++------- .../maven/caching/MojoExecutionManager.java | 12 +- .../maven/caching/PluginScanConfig.java | 4 +- .../maven/caching/PluginScanConfigImpl.java | 26 ++--- .../caching/RemoteArtifactsRepository.java | 4 +- .../maven/caching/checksum/DigestUtils.java | 16 +-- .../maven/caching/checksum/KeyUtils.java | 7 +- .../caching/checksum/MavenProjectInput.java | 50 ++++---- .../apache/maven/caching/xml/BuildInfo.java | 58 +++++----- .../apache/maven/caching/xml/CacheConfig.java | 10 +- .../maven/caching/xml/CacheConfigImpl.java | 92 +++++++-------- .../apache/maven/caching/xml/DtoUtils.java | 49 ++++---- .../apache/maven/caching/xml/XmlService.java | 24 ++-- .../src/main/mdo/cache-buildinfo.mdo | 24 ++-- .../src/main/mdo/cache-buildsdiff.mdo | 10 +- maven-caching/src/main/mdo/cache-config.mdo | 100 ++++++++-------- maven-caching/src/main/mdo/cache-report.mdo | 6 +- .../apache/maven/caching/BuildInfoTest.java | 36 +++--- .../maven/caching/xml/XmlServiceTest.java | 17 ++- 26 files changed, 456 insertions(+), 458 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java index c72781d35407..af73bebd9401 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java @@ -20,7 +20,7 @@ */ import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.xml.report.CacheReportType; +import org.apache.maven.caching.xml.report.CacheReport; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.execution.MavenSession; @@ -38,5 +38,5 @@ public interface ArtifactsRepository void saveArtifactFile( CacheResult cacheResult, Artifact artifact ) throws IOException; - void saveCacheReport( String buildId, MavenSession session, CacheReportType cacheReport ) throws IOException; + void saveCacheReport( String buildId, MavenSession session, CacheReport cacheReport ) throws IOException; } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java index d485687178d0..51c1b78fe6d8 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfoType; +import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfo; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; @@ -31,10 +31,10 @@ public class CacheContext { private final MavenProject project; - private final ProjectsInputInfoType inputInfo; + private final ProjectsInputInfo inputInfo; private final MavenSession session; - public CacheContext( MavenProject project, ProjectsInputInfoType inputInfo, MavenSession session ) + public CacheContext( MavenProject project, ProjectsInputInfo inputInfo, MavenSession session ) { this.project = checkNotNull( project ); this.inputInfo = checkNotNull( inputInfo ); @@ -46,7 +46,7 @@ public MavenProject getProject() return project; } - public ProjectsInputInfoType getInputInfo() + public ProjectsInputInfo getInputInfo() { return inputInfo; } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 7a35bbeab444..ed258028639c 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -54,7 +54,6 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.mutable.MutableBoolean; -import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.caching.checksum.KeyUtils; @@ -66,16 +65,16 @@ import org.apache.maven.caching.xml.CacheSource; import org.apache.maven.caching.xml.DtoUtils; import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.caching.xml.buildinfo.ArtifactType; -import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; -import org.apache.maven.caching.xml.buildinfo.DigestItemType; -import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfoType; +import org.apache.maven.caching.xml.buildinfo.Artifact; +import org.apache.maven.caching.xml.buildinfo.CompletedExecution; +import org.apache.maven.caching.xml.buildinfo.DigestItem; +import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfo; import org.apache.maven.caching.xml.buildinfo.Scm; -import org.apache.maven.caching.xml.buildsdiff.BuildDiffType; -import org.apache.maven.caching.xml.config.PropertyNameType; -import org.apache.maven.caching.xml.config.TrackedPropertyType; -import org.apache.maven.caching.xml.report.CacheReportType; -import org.apache.maven.caching.xml.report.ProjectReportType; +import org.apache.maven.caching.xml.buildsdiff.BuildDiff; +import org.apache.maven.caching.xml.config.PropertyName; +import org.apache.maven.caching.xml.config.TrackedProperty; +import org.apache.maven.caching.xml.report.CacheReport; +import org.apache.maven.caching.xml.report.ProjectReport; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MojoExecutionEvent; import org.apache.maven.lifecycle.internal.ProjectIndex; @@ -142,7 +141,7 @@ public class CacheControllerImpl implements CacheController @Inject private XmlService xmlService; - private final ConcurrentMap artifactDigestByKey = new ConcurrentHashMap<>(); + private final ConcurrentMap artifactDigestByKey = new ConcurrentHashMap<>(); private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); @@ -162,7 +161,7 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, logInfo( project, "Attempting to restore project from build cache" ); - ProjectsInputInfoType inputInfo = calculateInput( project, session, projectIndex ); + ProjectsInputInfo inputInfo = calculateInput( project, session, projectIndex ); final CacheContext context = new CacheContext( project, inputInfo, session ); // remote build first @@ -224,7 +223,7 @@ private CacheResult analyzeResult( CacheContext context, List moj { final MavenProject project = context.getProject(); - final ProjectsInputInfoType inputInfo = context.getInputInfo(); + final ProjectsInputInfo inputInfo = context.getInputInfo(); logInfo( project, "Found cached build, restoring from cache " + inputInfo.getChecksum() ); @@ -304,7 +303,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) final CacheContext context = cacheResult.getContext(); final MavenProject project = context.getProject(); - final ArtifactType artifact = buildInfo.getArtifact(); + final Artifact artifact = buildInfo.getArtifact(); artifact.setVersion( project.getVersion() ); try @@ -324,7 +323,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) putChecksum( artifact, context.getInputInfo().getChecksum() ); } - for ( ArtifactType attachedArtifact : buildInfo.getAttachedArtifacts() ) + for ( Artifact attachedArtifact : buildInfo.getAttachedArtifacts() ) { attachedArtifact.setVersion( project.getVersion() ); if ( isNotBlank( attachedArtifact.getFileName() ) ) @@ -369,17 +368,17 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) return true; } - private void putChecksum( ArtifactType artifact, String projectChecksum ) + private void putChecksum( Artifact artifact, String projectChecksum ) { - final DigestItemType projectArtifact = DtoUtils.createdDigestedByProjectChecksum( artifact, projectChecksum ); + final DigestItem projectArtifact = DtoUtils.createdDigestedByProjectChecksum( artifact, projectChecksum ); final String dependencyKey = KeyUtils.getArtifactKey( artifact ); artifactDigestByKey.put( dependencyKey, projectArtifact ); if ( !"pom".equals( artifact.getType() ) ) { final ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() ); - ArtifactType copy = DtoUtils.copy( artifact ); + Artifact copy = DtoUtils.copy( artifact ); copy.setType( artifactHandler.getPackaging() ); artifactDigestByKey.put( KeyUtils.getArtifactKey( copy ), projectArtifact ); copy.setType( artifactHandler.getExtension() ); @@ -387,7 +386,7 @@ private void putChecksum( ArtifactType artifact, String projectChecksum ) } } - private ProjectsInputInfoType calculateInput( MavenProject project, MavenSession session, + private ProjectsInputInfo calculateInput( MavenProject project, MavenSession session, ProjectIndex projectIndex ) { try @@ -423,16 +422,16 @@ public void save( CacheResult cacheResult, List mojoExecutions, attachGeneratedSources( project ); attachOutputs( project ); - final Artifact projectArtifact = project.getArtifact(); + final org.apache.maven.artifact.Artifact projectArtifact = project.getArtifact(); final HashFactory hashFactory = cacheConfig.getHashFactory(); final HashAlgorithm algorithm = hashFactory.createAlgorithm(); - final ArtifactType projectArtifactDto = artifactDto( project.getArtifact(), algorithm ); + final Artifact projectArtifactDto = artifactDto( project.getArtifact(), algorithm ); - final List attachedArtifacts = + final List attachedArtifacts = project.getAttachedArtifacts() != null ? project.getAttachedArtifacts() : Collections.emptyList(); - List attachedArtifactDtos = artifactDtos( attachedArtifacts, algorithm ); + List attachedArtifactDtos = artifactDtos( attachedArtifacts, algorithm ); - List completedExecution = buildExecutionInfo( mojoExecutions, executionEvents ); + List completedExecution = buildExecutionInfo( mojoExecutions, executionEvents ); final BuildInfo buildInfo = new BuildInfo( session.getGoals(), projectArtifactDto, attachedArtifactDtos, context.getInputInfo(), completedExecution, hashFactory.getAlgorithm() ); @@ -450,7 +449,7 @@ public void save( CacheResult cacheResult, List mojoExecutions, localCache.saveArtifactFile( cacheResult, projectArtifact ); putChecksum( projectArtifactDto, context.getInputInfo().getChecksum() ); } - for ( Artifact attachedArtifact : attachedArtifacts ) + for ( org.apache.maven.artifact.Artifact attachedArtifact : attachedArtifacts ) { if ( attachedArtifact.getFile() != null && isOutputArtifact( attachedArtifact.getFile().getName() ) ) @@ -458,7 +457,7 @@ public void save( CacheResult cacheResult, List mojoExecutions, localCache.saveArtifactFile( cacheResult, attachedArtifact ); } } - for ( ArtifactType attachedArtifactDto : attachedArtifactDtos ) + for ( Artifact attachedArtifactDto : attachedArtifactDtos ) { putChecksum( attachedArtifactDto, context.getInputInfo().getChecksum() ); } @@ -498,11 +497,11 @@ public void produceDiffReport( CacheResult cacheResult, BuildInfo buildInfo ) String outputDirectory = project.getBuild().getDirectory(); Path reportOutputDir = Paths.get( outputDirectory, "incremental-maven" ); logInfo( project, "Saving cache builds diff to: " + reportOutputDir ); - BuildDiffType diff = new CacheDiff( buildInfo.getDto(), baseline.getDto(), cacheConfig ).compare(); + BuildDiff diff = new CacheDiff( buildInfo.getDto(), baseline.getDto(), cacheConfig ).compare(); try { Files.createDirectories( reportOutputDir ); - final ProjectsInputInfoType baselineInputs = baseline.getDto().getProjectsInputInfo(); + final ProjectsInputInfo baselineInputs = baseline.getDto().getProjectsInputInfo(); final String checksum = baselineInputs.getChecksum(); Files.write( reportOutputDir.resolve( "buildinfo-baseline-" + checksum + ".xml" ), xmlService.toBytes( baseline.getDto() ), TRUNCATE_EXISTING, CREATE ); @@ -510,14 +509,14 @@ public void produceDiffReport( CacheResult cacheResult, BuildInfo buildInfo ) xmlService.toBytes( buildInfo.getDto() ), TRUNCATE_EXISTING, CREATE ); Files.write( reportOutputDir.resolve( "buildsdiff-" + checksum + ".xml" ), xmlService.toBytes( diff ), TRUNCATE_EXISTING, CREATE ); - final Optional pom = CacheDiff.findPom( buildInfo.getDto().getProjectsInputInfo() ); + final Optional pom = CacheDiff.findPom( buildInfo.getDto().getProjectsInputInfo() ); if ( pom.isPresent() ) { Files.write( reportOutputDir.resolve( "effective-pom-" + checksum + ".xml" ), pom.get().getValue().getBytes( StandardCharsets.UTF_8 ), TRUNCATE_EXISTING, CREATE ); } - final Optional baselinePom = CacheDiff.findPom( baselineInputs ); + final Optional baselinePom = CacheDiff.findPom( baselineInputs ); if ( baselinePom.isPresent() ) { Files.write( reportOutputDir.resolve( @@ -537,10 +536,11 @@ public void produceDiffReport( CacheResult cacheResult, BuildInfo buildInfo ) } } - private List artifactDtos( List attachedArtifacts, HashAlgorithm digest ) throws IOException + private List artifactDtos( List attachedArtifacts, + HashAlgorithm digest ) throws IOException { - List result = new ArrayList<>(); - for ( Artifact attachedArtifact : attachedArtifacts ) + List result = new ArrayList<>(); + for ( org.apache.maven.artifact.Artifact attachedArtifact : attachedArtifacts ) { if ( attachedArtifact.getFile() != null && isOutputArtifact( attachedArtifact.getFile().getName() ) ) { @@ -550,9 +550,10 @@ private List artifactDtos( List attachedArtifacts, HashA return result; } - private ArtifactType artifactDto( Artifact projectArtifact, HashAlgorithm algorithm ) throws IOException + private Artifact artifactDto( org.apache.maven.artifact.Artifact projectArtifact, + HashAlgorithm algorithm ) throws IOException { - final ArtifactType dto = DtoUtils.createDto( projectArtifact ); + final Artifact dto = DtoUtils.createDto( projectArtifact ); if ( projectArtifact.getFile() != null && projectArtifact.getFile().isFile() ) { final Path file = projectArtifact.getFile().toPath(); @@ -562,15 +563,15 @@ private ArtifactType artifactDto( Artifact projectArtifact, HashAlgorithm algori return dto; } - private List buildExecutionInfo( List mojoExecutions, - Map executionEvents ) + private List buildExecutionInfo( List mojoExecutions, + Map executionEvents ) { - List list = new ArrayList<>(); + List list = new ArrayList<>(); for ( MojoExecution mojoExecution : mojoExecutions ) { final String executionKey = ProjectUtils.mojoExecutionKey( mojoExecution ); final MojoExecutionEvent executionEvent = executionEvents.get( executionKey ); - CompletedExecutionType executionInfo = new CompletedExecutionType(); + CompletedExecution executionInfo = new CompletedExecution(); executionInfo.setExecutionKey( executionKey ); executionInfo.setMojoClassName( mojoExecution.getMojoDescriptor().getImplementation() ); if ( executionEvent != null ) @@ -582,14 +583,14 @@ private List buildExecutionInfo( List moj return list; } - private void recordMojoProperties( CompletedExecutionType execution, MojoExecutionEvent executionEvent ) + private void recordMojoProperties( CompletedExecution execution, MojoExecutionEvent executionEvent ) { final MojoExecution mojoExecution = executionEvent.getExecution(); final boolean logAll = cacheConfig.isLogAllProperties( mojoExecution ); - List trackedProperties = cacheConfig.getTrackedProperties( mojoExecution ); - List noLogProperties = cacheConfig.getNologProperties( mojoExecution ); - List forceLogProperties = cacheConfig.getLoggedProperties( mojoExecution ); + List trackedProperties = cacheConfig.getTrackedProperties( mojoExecution ); + List noLogProperties = cacheConfig.getNologProperties( mojoExecution ); + List forceLogProperties = cacheConfig.getLoggedProperties( mojoExecution ); final Mojo mojo = executionEvent.getMojo(); final File baseDir = executionEvent.getProject().getBasedir(); @@ -630,13 +631,13 @@ private void recordMojoProperties( CompletedExecutionType execution, MojoExecuti } } - private boolean isExcluded( String propertyName, boolean logAll, List excludedProperties, - List forceLogProperties ) + private boolean isExcluded( String propertyName, boolean logAll, List excludedProperties, + List forceLogProperties ) { if ( !forceLogProperties.isEmpty() ) { - for ( PropertyNameType logProperty : forceLogProperties ) + for ( PropertyName logProperty : forceLogProperties ) { if ( StringUtils.equals( propertyName, logProperty.getPropertyName() ) ) { @@ -648,7 +649,7 @@ private boolean isExcluded( String propertyName, boolean logAll, List trackedProperties ) + private boolean isTracked( String propertyName, List trackedProperties ) { - for ( TrackedPropertyType trackedProperty : trackedProperties ) + for ( TrackedProperty trackedProperty : trackedProperties ) { if ( StringUtils.equals( propertyName, trackedProperty.getPropertyName() ) ) { @@ -680,8 +681,8 @@ private boolean isCachedSegmentPropertiesPresent( MavenProject project, BuildInf { // completion of all mojos checked above, so we expect tp have execution info here - final List trackedProperties = cacheConfig.getTrackedProperties( mojoExecution ); - final CompletedExecutionType cachedExecution = buildInfo.findMojoExecutionInfo( mojoExecution ); + final List trackedProperties = cacheConfig.getTrackedProperties( mojoExecution ); + final CompletedExecution cachedExecution = buildInfo.findMojoExecutionInfo( mojoExecution ); if ( cachedExecution == null ) { @@ -753,10 +754,10 @@ public void saveCacheReport( MavenSession session ) try { - CacheReportType cacheReport = new CacheReportType(); + CacheReport cacheReport = new CacheReport(); for ( CacheResult result : cacheResults.values() ) { - ProjectReportType projectReport = new ProjectReportType(); + ProjectReport projectReport = new ProjectReport(); CacheContext context = result.getContext(); MavenProject project = context.getProject(); projectReport.setGroupId( project.getGroupId() ); @@ -841,7 +842,7 @@ private Path classifierToPath( Path outputDir, String classifier ) return outputDir.resolve( relPath ); } - private void restoreGeneratedSources( ArtifactType artifact, Path artifactFilePath, MavenProject project ) + private void restoreGeneratedSources( Artifact artifact, Path artifactFilePath, MavenProject project ) throws IOException { final Path targetDir = Paths.get( project.getBuild().getDirectory() ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java index 76c4dca548f6..c3bde3dbb117 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java @@ -22,13 +22,13 @@ import com.google.common.base.Optional; import com.google.common.collect.Sets; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.xml.buildinfo.BuildInfoType; -import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; -import org.apache.maven.caching.xml.buildinfo.DigestItemType; -import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfoType; -import org.apache.maven.caching.xml.buildinfo.PropertyValueType; -import org.apache.maven.caching.xml.buildsdiff.BuildDiffType; -import org.apache.maven.caching.xml.buildsdiff.MismatchType; +import org.apache.maven.caching.xml.buildinfo.BuildInfo; +import org.apache.maven.caching.xml.buildinfo.CompletedExecution; +import org.apache.maven.caching.xml.buildinfo.DigestItem; +import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfo; +import org.apache.maven.caching.xml.buildinfo.PropertyValue; +import org.apache.maven.caching.xml.buildsdiff.BuildDiff; +import org.apache.maven.caching.xml.buildsdiff.Mismatch; import org.apache.maven.caching.xml.CacheConfig; import java.util.ArrayList; @@ -44,11 +44,11 @@ public class CacheDiff { private final CacheConfig config; - private final BuildInfoType current; - private final BuildInfoType baseline; - private final LinkedList report; + private final BuildInfo current; + private final BuildInfo baseline; + private final LinkedList report; - public CacheDiff( BuildInfoType current, BuildInfoType baseline, CacheConfig config ) + public CacheDiff( BuildInfo current, BuildInfo baseline, CacheConfig config ) { this.current = current; this.baseline = baseline; @@ -56,7 +56,7 @@ public CacheDiff( BuildInfoType current, BuildInfoType baseline, CacheConfig con this.report = new LinkedList<>(); } - public BuildDiffType compare() + public BuildDiff compare() { if ( !StringUtils.equals( current.getHashFunction(), baseline.getHashFunction() ) ) @@ -74,17 +74,17 @@ public BuildDiffType compare() compareFiles( current.getProjectsInputInfo(), baseline.getProjectsInputInfo() ); compareDependencies( current.getProjectsInputInfo(), baseline.getProjectsInputInfo() ); - final BuildDiffType buildDiffType = new BuildDiffType(); + final BuildDiff buildDiffType = new BuildDiff(); buildDiffType.getMismatches().addAll( report ); return buildDiffType; } - private void compareEffectivePoms( ProjectsInputInfoType current, ProjectsInputInfoType baseline ) + private void compareEffectivePoms( ProjectsInputInfo current, ProjectsInputInfo baseline ) { - Optional currentPom = findPom( current ); + Optional currentPom = findPom( current ); String currentPomHash = currentPom.isPresent() ? currentPom.get().getHash() : null; - Optional baseLinePom = findPom( baseline ); + Optional baseLinePom = findPom( baseline ); String baselinePomHash = baseLinePom.isPresent() ? baseLinePom.get().getHash() : null; if ( !StringUtils.equals( currentPomHash, baselinePomHash ) ) @@ -98,9 +98,9 @@ private void compareEffectivePoms( ProjectsInputInfoType current, ProjectsInputI } } - public static Optional findPom( ProjectsInputInfoType projectInputs ) + public static Optional findPom( ProjectsInputInfo projectInputs ) { - for ( DigestItemType digestItemType : projectInputs.getItems() ) + for ( DigestItem digestItemType : projectInputs.getItems() ) { if ( "pom".equals( digestItemType.getType() ) ) { @@ -111,11 +111,11 @@ public static Optional findPom( ProjectsInputInfoType projectInp return Optional.absent(); } - private void compareFiles( ProjectsInputInfoType current, ProjectsInputInfoType baseline ) + private void compareFiles( ProjectsInputInfo current, ProjectsInputInfo baseline ) { - final Map currentFiles = new HashMap<>(); - for ( DigestItemType item : current.getItems() ) + final Map currentFiles = new HashMap<>(); + for ( DigestItem item : current.getItems() ) { if ( "file".equals( item.getType() ) ) { @@ -123,8 +123,8 @@ private void compareFiles( ProjectsInputInfoType current, ProjectsInputInfoType } } - final Map baselineFiles = new HashMap<>(); - for ( DigestItemType item : baseline.getItems() ) + final Map baselineFiles = new HashMap<>(); + for ( DigestItem item : baseline.getItems() ) { if ( "file".equals( item.getType() ) ) { @@ -147,12 +147,12 @@ private void compareFiles( ProjectsInputInfoType current, ProjectsInputInfoType return; } - for ( Map.Entry entry : currentFiles.entrySet() ) + for ( Map.Entry entry : currentFiles.entrySet() ) { String filePath = entry.getKey(); - DigestItemType currentFile = entry.getValue(); + DigestItem currentFile = entry.getValue(); // should be null safe because sets are compared above for differences - final DigestItemType baselineFile = baselineFiles.get( filePath ); + final DigestItem baselineFile = baselineFiles.get( filePath ); if ( !StringUtils.equals( currentFile.getHash(), baselineFile.getHash() ) ) { @@ -178,18 +178,18 @@ private void compareFiles( ProjectsInputInfoType current, ProjectsInputInfoType } } - private void compareDependencies( ProjectsInputInfoType current, ProjectsInputInfoType baseline ) + private void compareDependencies( ProjectsInputInfo current, ProjectsInputInfo baseline ) { - final Map currentDependencies = new HashMap<>(); - for ( DigestItemType digestItemType : current.getItems() ) + final Map currentDependencies = new HashMap<>(); + for ( DigestItem digestItemType : current.getItems() ) { if ( "dependency".equals( digestItemType.getType() ) ) { currentDependencies.put( digestItemType.getValue(), digestItemType ); } } - final Map baselineDependencies = new HashMap<>(); - for ( DigestItemType item : baseline.getItems() ) + final Map baselineDependencies = new HashMap<>(); + for ( DigestItem item : baseline.getItems() ) { if ( "dependency".equals( item.getType() ) ) { @@ -214,12 +214,12 @@ private void compareDependencies( ProjectsInputInfoType current, ProjectsInputIn return; } - for ( Map.Entry entry : currentDependencies.entrySet() ) + for ( Map.Entry entry : currentDependencies.entrySet() ) { String dependencyKey = entry.getKey(); - DigestItemType currentDependency = entry.getValue(); + DigestItem currentDependency = entry.getValue(); // null safe - sets compared for differences above - final DigestItemType baselineDependency = baselineDependencies.get( dependencyKey ); + final DigestItem baselineDependency = baselineDependencies.get( dependencyKey ); if ( !StringUtils.equals( currentDependency.getHash(), baselineDependency.getHash() ) ) { addNewMismatch( dependencyKey, currentDependency.getHash(), baselineDependency.getHash(), @@ -232,23 +232,23 @@ private void compareDependencies( ProjectsInputInfoType current, ProjectsInputIn } - private void compareExecutions( List current, List baseline ) + private void compareExecutions( List current, List baseline ) { - Map baselineExecutionsByKey = new HashMap<>(); - for ( CompletedExecutionType completedExecutionType : baseline ) + Map baselineExecutionsByKey = new HashMap<>(); + for ( CompletedExecution completedExecutionType : baseline ) { baselineExecutionsByKey.put( completedExecutionType.getExecutionKey(), completedExecutionType ); } - Map currentExecutionsByKey = new HashMap<>(); - for ( CompletedExecutionType e1 : current ) + Map currentExecutionsByKey = new HashMap<>(); + for ( CompletedExecution e1 : current ) { currentExecutionsByKey.put( e1.getExecutionKey(), e1 ); } // such situation normally means different poms and mismatch in effective poms, // but in any case it is helpful to report - for ( CompletedExecutionType baselineExecution : baseline ) + for ( CompletedExecution baselineExecution : baseline ) { if ( !currentExecutionsByKey.containsKey( baselineExecution.getExecutionKey() ) ) { @@ -261,7 +261,7 @@ private void compareExecutions( List current, List current, List trackedProperties = new ArrayList<>(); - for ( PropertyValueType propertyValueType : current.getProperties() ) + final List trackedProperties = new ArrayList<>(); + for ( PropertyValue propertyValueType : current.getProperties() ) { if ( propertyValueType.isTracked() ) { @@ -297,15 +297,15 @@ private void comparePlugins( CompletedExecutionType current, CompletedExecutionT return; } - final Map baselinePropertiesByName = new HashMap<>(); - for ( PropertyValueType propertyValueType : baseline.getProperties() ) + final Map baselinePropertiesByName = new HashMap<>(); + for ( PropertyValue propertyValueType : baseline.getProperties() ) { baselinePropertiesByName.put( propertyValueType.getName(), propertyValueType ); } - for ( PropertyValueType p : trackedProperties ) + for ( PropertyValue p : trackedProperties ) { - final PropertyValueType baselineValue = baselinePropertiesByName.get( p.getName() ); + final PropertyValue baselineValue = baselinePropertiesByName.get( p.getName() ); if ( baselineValue == null || !StringUtils.equals( baselineValue.getValue(), p.getValue() ) ) { addNewMismatch( @@ -325,7 +325,7 @@ private void comparePlugins( CompletedExecutionType current, CompletedExecutionT private void addNewMismatch( String item, String current, String baseline, String reason, String resolution ) { - final MismatchType mismatch = new MismatchType(); + final Mismatch mismatch = new Mismatch(); mismatch.setItem( item ); mismatch.setCurrent( current ); mismatch.setBaseline( baseline ); @@ -336,7 +336,7 @@ private void addNewMismatch( String item, String current, String baseline, Strin private void addNewMismatch( String property, String reason, String resolution ) { - final MismatchType mismatchType = new MismatchType(); + final Mismatch mismatchType = new Mismatch(); mismatchType.setItem( property ); mismatchType.setReason( reason ); mismatchType.setResolution( resolution ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java index cff0375d3d1a..31d7cb2ec663 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.xml.config.DirScanConfigType; +import org.apache.maven.caching.xml.config.DirScanConfig; import javax.annotation.Nonnull; @@ -56,7 +56,7 @@ public ScanConfigProperties getTagScanProperties( String tagName ) } @Override - public DirScanConfigType dto() + public DirScanConfig dto() { return null; } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java index 2f1604e18ce4..686d762e783a 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java @@ -42,16 +42,14 @@ import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.maven.artifact.Artifact; import org.apache.maven.caching.checksum.MavenProjectInput; -import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.caching.xml.buildinfo.ArtifactType; -import org.apache.maven.caching.xml.buildinfo.BuildInfoType; -import org.apache.maven.caching.xml.report.CacheReportType; -import org.apache.maven.caching.xml.report.ProjectReportType; +import org.apache.maven.caching.xml.buildinfo.Artifact; +import org.apache.maven.caching.xml.buildinfo.BuildInfo; +import org.apache.maven.caching.xml.report.CacheReport; +import org.apache.maven.caching.xml.report.ProjectReport; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.project.MavenProject; @@ -95,28 +93,29 @@ protected HttpClient initialValue() }; @Override - public BuildInfo findBuild( CacheContext context ) + public org.apache.maven.caching.xml.BuildInfo findBuild( CacheContext context ) { final String resourceUrl = getResourceUrl( context, BUILDINFO_XML ); String artifactId = context.getProject().getArtifactId(); if ( exists( artifactId, resourceUrl ) ) { final byte[] bytes = getResourceContent( resourceUrl, artifactId ); - final BuildInfoType dto = xmlService.fromBytes( BuildInfoType.class, bytes ); - return new BuildInfo( dto, CacheSource.REMOTE ); + final BuildInfo dto = xmlService.fromBytes( BuildInfo.class, bytes ); + return new org.apache.maven.caching.xml.BuildInfo( dto, CacheSource.REMOTE ); } return null; } @Override - public byte[] getArtifactContent( CacheContext context, ArtifactType artifact ) + public byte[] getArtifactContent( CacheContext context, Artifact artifact ) { return getResourceContent( getResourceUrl( context, artifact.getFileName() ), context.getProject().getArtifactId() ); } @Override - public void saveBuildInfo( CacheResult cacheResult, BuildInfo buildInfo ) throws IOException + public void saveBuildInfo( CacheResult cacheResult, org.apache.maven.caching.xml.BuildInfo buildInfo ) + throws IOException { CacheContext context = cacheResult.getContext(); final String resourceUrl = getResourceUrl( cacheResult.getContext(), BUILDINFO_XML ); @@ -126,7 +125,7 @@ public void saveBuildInfo( CacheResult cacheResult, BuildInfo buildInfo ) throws @Override - public void saveCacheReport( String buildId, MavenSession session, CacheReportType cacheReport ) throws IOException + public void saveCacheReport( String buildId, MavenSession session, CacheReport cacheReport ) throws IOException { MavenProject rootProject = session.getTopLevelProject(); final String resourceUrl = cacheConfig.getUrl() + "/" + MavenProjectInput.CACHE_IMPLMENTATION_VERSION @@ -139,7 +138,8 @@ public void saveCacheReport( String buildId, MavenSession session, CacheReportTy } @Override - public void saveArtifactFile( CacheResult cacheResult, Artifact artifact ) throws IOException + public void saveArtifactFile( CacheResult cacheResult, + org.apache.maven.artifact.Artifact artifact ) throws IOException { CacheContext context = cacheResult.getContext(); final String resourceUrl = getResourceUrl( cacheResult.getContext(), ProjectUtils.normalizedName( artifact ) ); @@ -244,20 +244,20 @@ private void putToRemoteCache( InputStream instream, String url, String logRefer } } - private final AtomicReference>> cacheReportSupplier = new AtomicReference<>(); + private final AtomicReference>> cacheReportSupplier = new AtomicReference<>(); @Override - public Optional findBaselineBuild( MavenProject project ) + public Optional findBaselineBuild( MavenProject project ) { - final Optional> cachedProjectsHolder = findCacheInfo() - .transform( CacheReportType::getProjects ); + final Optional> cachedProjectsHolder = findCacheInfo() + .transform( CacheReport::getProjects ); if ( !cachedProjectsHolder.isPresent() ) { return Optional.absent(); } - Optional cachedProjectHolder = Optional.absent(); - for ( ProjectReportType p : cachedProjectsHolder.get() ) + Optional cachedProjectHolder = Optional.absent(); + for ( ProjectReport p : cachedProjectsHolder.get() ) { if ( project.getArtifactId().equals( p.getArtifactId() ) && project.getGroupId().equals( p.getGroupId() ) ) @@ -270,7 +270,7 @@ public Optional findBaselineBuild( MavenProject project ) if ( cachedProjectHolder.isPresent() ) { String url; - final ProjectReportType projectReport = cachedProjectHolder.get(); + final ProjectReport projectReport = cachedProjectHolder.get(); if ( projectReport.getUrl() != null ) { url = cachedProjectHolder.get().getUrl(); @@ -288,8 +288,8 @@ public Optional findBaselineBuild( MavenProject project ) if ( exists( project.getArtifactId(), url ) ) { byte[] content = getResourceContent( url, project.getArtifactId() ); - final BuildInfoType dto = xmlService.fromBytes( BuildInfoType.class, content ); - return Optional.of( new BuildInfo( dto, CacheSource.REMOTE ) ); + final BuildInfo dto = xmlService.fromBytes( BuildInfo.class, content ); + return Optional.of( new org.apache.maven.caching.xml.BuildInfo( dto, CacheSource.REMOTE ) ); } else { @@ -307,17 +307,17 @@ public Optional findBaselineBuild( MavenProject project ) return Optional.absent(); } - private Optional findCacheInfo() + private Optional findCacheInfo() { - Supplier> candidate = Suppliers.memoize( () -> + Supplier> candidate = Suppliers.memoize( () -> { try { logInfo( "Downloading baseline cache report from: " + cacheConfig.getBaselineCacheUrl(), "DEBUG" ); byte[] content = getResourceContent( cacheConfig.getBaselineCacheUrl(), "cache-info" ); - CacheReportType cacheReportType = xmlService.fromBytes( CacheReportType.class, content ); + CacheReport cacheReportType = xmlService.fromBytes( CacheReport.class, content ); return Optional.of( cacheReportType ); } catch ( Exception e ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java index c646aa76c0f7..feb091babf3d 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java @@ -22,7 +22,7 @@ import com.google.common.base.Optional; import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheSource; -import org.apache.maven.caching.xml.buildinfo.ArtifactType; +import org.apache.maven.caching.xml.buildinfo.Artifact; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; @@ -37,7 +37,7 @@ public interface LocalArtifactsRepository extends ArtifactsRepository void beforeSave( CacheContext environment ) throws IOException; - Path getArtifactFile( CacheContext context, CacheSource source, ArtifactType artifact ) throws IOException; + Path getArtifactFile( CacheContext context, CacheSource source, Artifact artifact ) throws IOException; void clearCache( CacheContext context ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java index e9985d42ecf9..e3935fdcc892 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java @@ -50,15 +50,13 @@ import com.google.common.collect.Ordering; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.tuple.Pair; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.caching.xml.buildinfo.ArtifactType; -import org.apache.maven.caching.xml.buildinfo.BuildInfoType; +import org.apache.maven.caching.xml.buildinfo.Artifact; +import org.apache.maven.caching.xml.buildinfo.BuildInfo; import org.apache.maven.caching.xml.buildinfo.Scm; -import org.apache.maven.caching.xml.report.CacheReportType; +import org.apache.maven.caching.xml.report.CacheReport; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.LegacySupport; @@ -90,7 +88,7 @@ public class LocalRepositoryImpl implements LocalArtifactsRepository private static final long ONE_DAY_MILLIS = DAYS.toMillis( 1 ); private static final String EMPTY = ""; private static final LastModifiedComparator LAST_MODIFIED_COMPARATOR = new LastModifiedComparator(); - private static final Function, Long> GET_LAST_MODIFIED = + private static final Function, Long> GET_LAST_MODIFIED = pair -> pair.getRight().lastModified(); @Inject @@ -108,27 +106,28 @@ public class LocalRepositoryImpl implements LocalArtifactsRepository @Inject private CacheConfig cacheConfig; - private final LoadingCache, Optional> bestBuildCache = - CacheBuilder.newBuilder().build( - CacheLoader.from( new Function, Optional>() + private final LoadingCache, + Optional> bestBuildCache = + CacheBuilder.newBuilder().build( CacheLoader.from( new Function, + Optional>() + { + @Override + public Optional apply( Pair input ) + { + try { - @Override - public Optional apply( Pair input ) - { - try - { - return findBestMatchingBuildImpl( input ); - } - catch ( IOException e ) - { - logger.error( "Cannot find dependency in cache", e ); - return Optional.absent(); - } - } - } ) ); + return findBestMatchingBuildImpl( input ); + } + catch ( IOException e ) + { + logger.error( "Cannot find dependency in cache", e ); + return Optional.absent(); + } + } + } ) ); @Override - public BuildInfo findLocalBuild( CacheContext context ) throws IOException + public org.apache.maven.caching.xml.BuildInfo findLocalBuild( CacheContext context ) throws IOException { Path localBuildInfoPath = localBuildPath( context, BUILDINFO_XML, false ); logDebug( context, "Checking local build info: " + localBuildInfoPath ); @@ -137,8 +136,8 @@ public BuildInfo findLocalBuild( CacheContext context ) throws IOException logInfo( context, "Local build found by checksum " + context.getInputInfo().getChecksum() ); try { - final BuildInfoType dto = xmlService.fromFile( BuildInfoType.class, localBuildInfoPath.toFile() ); - return new BuildInfo( dto, CacheSource.LOCAL ); + final BuildInfo dto = xmlService.fromFile( BuildInfo.class, localBuildInfoPath.toFile() ); + return new org.apache.maven.caching.xml.BuildInfo( dto, CacheSource.LOCAL ); } catch ( Exception e ) { @@ -150,7 +149,7 @@ public BuildInfo findLocalBuild( CacheContext context ) throws IOException } @Override - public BuildInfo findBuild( CacheContext context ) throws IOException + public org.apache.maven.caching.xml.BuildInfo findBuild( CacheContext context ) throws IOException { Path buildInfoPath = remoteBuildPath( context, BUILDINFO_XML ); @@ -161,8 +160,8 @@ public BuildInfo findBuild( CacheContext context ) throws IOException logInfo( context, "Downloaded build found by checksum " + context.getInputInfo().getChecksum() ); try { - final BuildInfoType dto = xmlService.fromFile( BuildInfoType.class, buildInfoPath.toFile() ); - return new BuildInfo( dto, CacheSource.REMOTE ); + final BuildInfo dto = xmlService.fromFile( BuildInfo.class, buildInfoPath.toFile() ); + return new org.apache.maven.caching.xml.BuildInfo( dto, CacheSource.REMOTE ); } catch ( Exception e ) { @@ -205,7 +204,7 @@ else if ( now > created + ONE_DAY_MILLIS && now < lastModified + ONE_DAY_MILLIS } } - final BuildInfo buildInfo = remoteRepository.findBuild( context ); + final org.apache.maven.caching.xml.BuildInfo buildInfo = remoteRepository.findBuild( context ); if ( buildInfo != null ) { logInfo( context, "Build info downloaded from remote repo, saving to: " + buildInfoPath ); @@ -271,13 +270,15 @@ public void clearCache( CacheContext context ) } @Override - public Optional findBestMatchingBuild( MavenSession session, Dependency dependency ) + public Optional findBestMatchingBuild( + MavenSession session, Dependency dependency ) { return bestBuildCache.getUnchecked( Pair.of( session, dependency ) ); } - private Optional findBestMatchingBuildImpl( Pair dependencySession ) + private Optional findBestMatchingBuildImpl( + Pair dependencySession ) throws IOException { final MavenSession session = dependencySession.getLeft(); @@ -285,7 +286,8 @@ private Optional findBestMatchingBuildImpl( Pair, Pair> filesByVersion = ArrayListMultimap.create(); + final Multimap, Pair> + filesByVersion = ArrayListMultimap.create(); Files.walkFileTree( artifactCacheDir, new SimpleFileVisitor() { @@ -297,9 +299,9 @@ public FileVisitResult visitFile( Path o, BasicFileAttributes basicFileAttribute { try { - final BuildInfoType dto = xmlService.fromFile( BuildInfoType.class, file ); - final Pair buildInfoAndFile = Pair.of( new BuildInfo( dto, CacheSource.LOCAL ), - file ); + final BuildInfo dto = xmlService.fromFile( BuildInfo.class, file ); + final Pair buildInfoAndFile = + Pair.of( new org.apache.maven.caching.xml.BuildInfo( dto, CacheSource.LOCAL ), file ); final String cachedVersion = dto.getArtifact().getVersion(); final String cachedBranch = getScmRef( dto.getScm() ); filesByVersion.put( Pair.of( cachedVersion, cachedBranch ), buildInfoAndFile ); @@ -329,7 +331,7 @@ public FileVisitResult visitFile( Path o, BasicFileAttributes basicFileAttribute final String currentRef = getScmRef( ProjectUtils.readGitInfo( session ) ); // first lets try by branch and version - Collection> bestMatched = new LinkedList<>(); + Collection> bestMatched = new LinkedList<>(); if ( isNotBlank( currentRef ) ) { bestMatched = filesByVersion.get( Pair.of( dependency.getVersion(), currentRef ) ); @@ -350,7 +352,7 @@ public FileVisitResult visitFile( Path o, BasicFileAttributes basicFileAttribute bestMatched = filesByVersion.values(); } - List> orderedFiles = Ordering.natural().onResultOf( + List> orderedFiles = Ordering.natural().onResultOf( GET_LAST_MODIFIED ).reverse().sortedCopy( bestMatched ); return Optional.of( orderedFiles.get( 0 ).getLeft() ); } @@ -368,7 +370,7 @@ private String getScmRef( Scm scm ) } @Override - public Path getArtifactFile( CacheContext context, CacheSource source, ArtifactType artifact ) throws IOException + public Path getArtifactFile( CacheContext context, CacheSource source, Artifact artifact ) throws IOException { if ( source == CacheSource.LOCAL ) { @@ -396,7 +398,8 @@ public void beforeSave( CacheContext environment ) } @Override - public void saveBuildInfo( CacheResult cacheResult, BuildInfo buildInfo ) throws IOException + public void saveBuildInfo( CacheResult cacheResult, org.apache.maven.caching.xml.BuildInfo buildInfo ) + throws IOException { final Path path = localBuildPath( cacheResult.getContext(), BUILDINFO_XML, true ); Files.write( path, xmlService.toBytes( buildInfo.getDto() ), TRUNCATE_EXISTING, CREATE ); @@ -407,7 +410,7 @@ public void saveBuildInfo( CacheResult cacheResult, BuildInfo buildInfo ) throws } @Override - public void saveCacheReport( String buildId, MavenSession session, CacheReportType cacheReport ) throws IOException + public void saveCacheReport( String buildId, MavenSession session, CacheReport cacheReport ) throws IOException { Path path = getMultimoduleRoot( session ).resolve( "target" ).resolve( "maven-incremental" ); Files.createDirectories( path ); @@ -421,7 +424,8 @@ public void saveCacheReport( String buildId, MavenSession session, CacheReportTy } @Override - public void saveArtifactFile( CacheResult cacheResult, Artifact artifact ) throws IOException + public void saveArtifactFile( CacheResult cacheResult, org.apache.maven.artifact.Artifact artifact ) + throws IOException { // safe artifacts to cache File artifactFile = artifact.getFile(); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java index 84efff4c5945..d97e20469080 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java @@ -23,8 +23,8 @@ import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; -import org.apache.maven.caching.xml.config.TrackedPropertyType; -import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; +import org.apache.maven.caching.xml.config.TrackedProperty; +import org.apache.maven.caching.xml.buildinfo.CompletedExecution; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.MojoCheker; @@ -86,7 +86,7 @@ public boolean needCheck( MojoExecution mojoExecution, MavenSession session ) public boolean check( MojoExecution execution, Mojo mojo, MavenSession session ) { - final CompletedExecutionType completedExecution = buildInfo.findMojoExecutionInfo( execution ); + final CompletedExecution completedExecution = buildInfo.findMojoExecutionInfo( execution ); final String fullGoalName = execution.getMojoDescriptor().getFullGoalName(); if ( completedExecution != null && !isParamsMatched( project, execution, mojo, completedExecution ) ) @@ -114,12 +114,12 @@ public boolean check( MojoExecution execution, Mojo mojo, MavenSession session ) private boolean isParamsMatched( MavenProject project, MojoExecution mojoExecution, Mojo mojo, - CompletedExecutionType completedExecution ) + CompletedExecution completedExecution ) { - List tracked = cacheConfig.getTrackedProperties( mojoExecution ); + List tracked = cacheConfig.getTrackedProperties( mojoExecution ); - for ( TrackedPropertyType trackedProperty : tracked ) + for ( TrackedProperty trackedProperty : tracked ) { final String propertyName = trackedProperty.getPropertyName(); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfig.java index 08ea117a4cb7..da5767767f8d 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfig.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfig.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.xml.config.DirScanConfigType; +import org.apache.maven.caching.xml.config.DirScanConfig; import javax.annotation.Nonnull; @@ -37,5 +37,5 @@ public interface PluginScanConfig @Nonnull ScanConfigProperties getTagScanProperties( String tagName ); - DirScanConfigType dto(); + DirScanConfig dto(); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java index c7031fa3f866..34f71802e1f7 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java @@ -20,9 +20,9 @@ */ import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.xml.config.DirScanConfigType; -import org.apache.maven.caching.xml.config.TagNameType; -import org.apache.maven.caching.xml.config.TagScanConfigType; +import org.apache.maven.caching.xml.config.DirScanConfig; +import org.apache.maven.caching.xml.config.TagExclude; +import org.apache.maven.caching.xml.config.TagScanConfig; import javax.annotation.Nonnull; import java.util.List; @@ -33,9 +33,9 @@ public class PluginScanConfigImpl implements PluginScanConfig { - private final DirScanConfigType dto; + private final DirScanConfig dto; - public PluginScanConfigImpl( DirScanConfigType scanConfig ) + public PluginScanConfigImpl( DirScanConfig scanConfig ) { this.dto = scanConfig; } @@ -52,7 +52,7 @@ public boolean accept( String tagName ) // include or exclude is a choice element, could be only obe property set //noinspection ConstantConditions - final List includes = dto.getIncludes(); + final List includes = dto.getIncludes(); if ( !includes.isEmpty() ) { return findTagScanProperties( tagName ) != null; @@ -61,9 +61,9 @@ public boolean accept( String tagName ) return !contains( dto.getExcludes(), tagName ); } - private boolean contains( List excludes, String tagName ) + private boolean contains( List excludes, String tagName ) { - for ( TagNameType exclude : excludes ) + for ( TagExclude exclude : excludes ) { if ( StringUtils.equals( exclude.getTagName(), tagName ) ) { @@ -83,7 +83,7 @@ public PluginScanConfig mergeWith( final PluginScanConfig overrideConfig ) return overrideConfig; } - final DirScanConfigType override = overrideConfig.dto(); + final DirScanConfig override = overrideConfig.dto(); if ( override == null ) { return this; @@ -94,7 +94,7 @@ public PluginScanConfig mergeWith( final PluginScanConfig overrideConfig ) return overrideConfig; } - DirScanConfigType merged = new DirScanConfigType(); + DirScanConfig merged = new DirScanConfig(); if ( override.getMode() != null ) { merged.setMode( override.getMode() ); @@ -121,7 +121,7 @@ public ScanConfigProperties getTagScanProperties( String tagName ) } @Override - public DirScanConfigType dto() + public DirScanConfig dto() { return dto; } @@ -136,7 +136,7 @@ private ScanConfigProperties findTagScanProperties( String tagName ) return scanConfigProperties; } - private ScanConfigProperties findConfigByName( String tagName, List configs ) + private ScanConfigProperties findConfigByName( String tagName, List configs ) { if ( configs == null ) @@ -144,7 +144,7 @@ private ScanConfigProperties findConfigByName( String tagName, List projectArtifactsByKey; + private final ConcurrentMap projectArtifactsByKey; private final PathIgnoringCaseComparator fileComparator; private final DependencyComparator dependencyComparator; private final List filteredOutPaths; @@ -152,7 +152,7 @@ public MavenProjectInput( MavenProject project, MavenSession session, CacheConfig config, ProjectIndex projectIndex, - ConcurrentMap artifactsByKey, + ConcurrentMap artifactsByKey, RepositorySystem repoSystem, ArtifactHandlerManager artifactHandlerManager, Logger logger, @@ -197,30 +197,30 @@ public MavenProjectInput( MavenProject project, this.dependencyComparator = new DependencyComparator(); } - public ProjectsInputInfoType calculateChecksum( HashFactory hashFactory ) throws IOException + public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOException { long time = Clock.time(); final String effectivePom = getEffectivePom( project.getOriginalEffectiveModel() ); final SortedSet inputFiles = getInputFiles(); - final SortedMap dependenciesChecksum = getMutableDependencies(); + final SortedMap dependenciesChecksum = getMutableDependencies(); final long inputTime = Clock.elapsed( time ); time = Clock.time(); // hash items: effective pom + input files + dependencies final int count = 1 + inputFiles.size() + dependenciesChecksum.size(); - final List items = new ArrayList<>( count ); + final List items = new ArrayList<>( count ); final HashChecksum checksum = hashFactory.createChecksum( count ); - Optional baselineHolder = Optional.absent(); + Optional baselineHolder = Optional.absent(); if ( config.isBaselineDiffEnabled() ) { baselineHolder = remoteCache.findBaselineBuild( project ).transform( b -> b.getDto().getProjectsInputInfo() ); } - DigestItemType effectivePomChecksum = DigestUtils.pom( checksum, effectivePom ); + DigestItem effectivePomChecksum = DigestUtils.pom( checksum, effectivePom ); items.add( effectivePomChecksum ); final boolean compareWithBaseline = config.isBaselineDiffEnabled() && baselineHolder.isPresent(); if ( compareWithBaseline ) @@ -231,7 +231,7 @@ public ProjectsInputInfoType calculateChecksum( HashFactory hashFactory ) throws boolean sourcesMatched = true; for ( Path file : inputFiles ) { - DigestItemType fileDigest = DigestUtils.file( checksum, baseDirPath, file ); + DigestItem fileDigest = DigestUtils.file( checksum, baseDirPath, file ); items.add( fileDigest ); if ( compareWithBaseline ) { @@ -244,9 +244,9 @@ public ProjectsInputInfoType calculateChecksum( HashFactory hashFactory ) throws } boolean dependenciesMatched = true; - for ( Map.Entry entry : dependenciesChecksum.entrySet() ) + for ( Map.Entry entry : dependenciesChecksum.entrySet() ) { - DigestItemType dependencyDigest = + DigestItem dependencyDigest = DigestUtils.dependency( checksum, entry.getKey(), entry.getValue().getHash() ); items.add( dependencyDigest ); if ( compareWithBaseline ) @@ -260,7 +260,7 @@ public ProjectsInputInfoType calculateChecksum( HashFactory hashFactory ) throws logInfo( "Dependencies: " + ( dependenciesMatched ? "MATCHED" : "OUT OF DATE" ) ); } - final ProjectsInputInfoType projectsInputInfoType = new ProjectsInputInfoType(); + final ProjectsInputInfo projectsInputInfoType = new ProjectsInputInfo(); projectsInputInfoType.setChecksum( checksum.digest() ); projectsInputInfoType.getItems().addAll( items ); @@ -268,7 +268,7 @@ public ProjectsInputInfoType calculateChecksum( HashFactory hashFactory ) throws if ( logger.isDebugEnabled() ) { - for ( DigestItemType item : projectsInputInfoType.getItems() ) + for ( DigestItem item : projectsInputInfoType.getItems() ) { logger.debug( "Hash calculated, item: " + item.getType() + ", hash: " + item.getHash() ); } @@ -280,10 +280,10 @@ public ProjectsInputInfoType calculateChecksum( HashFactory hashFactory ) throws return projectsInputInfoType; } - private void checkEffectivePomMatch( ProjectsInputInfoType baselineBuild, DigestItemType effectivePomChecksum ) + private void checkEffectivePomMatch( ProjectsInputInfo baselineBuild, DigestItem effectivePomChecksum ) { - Optional pomHolder = Optional.absent(); - for ( DigestItemType it : baselineBuild.getItems() ) + Optional pomHolder = Optional.absent(); + for ( DigestItem it : baselineBuild.getItems() ) { if ( it.getType().equals( "pom" ) ) { @@ -294,7 +294,7 @@ private void checkEffectivePomMatch( ProjectsInputInfoType baselineBuild, Digest if ( pomHolder.isPresent() ) { - DigestItemType pomItem = pomHolder.get(); + DigestItem pomItem = pomHolder.get(); final boolean matches = StringUtils.equals( pomItem.getHash(), effectivePomChecksum.getHash() ); if ( !matches ) { @@ -306,10 +306,10 @@ private void checkEffectivePomMatch( ProjectsInputInfoType baselineBuild, Digest } } - private boolean checkItemMatchesBaseline( ProjectsInputInfoType baselineBuild, DigestItemType fileDigest ) + private boolean checkItemMatchesBaseline( ProjectsInputInfo baselineBuild, DigestItem fileDigest ) { - Optional baselineFileDigest = Optional.absent(); - for ( DigestItemType it : baselineBuild.getItems() ) + Optional baselineFileDigest = Optional.absent(); + for ( DigestItem it : baselineBuild.getItems() ) { if ( it.getType().equals( fileDigest.getType() ) && fileDigest.getValue().equals( it.getValue().trim() ) ) @@ -757,10 +757,10 @@ private boolean isFilteredOutSubpath( Path path ) return false; } - private SortedMap getMutableDependencies() throws IOException + private SortedMap getMutableDependencies() throws IOException { MultimoduleDiscoveryStrategy strategy = config.getMultimoduleDiscoveryStrategy(); - SortedMap result = new TreeMap<>(); + SortedMap result = new TreeMap<>(); for ( Dependency dependency : project.getDependencies() ) { @@ -784,7 +784,7 @@ private SortedMap getMutableDependencies() throws IOExce final Artifact dependencyArtifact = repoSystem.createDependencyArtifact( dependency ); final String artifactKey = KeyUtils.getArtifactKey( dependencyArtifact ); - DigestItemType resolved = null; + DigestItem resolved = null; if ( currentlyBuilding ) { resolved = projectArtifactsByKey.get( artifactKey ); @@ -823,7 +823,7 @@ private SortedMap getMutableDependencies() throws IOExce } @Nonnull - private DigestItemType resolveArtifact( final Artifact dependencyArtifact, + private DigestItem resolveArtifact( final Artifact dependencyArtifact, MultimoduleDiscoveryStrategy strategy ) throws IOException { diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/BuildInfo.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/BuildInfo.java index f0cf3c7c7b6d..606cb5276632 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/BuildInfo.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/BuildInfo.java @@ -20,15 +20,13 @@ */ import com.google.common.collect.Iterables; -import org.apache.maven.artifact.Artifact; import org.apache.maven.caching.ProjectUtils; import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.hash.HashAlgorithm; -import org.apache.maven.caching.xml.buildinfo.ArtifactType; -import org.apache.maven.caching.xml.buildinfo.BuildInfoType; -import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; -import org.apache.maven.caching.xml.buildinfo.DigestItemType; -import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfoType; +import org.apache.maven.caching.xml.buildinfo.Artifact; +import org.apache.maven.caching.xml.buildinfo.CompletedExecution; +import org.apache.maven.caching.xml.buildinfo.DigestItem; +import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfo; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecution; import org.codehaus.plexus.logging.Logger; @@ -52,17 +50,17 @@ public class BuildInfo { - final BuildInfoType dto; + final org.apache.maven.caching.xml.buildinfo.BuildInfo dto; CacheSource source; public BuildInfo( List goals, - ArtifactType artifact, - List attachedArtifacts, - ProjectsInputInfoType projectsInputInfo, - List completedExecutions, + Artifact artifact, + List attachedArtifacts, + ProjectsInputInfo projectsInputInfo, + List completedExecutions, String hashAlgorithm ) { - this.dto = new BuildInfoType(); + this.dto = new org.apache.maven.caching.xml.buildinfo.BuildInfo(); this.dto.setCacheImplementationVersion( MavenProjectInput.CACHE_IMPLMENTATION_VERSION ); this.dto.setBuildTime( new Date() ); try @@ -87,19 +85,19 @@ public CacheSource getSource() return source; } - public BuildInfo( BuildInfoType buildInfo, CacheSource source ) + public BuildInfo( org.apache.maven.caching.xml.buildinfo.BuildInfo buildInfo, CacheSource source ) { this.dto = buildInfo; this.source = source; } - public static List createAttachedArtifacts( List artifacts, - HashAlgorithm algorithm ) throws IOException + public static List createAttachedArtifacts( List artifacts, + HashAlgorithm algorithm ) throws IOException { - List attachedArtifacts = new ArrayList<>(); - for ( Artifact artifact : artifacts ) + List attachedArtifacts = new ArrayList<>(); + for ( org.apache.maven.artifact.Artifact artifact : artifacts ) { - final ArtifactType dto = DtoUtils.createDto( artifact ); + final Artifact dto = DtoUtils.createDto( artifact ); if ( artifact.getFile() != null ) { dto.setFileHash( algorithm.hash( artifact.getFile().toPath() ) ); @@ -125,10 +123,10 @@ public boolean isAllExecutionsPresent( List mojos, Logger logger private boolean hasCompletedExecution( String mojoExecutionKey ) { - final List completedExecutions = dto.getExecutions(); + final List completedExecutions = dto.getExecutions(); if ( dto.getExecutions() != null ) { - for ( CompletedExecutionType completedExecution : completedExecutions ) + for ( CompletedExecution completedExecution : completedExecutions ) { if ( StringUtils.equals( completedExecution.getExecutionKey(), mojoExecutionKey ) ) { @@ -145,7 +143,7 @@ public String toString() return "BuildInfo{" + "dto=" + dto + '}'; } - public CompletedExecutionType findMojoExecutionInfo( MojoExecution mojoExecution ) + public CompletedExecution findMojoExecutionInfo( MojoExecution mojoExecution ) { if ( dto.getExecutions() == null ) @@ -153,8 +151,8 @@ public CompletedExecutionType findMojoExecutionInfo( MojoExecution mojoExecution return null; } - final List executions = dto.getExecutions(); - for ( CompletedExecutionType execution : executions ) + final List executions = dto.getExecutions(); + for ( CompletedExecution execution : executions ) { if ( StringUtils.equals( execution.getExecutionKey(), mojoExecutionKey( mojoExecution ) ) ) { @@ -169,12 +167,12 @@ public String getCacheImplementationVersion() return dto.getCacheImplementationVersion(); } - public ArtifactType getArtifact() + public Artifact getArtifact() { return dto.getArtifact(); } - public List getAttachedArtifacts() + public List getAttachedArtifacts() { if ( dto.getAttachedArtifacts() != null ) { @@ -183,7 +181,7 @@ public List getAttachedArtifacts() return Collections.emptyList(); } - public BuildInfoType getDto() + public org.apache.maven.caching.xml.buildinfo.BuildInfo getDto() { return dto; } @@ -225,16 +223,16 @@ public List getPostCachedSegment( List mojoExecuti return list; } - public DigestItemType findArtifact( Dependency dependency ) + public DigestItem findArtifact( Dependency dependency ) { if ( ProjectUtils.isPom( dependency ) ) { throw new IllegalArgumentException( "Pom dependencies should not be treated as artifacts: " + dependency ); } - List artifacts = new ArrayList<>( getAttachedArtifacts() ); + List artifacts = new ArrayList<>( getAttachedArtifacts() ); artifacts.add( getArtifact() ); - for ( ArtifactType artifact : artifacts ) + for ( Artifact artifact : artifacts ) { if ( isEquals( dependency, artifact ) ) { @@ -244,7 +242,7 @@ public DigestItemType findArtifact( Dependency dependency ) return null; } - private boolean isEquals( Dependency dependency, ArtifactType artifact ) + private boolean isEquals( Dependency dependency, Artifact artifact ) { return Objects.equals( dependency.getGroupId(), artifact.getArtifactId() ) && Objects.equals( dependency.getArtifactId(), artifact.getArtifactId() ) && Objects.equals( dependency.getType(), diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java index 7d90cc1fea73..16a300bfbb9f 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java @@ -24,8 +24,8 @@ import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.xml.config.Exclude; import org.apache.maven.caching.xml.config.Include; -import org.apache.maven.caching.xml.config.PropertyNameType; -import org.apache.maven.caching.xml.config.TrackedPropertyType; +import org.apache.maven.caching.xml.config.PropertyName; +import org.apache.maven.caching.xml.config.TrackedProperty; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; @@ -45,15 +45,15 @@ public interface CacheConfig CacheState initialize( MavenProject project, MavenSession session ); @Nonnull - List getTrackedProperties( MojoExecution mojoExecution ); + List getTrackedProperties( MojoExecution mojoExecution ); boolean isLogAllProperties( MojoExecution mojoExecution ); @Nonnull - List getLoggedProperties( MojoExecution mojoExecution ); + List getLoggedProperties( MojoExecution mojoExecution ); @Nonnull - List getNologProperties( MojoExecution mojoExecution ); + List getNologProperties( MojoExecution mojoExecution ); @Nonnull List getEffectivePomExcludeProperties( Plugin plugin ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 536bdffca350..0ab71bddcd51 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -41,24 +41,24 @@ import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.xml.config.AttachedOutputs; -import org.apache.maven.caching.xml.config.CacheType; -import org.apache.maven.caching.xml.config.ConfigurationType; -import org.apache.maven.caching.xml.config.CoordinatesBaseType; +import org.apache.maven.caching.xml.config.CacheConfig; +import org.apache.maven.caching.xml.config.Configuration; +import org.apache.maven.caching.xml.config.CoordinatesBase; import org.apache.maven.caching.xml.config.Exclude; -import org.apache.maven.caching.xml.config.ExecutablesType; -import org.apache.maven.caching.xml.config.ExecutionConfigurationScanType; -import org.apache.maven.caching.xml.config.ExecutionControlType; -import org.apache.maven.caching.xml.config.ExecutionIdsListType; -import org.apache.maven.caching.xml.config.GoalReconciliationType; -import org.apache.maven.caching.xml.config.GoalsListType; +import org.apache.maven.caching.xml.config.Executables; +import org.apache.maven.caching.xml.config.ExecutionConfigurationScan; +import org.apache.maven.caching.xml.config.ExecutionControl; +import org.apache.maven.caching.xml.config.ExecutionIdsList; +import org.apache.maven.caching.xml.config.GoalReconciliation; +import org.apache.maven.caching.xml.config.GoalsList; import org.apache.maven.caching.xml.config.Include; import org.apache.maven.caching.xml.config.Local; -import org.apache.maven.caching.xml.config.PluginConfigurationScanType; -import org.apache.maven.caching.xml.config.PluginSetType; +import org.apache.maven.caching.xml.config.PluginConfigurationScan; +import org.apache.maven.caching.xml.config.PluginSet; import org.apache.maven.caching.xml.config.ProjectDiscoveryStrategy; -import org.apache.maven.caching.xml.config.PropertyNameType; +import org.apache.maven.caching.xml.config.PropertyName; import org.apache.maven.caching.xml.config.Remote; -import org.apache.maven.caching.xml.config.TrackedPropertyType; +import org.apache.maven.caching.xml.config.TrackedProperty; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; @@ -76,7 +76,7 @@ */ @Singleton @Named -public class CacheConfigImpl implements CacheConfig +public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig { public static final String CONFIG_PATH_PROPERTY_NAME = "remote.cache.configPath"; @@ -93,7 +93,7 @@ public class CacheConfigImpl implements CacheConfig private XmlService xmlService; private volatile CacheState state = CacheState.NOT_INITIALIZED; - private volatile CacheType cacheConfig; + private volatile CacheConfig cacheConfig; private volatile HashFactory hashFactory; private MavenSession session; private MavenProject project; @@ -151,7 +151,7 @@ public synchronized CacheState initialize( MavenProject project, MavenSession se try { logger.info( "Loading cache configuration from " + configPath ); - cacheConfig = xmlService.fromFile( CacheType.class, configPath.toFile() ); + cacheConfig = xmlService.fromFile( CacheConfig.class, configPath.toFile() ); } catch ( Exception e ) { @@ -183,10 +183,10 @@ public synchronized CacheState initialize( MavenProject project, MavenSession se @Nonnull @Override - public List getTrackedProperties( MojoExecution mojoExecution ) + public List getTrackedProperties( MojoExecution mojoExecution ) { checkInitializedState(); - final GoalReconciliationType reconciliationConfig = findReconciliationConfig( mojoExecution ); + final GoalReconciliation reconciliationConfig = findReconciliationConfig( mojoExecution ); if ( reconciliationConfig != null ) { return reconciliationConfig.getReconciles(); @@ -200,7 +200,7 @@ public List getTrackedProperties( MojoExecution mojoExecuti @Override public boolean isLogAllProperties( MojoExecution mojoExecution ) { - final GoalReconciliationType reconciliationConfig = findReconciliationConfig( mojoExecution ); + final GoalReconciliation reconciliationConfig = findReconciliationConfig( mojoExecution ); if ( reconciliationConfig != null && reconciliationConfig.isLogAll() ) { return true; @@ -209,7 +209,7 @@ public boolean isLogAllProperties( MojoExecution mojoExecution ) && cacheConfig.getExecutionControl().getReconcile().isLogAllProperties(); } - private GoalReconciliationType findReconciliationConfig( MojoExecution mojoExecution ) + private GoalReconciliation findReconciliationConfig( MojoExecution mojoExecution ) { if ( cacheConfig.getExecutionControl() == null ) @@ -217,15 +217,15 @@ private GoalReconciliationType findReconciliationConfig( MojoExecution mojoExecu return null; } - final ExecutionControlType executionControl = cacheConfig.getExecutionControl(); + final ExecutionControl executionControl = cacheConfig.getExecutionControl(); if ( executionControl.getReconcile() == null ) { return null; } - final List reconciliation = executionControl.getReconcile().getPlugins(); + final List reconciliation = executionControl.getReconcile().getPlugins(); - for ( GoalReconciliationType goalReconciliationConfig : reconciliation ) + for ( GoalReconciliation goalReconciliationConfig : reconciliation ) { final String goal = mojoExecution.getGoal(); @@ -241,11 +241,11 @@ private GoalReconciliationType findReconciliationConfig( MojoExecution mojoExecu @Nonnull @Override - public List getLoggedProperties( MojoExecution mojoExecution ) + public List getLoggedProperties( MojoExecution mojoExecution ) { checkInitializedState(); - final GoalReconciliationType reconciliationConfig = findReconciliationConfig( mojoExecution ); + final GoalReconciliation reconciliationConfig = findReconciliationConfig( mojoExecution ); if ( reconciliationConfig != null ) { return reconciliationConfig.getLogs(); @@ -258,10 +258,10 @@ public List getLoggedProperties( MojoExecution mojoExecution ) @Nonnull @Override - public List getNologProperties( MojoExecution mojoExecution ) + public List getNologProperties( MojoExecution mojoExecution ) { checkInitializedState(); - final GoalReconciliationType reconciliationConfig = findReconciliationConfig( mojoExecution ); + final GoalReconciliation reconciliationConfig = findReconciliationConfig( mojoExecution ); if ( reconciliationConfig != null ) { return reconciliationConfig.getNologs(); @@ -277,7 +277,7 @@ public List getNologProperties( MojoExecution mojoExecution ) public List getEffectivePomExcludeProperties( Plugin plugin ) { checkInitializedState(); - final PluginConfigurationScanType pluginConfig = findPluginScanConfig( plugin ); + final PluginConfigurationScan pluginConfig = findPluginScanConfig( plugin ); if ( pluginConfig != null && pluginConfig.getEffectivePom() != null ) { @@ -286,7 +286,7 @@ public List getEffectivePomExcludeProperties( Plugin plugin ) return Collections.emptyList(); } - private PluginConfigurationScanType findPluginScanConfig( Plugin plugin ) + private PluginConfigurationScan findPluginScanConfig( Plugin plugin ) { if ( cacheConfig.getInput() == null ) @@ -294,8 +294,8 @@ private PluginConfigurationScanType findPluginScanConfig( Plugin plugin ) return null; } - final List pluginConfigs = cacheConfig.getInput().getPlugins(); - for ( PluginConfigurationScanType pluginConfig : pluginConfigs ) + final List pluginConfigs = cacheConfig.getInput().getPlugins(); + for ( PluginConfigurationScan pluginConfig : pluginConfigs ) { if ( isPluginMatch( plugin, pluginConfig ) ) { @@ -305,7 +305,7 @@ private PluginConfigurationScanType findPluginScanConfig( Plugin plugin ) return null; } - private boolean isPluginMatch( Plugin plugin, CoordinatesBaseType pluginConfig ) + private boolean isPluginMatch( Plugin plugin, CoordinatesBase pluginConfig ) { return StringUtils.equals( pluginConfig.getArtifactId(), plugin.getArtifactId() ) && ( pluginConfig.getGroupId() == null || StringUtils.equals( @@ -318,7 +318,7 @@ private boolean isPluginMatch( Plugin plugin, CoordinatesBaseType pluginConfig ) public PluginScanConfig getPluginDirScanConfig( Plugin plugin ) { checkInitializedState(); - final PluginConfigurationScanType pluginConfig = findPluginScanConfig( plugin ); + final PluginConfigurationScan pluginConfig = findPluginScanConfig( plugin ); if ( pluginConfig == null || pluginConfig.getDirScan() == null ) { return new DefaultPluginScanConfig(); @@ -332,11 +332,11 @@ public PluginScanConfig getPluginDirScanConfig( Plugin plugin ) public PluginScanConfig getExecutionDirScanConfig( Plugin plugin, PluginExecution exec ) { checkInitializedState(); - final PluginConfigurationScanType pluginScanConfig = findPluginScanConfig( plugin ); + final PluginConfigurationScan pluginScanConfig = findPluginScanConfig( plugin ); if ( pluginScanConfig != null ) { - final ExecutionConfigurationScanType executionScanConfig = findExecutionScanConfig( exec, + final ExecutionConfigurationScan executionScanConfig = findExecutionScanConfig( exec, pluginScanConfig.getExecutions() ); if ( executionScanConfig != null && executionScanConfig.getDirScan() != null ) { @@ -347,10 +347,10 @@ public PluginScanConfig getExecutionDirScanConfig( Plugin plugin, PluginExecutio return new DefaultPluginScanConfig(); } - private ExecutionConfigurationScanType findExecutionScanConfig( PluginExecution execution, - List scanConfigs ) + private ExecutionConfigurationScan findExecutionScanConfig( PluginExecution execution, + List scanConfigs ) { - for ( ExecutionConfigurationScanType executionScanConfig : scanConfigs ) + for ( ExecutionConfigurationScan executionScanConfig : scanConfigs ) { if ( executionScanConfig.getExecIds().contains( execution.getId() ) ) { @@ -436,10 +436,10 @@ public boolean isForcedExecution( MojoExecution execution ) return executionMatches( execution, cacheConfig.getExecutionControl().getRunAlways() ); } - private boolean executionMatches( MojoExecution execution, ExecutablesType executablesType ) + private boolean executionMatches( MojoExecution execution, Executables executablesType ) { - final List pluginConfigs = executablesType.getPlugins(); - for ( PluginSetType pluginConfig : pluginConfigs ) + final List pluginConfigs = executablesType.getPlugins(); + for ( PluginSet pluginConfig : pluginConfigs ) { if ( isPluginMatch( execution.getPlugin(), pluginConfig ) ) { @@ -447,8 +447,8 @@ private boolean executionMatches( MojoExecution execution, ExecutablesType execu } } - final List executionIds = executablesType.getExecutions(); - for ( ExecutionIdsListType executionConfig : executionIds ) + final List executionIds = executablesType.getExecutions(); + for ( ExecutionIdsList executionConfig : executionIds ) { if ( isPluginMatch( execution.getPlugin(), executionConfig ) && executionConfig.getExecIds().contains( execution.getExecutionId() ) ) @@ -457,8 +457,8 @@ private boolean executionMatches( MojoExecution execution, ExecutablesType execu } } - final List pluginsGoalsList = executablesType.getGoalsLists(); - for ( GoalsListType pluginGoals : pluginsGoalsList ) + final List pluginsGoalsList = executablesType.getGoalsLists(); + for ( GoalsList pluginGoals : pluginsGoalsList ) { if ( isPluginMatch( execution.getPlugin(), pluginGoals ) && pluginGoals.getGoals().contains( execution.getGoal() ) ) @@ -570,7 +570,7 @@ private Local getLocal() return getConfiguration().getLocal(); } - private ConfigurationType getConfiguration() + private Configuration getConfiguration() { return cacheConfig.getConfiguration(); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java index 3754f34f4638..74a7540055d1 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java @@ -21,13 +21,12 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.artifact.Artifact; import org.apache.maven.caching.ProjectUtils; -import org.apache.maven.caching.xml.buildinfo.ArtifactType; -import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; -import org.apache.maven.caching.xml.buildinfo.DigestItemType; -import org.apache.maven.caching.xml.buildinfo.PropertyValueType; -import org.apache.maven.caching.xml.config.TrackedPropertyType; +import org.apache.maven.caching.xml.buildinfo.Artifact; +import org.apache.maven.caching.xml.buildinfo.CompletedExecution; +import org.apache.maven.caching.xml.buildinfo.DigestItem; +import org.apache.maven.caching.xml.buildinfo.PropertyValue; +import org.apache.maven.caching.xml.config.TrackedProperty; import org.apache.maven.model.Dependency; import javax.annotation.Nonnull; @@ -42,14 +41,14 @@ public class DtoUtils { - public static String findPropertyValue( String propertyName, CompletedExecutionType completedExecution ) + public static String findPropertyValue( String propertyName, CompletedExecution completedExecution ) { - final List properties = completedExecution.getProperties(); + final List properties = completedExecution.getProperties(); if ( properties == null ) { return null; } - for ( PropertyValueType property : properties ) + for ( PropertyValue property : properties ) { if ( StringUtils.equals( propertyName, property.getName() ) ) { @@ -59,9 +58,9 @@ public static String findPropertyValue( String propertyName, CompletedExecutionT return null; } - public static ArtifactType createDto( Artifact artifact ) + public static Artifact createDto( org.apache.maven.artifact.Artifact artifact ) { - ArtifactType dto = new ArtifactType(); + Artifact dto = new Artifact(); dto.setArtifactId( artifact.getArtifactId() ); dto.setGroupId( artifact.getGroupId() ); dto.setVersion( artifact.getVersion() ); @@ -72,9 +71,9 @@ public static ArtifactType createDto( Artifact artifact ) return dto; } - public static DigestItemType createdDigestedByProjectChecksum( ArtifactType artifact, String projectChecksum ) + public static DigestItem createdDigestedByProjectChecksum( Artifact artifact, String projectChecksum ) { - DigestItemType dit = new DigestItemType(); + DigestItem dit = new DigestItem(); dit.setType( "module" ); dit.setHash( projectChecksum ); dit.setFileChecksum( artifact.getFileHash() ); @@ -82,9 +81,9 @@ public static DigestItemType createdDigestedByProjectChecksum( ArtifactType arti return dit; } - public static DigestItemType createDigestedFile( Artifact artifact, String fileHash ) + public static DigestItem createDigestedFile( org.apache.maven.artifact.Artifact artifact, String fileHash ) { - DigestItemType dit = new DigestItemType(); + DigestItem dit = new DigestItem(); dit.setType( "artifact" ); dit.setHash( fileHash ); dit.setFileChecksum( fileHash ); @@ -92,7 +91,7 @@ public static DigestItemType createDigestedFile( Artifact artifact, String fileH return dit; } - public static Dependency createDependency( ArtifactType artifact ) + public static Dependency createDependency( org.apache.maven.artifact.Artifact artifact ) { final Dependency dependency = new Dependency(); dependency.setArtifactId( artifact.getArtifactId() ); @@ -116,13 +115,13 @@ public static Dependency createDependency( Artifact artifact ) return dependency; } - public static void addProperty( CompletedExecutionType execution, + public static void addProperty( CompletedExecution execution, String propertyName, Object value, String baseDirPath, boolean tracked ) { - final PropertyValueType valueType = new PropertyValueType(); + final PropertyValue valueType = new PropertyValue(); valueType.setName( propertyName ); if ( value != null && value.getClass().isArray() ) { @@ -135,7 +134,7 @@ public static void addProperty( CompletedExecutionType execution, } public static boolean containsAllProperties( - @Nonnull CompletedExecutionType cachedExecution, List trackedProperties ) + @Nonnull CompletedExecution cachedExecution, List trackedProperties ) { if ( trackedProperties == null || trackedProperties.isEmpty() ) @@ -148,8 +147,8 @@ public static boolean containsAllProperties( return false; } - final List executionProperties = cachedExecution.getProperties(); - for ( TrackedPropertyType trackedProperty : trackedProperties ) + final List executionProperties = cachedExecution.getProperties(); + for ( TrackedProperty trackedProperty : trackedProperties ) { if ( !contains( executionProperties, trackedProperty.getPropertyName() ) ) { @@ -159,9 +158,9 @@ public static boolean containsAllProperties( return true; } - public static boolean contains( List executionProperties, String propertyName ) + public static boolean contains( List executionProperties, String propertyName ) { - for ( PropertyValueType executionProperty : executionProperties ) + for ( PropertyValue executionProperty : executionProperties ) { if ( StringUtils.equals( executionProperty.getName(), propertyName ) ) { @@ -171,9 +170,9 @@ public static boolean contains( List executionProperties, Str return false; } - public static ArtifactType copy( ArtifactType artifact ) + public static Artifact copy( Artifact artifact ) { - ArtifactType copy = new ArtifactType(); + Artifact copy = new Artifact(); copy.setArtifactId( artifact.getArtifactId() ); copy.setGroupId( artifact.getGroupId() ); copy.setVersion( artifact.getVersion() ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java index 0cfe506ee262..c10b1ee0b330 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java @@ -29,16 +29,16 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.apache.maven.caching.xml.buildinfo.BuildInfoType; +import org.apache.maven.caching.xml.buildinfo.BuildInfo; import org.apache.maven.caching.xml.buildinfo.io.xpp3.CacheBuildInfoXpp3Reader; import org.apache.maven.caching.xml.buildinfo.io.xpp3.CacheBuildInfoXpp3Writer; -import org.apache.maven.caching.xml.buildsdiff.BuildDiffType; +import org.apache.maven.caching.xml.buildsdiff.BuildDiff; import org.apache.maven.caching.xml.buildsdiff.io.xpp3.CacheBuildsDiffXpp3Reader; import org.apache.maven.caching.xml.buildsdiff.io.xpp3.CacheBuildsDiffXpp3Writer; -import org.apache.maven.caching.xml.config.CacheType; +import org.apache.maven.caching.xml.config.CacheConfig; import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Reader; import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Writer; -import org.apache.maven.caching.xml.report.CacheReportType; +import org.apache.maven.caching.xml.report.CacheReport; import org.apache.maven.caching.xml.report.io.xpp3.CacheReportXpp3Reader; import org.apache.maven.caching.xml.report.io.xpp3.CacheReportXpp3Writer; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -51,7 +51,7 @@ public class XmlService { - public byte[] toBytes( CacheType cache ) throws IOException + public byte[] toBytes( CacheConfig cache ) throws IOException { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { @@ -60,7 +60,7 @@ public byte[] toBytes( CacheType cache ) throws IOException } } - public byte[] toBytes( BuildInfoType buildInfo ) throws IOException + public byte[] toBytes( BuildInfo buildInfo ) throws IOException { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { @@ -69,7 +69,7 @@ public byte[] toBytes( BuildInfoType buildInfo ) throws IOException } } - public byte[] toBytes( BuildDiffType diff ) throws IOException + public byte[] toBytes( BuildDiff diff ) throws IOException { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { @@ -78,7 +78,7 @@ public byte[] toBytes( BuildDiffType diff ) throws IOException } } - public byte[] toBytes( CacheReportType cacheReportType ) throws IOException + public byte[] toBytes( CacheReport cacheReportType ) throws IOException { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { @@ -101,19 +101,19 @@ public T fromInputStream( Class clazz, InputStream inputStream ) { try { - if ( clazz == BuildInfoType.class ) + if ( clazz == BuildInfo.class ) { return clazz.cast( new CacheBuildInfoXpp3Reader().read( inputStream ) ); } - else if ( clazz == CacheType.class ) + else if ( clazz == CacheConfig.class ) { return clazz.cast( new CacheConfigXpp3Reader().read( inputStream ) ); } - else if ( clazz == BuildDiffType.class ) + else if ( clazz == BuildDiff.class ) { return clazz.cast( new CacheBuildsDiffXpp3Reader().read( inputStream ) ); } - else if ( clazz == CacheReportType.class ) + else if ( clazz == CacheReport.class ) { return clazz.cast( new CacheReportXpp3Reader().read( inputStream ) ); } diff --git a/maven-caching/src/main/mdo/cache-buildinfo.mdo b/maven-caching/src/main/mdo/cache-buildinfo.mdo index 9dacce39b94c..4d83fcd8d102 100644 --- a/maven-caching/src/main/mdo/cache-buildinfo.mdo +++ b/maven-caching/src/main/mdo/cache-buildinfo.mdo @@ -34,7 +34,7 @@ under the License. - BuildInfoType + BuildInfo 1.0.0+ @@ -106,7 +106,7 @@ under the License. artifact 1.0.0+ - ArtifactType + Artifact @@ -120,7 +120,7 @@ under the License. attachedArtifacts - ArtifactType + Artifact * @@ -150,7 +150,7 @@ under the License. executions - CompletedExecutionType + CompletedExecution * @@ -158,7 +158,7 @@ under the License. projectsInputInfo - ProjectsInputInfoType + ProjectsInputInfo @@ -188,7 +188,7 @@ under the License. - ArtifactType + Artifact @@ -259,7 +259,7 @@ under the License. - CompletedExecutionType + CompletedExecution executionKey @@ -272,7 +272,7 @@ under the License. properties - PropertyValueType + PropertyValue * @@ -289,7 +289,7 @@ under the License. - PropertyValueType + PropertyValue value @@ -314,7 +314,7 @@ under the License. - ProjectsInputInfoType + ProjectsInputInfo checksum @@ -323,7 +323,7 @@ under the License. items - DigestItemType + DigestItem * @@ -345,7 +345,7 @@ under the License. - DigestItemType + DigestItem value diff --git a/maven-caching/src/main/mdo/cache-buildsdiff.mdo b/maven-caching/src/main/mdo/cache-buildsdiff.mdo index c9af0a9d8351..a7b55f0c5fdc 100644 --- a/maven-caching/src/main/mdo/cache-buildsdiff.mdo +++ b/maven-caching/src/main/mdo/cache-buildsdiff.mdo @@ -40,12 +40,12 @@ under the License. - BuildDiffType + BuildDiff mismatches - MismatchType + Mismatch * @@ -65,12 +65,12 @@ under the License. - MismatchType + Mismatch detail - MismatchDetailType + MismatchDetail * @@ -103,7 +103,7 @@ under the License. - MismatchDetailType + MismatchDetail diff --git a/maven-caching/src/main/mdo/cache-config.mdo b/maven-caching/src/main/mdo/cache-config.mdo index 1e94cef5921f..6f3c3398f8b4 100644 --- a/maven-caching/src/main/mdo/cache-config.mdo +++ b/maven-caching/src/main/mdo/cache-config.mdo @@ -36,33 +36,33 @@ under the License. - CacheType + CacheConfig configuration - ConfigurationType + Configuration Configuration of main cache properties input - InputType + Input Configuration for source code input files participating in checksum calculation output - OutputType + Output Configuration for output artifacts, it's needed if you want to explicitly include/exclude something from caching executionControl - ExecutionControlType + ExecutionControl Execution rules for plugins in cached mode. Defines which plugins should run always @@ -220,7 +220,7 @@ under the License. --> - ConfigurationType + Configuration enabled @@ -378,19 +378,19 @@ under the License. --> - InputType + Input global - PathSetType + PathSet Global input calculation rules applicable to all projects and plugins in the build plugins - PluginConfigurationScanType + PluginConfigurationScan * Plugin specific input calculation rules @@ -445,8 +445,8 @@ under the License. --> - PluginConfigurationScanType - CoordinatesBaseType + PluginConfigurationScan + CoordinatesBase effectivePom @@ -458,14 +458,14 @@ under the License. dirScan - DirScanConfigType + DirScanConfig Specifies plugin level rules of configuration processing in search of referenced source files executions - ExecutionConfigurationScanType + ExecutionConfigurationScan * Specifies execution specific configuration processing in search of referenced source files @@ -523,7 +523,7 @@ under the License. --> - ExecutionConfigurationScanType + ExecutionConfigurationScan execIds @@ -535,7 +535,7 @@ under the License. dirScan - DirScanConfigType + DirScanConfig Specifies rules of configuration processing in search of referenced source files @@ -557,8 +557,8 @@ under the License. --> - TagScanConfigType - TagNameType + TagScanConfig + TagExclude recursive @@ -634,12 +634,12 @@ under the License. --> - DirScanConfigType + DirScanConfig includes - TagScanConfigType + TagScanConfig * Forces cache to treat property value as input and include in calculation. If set, only included @@ -648,7 +648,7 @@ under the License. excludes - TagNameType + TagExclude * Tag to exclude when scanning plugin configuration for input files (blacklist) @@ -656,7 +656,7 @@ under the License. tagScanConfigs - TagScanConfigType + TagScanConfig * Additional processing rules for non-blacklisted tags @@ -696,12 +696,12 @@ under the License. --> - OutputType + Output exclude - OutputTypeExclude + OutputExclude Patterns to exclude output artifacts applicable to all projects in the build @@ -709,7 +709,7 @@ under the License. - OutputTypeExclude + OutputExclude patterns @@ -739,7 +739,7 @@ under the License. --> - PathSetType + PathSet glob @@ -849,20 +849,20 @@ under the License. --> - GoalReconciliationType - GoalIdType + GoalReconciliation + GoalId reconciles - TrackedPropertyType + TrackedProperty * logs - PropertyNameType + PropertyName * Specify property which should be logged to build metadata for exploration @@ -870,7 +870,7 @@ under the License. nologs - PropertyNameType + PropertyName * Specify property which should not be logged @@ -946,19 +946,19 @@ under the License. --> - ExecutionControlType + ExecutionControl runAlways - ExecutablesType + Executables Specify which plugin should run always if present in build regardless of cached status ignoreMissing - ExecutablesType + Executables Specify which executions/plugins/goals do not affect generated artifacts and do not affect build correctness. @@ -1011,7 +1011,7 @@ under the License. plugins - GoalReconciliationType + GoalReconciliation * Reconciliation rules for plugin properties which might be affected by command line flags, etc @@ -1062,12 +1062,12 @@ under the License. --> - ExecutablesType + Executables plugins - PluginSetType + PluginSet * Specify which executions should run always if present in build regardless of cached status @@ -1075,7 +1075,7 @@ under the License. executions - ExecutionIdsListType + ExecutionIdsList * Specify which executions should run always if present in build regardless of cached status @@ -1083,7 +1083,7 @@ under the License. goalsLists - GoalsListType + GoalsList * Specify which goals should run always if present in build regardless of cached status @@ -1110,8 +1110,8 @@ under the License. --> - GoalsListType - CoordinatesBaseType + GoalsList + CoordinatesBase goals @@ -1135,8 +1135,8 @@ under the License. --> - GoalIdType - CoordinatesBaseType + GoalId + CoordinatesBase goal @@ -1165,8 +1165,8 @@ under the License. --> - ExecutionIdsListType - CoordinatesBaseType + ExecutionIdsList + CoordinatesBase execIds @@ -1188,8 +1188,8 @@ under the License. --> - PluginSetType - CoordinatesBaseType + PluginSet + CoordinatesBase - CoordinatesBaseType + CoordinatesBase groupId @@ -1224,7 +1224,7 @@ under the License. --> - TagNameType + TagExclude tagName @@ -1245,7 +1245,7 @@ under the License. --> - PropertyNameType + PropertyName value @@ -1290,7 +1290,7 @@ under the License. --> - TrackedPropertyType + TrackedProperty value diff --git a/maven-caching/src/main/mdo/cache-report.mdo b/maven-caching/src/main/mdo/cache-report.mdo index 5d6375cd7dff..d77ba5655cdd 100644 --- a/maven-caching/src/main/mdo/cache-report.mdo +++ b/maven-caching/src/main/mdo/cache-report.mdo @@ -34,12 +34,12 @@ under the License. - CacheReportType + CacheReport projects - ProjectReportType + ProjectReport * @@ -64,7 +64,7 @@ under the License. - ProjectReportType + ProjectReport groupId diff --git a/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java b/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java index 9c96fc21041b..5ae2a870ff09 100644 --- a/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java @@ -31,17 +31,15 @@ import java.util.List; import com.google.common.collect.Lists; -import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.xml.buildinfo.ArtifactType; -import org.apache.maven.caching.xml.buildinfo.BuildInfoType; -import org.apache.maven.caching.xml.buildinfo.CompletedExecutionType; -import org.apache.maven.caching.xml.buildinfo.DigestItemType; -import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfoType; -import org.apache.maven.caching.xml.buildinfo.PropertyValueType; -import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.buildinfo.Artifact; +import org.apache.maven.caching.xml.buildinfo.BuildInfo; +import org.apache.maven.caching.xml.buildinfo.CompletedExecution; +import org.apache.maven.caching.xml.buildinfo.DigestItem; +import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfo; +import org.apache.maven.caching.xml.buildinfo.PropertyValue; import org.apache.maven.caching.xml.XmlService; import org.junit.Test; @@ -52,12 +50,12 @@ public void name() throws Exception { XmlService xmlService = new XmlService(); - ProjectsInputInfoType main = new ProjectsInputInfoType(); + ProjectsInputInfo main = new ProjectsInputInfo(); main.setChecksum("dependencyChecksum"); main.addItem(createItem("pom", "4.0.0", "hash1")); main.addItem(createItem("file", Paths.get(".").toString(), "hash2")); - ArtifactType artifact = new ArtifactType(); + Artifact artifact = new Artifact(); artifact.setGroupId("g"); artifact.setArtifactId("a"); artifact.setType("t"); @@ -67,15 +65,15 @@ public void name() throws Exception { artifact.setFileSize(123456); artifact.setFileHash("456L"); - BuildInfoType buildInfo = new BuildInfoType(); + BuildInfo buildInfo = new BuildInfo(); buildInfo.setCacheImplementationVersion("cacheImplementationVersion"); buildInfo.setBuildServer("server"); buildInfo.setBuildTime(new Date()); buildInfo.setArtifact(artifact); buildInfo.setHashFunction("SHA-256"); buildInfo.setGoals(Lists.newArrayList("install")); - final Artifact attachedArtifact = new DefaultArtifact("ag", "aa", "av", "as", "at", "ac", new DefaultArtifactHandler()); - buildInfo.setAttachedArtifacts(BuildInfo.createAttachedArtifacts(Lists.newArrayList(attachedArtifact), HashFactory.XX.createAlgorithm())); + final org.apache.maven.artifact.Artifact attachedArtifact = new DefaultArtifact("ag", "aa", "av", "as", "at", "ac", new DefaultArtifactHandler()); + buildInfo.setAttachedArtifacts(org.apache.maven.caching.xml.BuildInfo.createAttachedArtifacts(Lists.newArrayList(attachedArtifact), HashFactory.XX.createAlgorithm())); buildInfo.setProjectsInputInfo(main); buildInfo.setExecutions(createExecutions()); @@ -86,22 +84,22 @@ public void name() throws Exception { file.deleteOnExit(); Files.write(tempFilePath, bytes); - BuildInfoType buildInfo1 = xmlService.fromFile(BuildInfoType.class, file); + BuildInfo buildInfo1 = xmlService.fromFile(BuildInfo.class, file); System.out.println(buildInfo1); } - private List createExecutions() { - CompletedExecutionType execution = new CompletedExecutionType(); + private List createExecutions() { + CompletedExecution execution = new CompletedExecution(); execution.setExecutionKey("execkey"); - PropertyValueType property = new PropertyValueType(); + PropertyValue property = new PropertyValue(); property.setValue("value"); property.setName("key"); execution.addProperty(property); return new ArrayList<>(Arrays.asList(execution)); } - private DigestItemType createItem(String pom, String s, String hash1) { - final DigestItemType d1 = new DigestItemType(); + private DigestItem createItem(String pom, String s, String hash1) { + final DigestItem d1 = new DigestItem(); d1.setType(pom); d1.setHash(s); d1.setValue(hash1); diff --git a/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java b/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java index 5a5e340fbc50..f0ce1d5faa17 100644 --- a/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java @@ -19,11 +19,10 @@ * under the License. */ -import org.apache.maven.caching.xml.buildinfo.BuildInfoType; -import org.apache.maven.caching.xml.buildinfo.io.xpp3.CacheBuildInfoXpp3Reader; -import org.apache.maven.caching.xml.buildsdiff.BuildDiffType; -import org.apache.maven.caching.xml.config.CacheType; -import org.apache.maven.caching.xml.report.CacheReportType; +import org.apache.maven.caching.xml.buildinfo.BuildInfo; +import org.apache.maven.caching.xml.buildsdiff.BuildDiff; +import org.apache.maven.caching.xml.config.CacheConfig; +import org.apache.maven.caching.xml.report.CacheReportDto; import org.junit.Test; import java.io.InputStream; @@ -49,7 +48,7 @@ public void testConfig() throws Exception { Document doc = db.parse( getClass().getResource( "cache-config-instance.xml" ).toString() ); InputStream is = getClass().getResourceAsStream( "cache-config-instance.xml" ); - final CacheType cacheConfig = new XmlService().fromInputStream( CacheType.class, is ); + final CacheConfig cache = new XmlService().fromInputStream( CacheConfig.class, is ); } @Test @@ -63,7 +62,7 @@ public void testReport() throws Exception { Document doc = db.parse( getClass().getResource( "cache-report-instance.xml" ).toString() ); InputStream is = getClass().getResourceAsStream( "cache-report-instance.xml" ); - final CacheReportType cacheReport = new XmlService().fromInputStream( CacheReportType.class, is ); + final CacheReportDto cacheReport = new XmlService().fromInputStream( CacheReportDto.class, is ); } @Test @@ -77,7 +76,7 @@ public void testBuildInfo() throws Exception { Document doc = db.parse( getClass().getResource( "cache-buildinfo-instance.xml" ).toString() ); InputStream is = getClass().getResourceAsStream( "cache-buildinfo-instance.xml" ); - final BuildInfoType buildInfo = new XmlService().fromInputStream( BuildInfoType.class, is ); + final BuildInfo buildInfo = new XmlService().fromInputStream( BuildInfo.class, is ); } @Test @@ -91,6 +90,6 @@ public void testBuildsDiff() throws Exception { Document doc = db.parse( getClass().getResource( "cache-buildsdiff-instance.xml" ).toString() ); InputStream is = getClass().getResourceAsStream( "cache-buildsdiff-instance.xml" ); - final BuildDiffType buildInfo = new XmlService().fromInputStream( BuildDiffType.class, is ); + final BuildDiff buildDiff = new XmlService().fromInputStream( BuildDiff.class, is ); } } \ No newline at end of file From 0cfdda1cfbd587a0e67d3cd28ab5d4e29ad84b10 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 16:54:06 +0100 Subject: [PATCH 115/188] [MNG-7324] Update doc regarding model changes --- Documentation/CACHE-HOWTO.md | 171 +++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 77 deletions(-) diff --git a/Documentation/CACHE-HOWTO.md b/Documentation/CACHE-HOWTO.md index 77d03ba07f19..c0877acfba08 100644 --- a/Documentation/CACHE-HOWTO.md +++ b/Documentation/CACHE-HOWTO.md @@ -26,8 +26,8 @@ Absolutely minimal config which enables incremental Maven with local cache ```xml - + true @@ -47,14 +47,13 @@ Absolutely minimal config which enables incremental Maven with local cache Just add `` section under `` ```xml - - - true - XX - - https://yourserver:port - - + + true + XX + + https://yourserver:port + + ``` ### Adding more file types to input @@ -62,12 +61,11 @@ Just add `` section under `` Add all the project specific source code files in ``. Scala in this case: ```xml - - - - {*.java,*.xml,*.properties,*.scala} - - + + + {*.java,*.xml,*.properties,*.scala} + + ``` ### Adding source directory for bespoke project layouts @@ -76,14 +74,17 @@ In most of the cases incremental Maven will recognize directories automatically add additional directories with ``. Also you can filter out undesirable dirs and files by using exclude tag ```xml - - - - {*.java,*.xml,*.properties,*.scala} - importantdir/ - tempfile.out - - + + + {*.java,*.xml,*.properties,*.scala} + + importantdir/ + + + tempfile.out + + + ``` ### Plugin property is env specific (breaks checksum and caching) @@ -91,17 +92,20 @@ add additional directories with ``. Also you can filter out undesirable Consider to exclude env specific properties: ```xml - - - - ... - - - - argLine - - - + + + ... + + + + + + argLine + + + + + ``` Implications - builds with different `argLine` will have identical checksum. Validate that is semantically valid. @@ -112,18 +116,21 @@ If plugin configuration property points to `somedir` it will be scanned with def processing rule ```xml - - - - ... - - - - - - - - + + + ... + + + + + + + + + + + + ``` ### Local repository is not updated because `install` is cached @@ -131,27 +138,27 @@ processing rule Add `executionControl/runAlways` section ```xml - - - - ... - - - ... - - - - unpack-autoupdate - - - install - + + + + + + + unpack-autoupdate + + + + + + + install + + + - ``` ### I occasionally cached build with `-DskipTests=true` and tests do not run now @@ -161,20 +168,30 @@ resolution to plugin runtime. To invalidate build if filed value is different in to `executionControl`: ```xml - - - + + + ... - - - - - - - - - - + + + + ... + + + + + + + + + + + + + + + ``` Please notice `skipValue` attribute. It denotes value which forces skipped execution. From 73d127437bcf03f2a3a9579296f152abba1f4d62 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 17:03:28 +0100 Subject: [PATCH 116/188] [MNG-7328] Fix tests --- .../java/org/apache/maven/caching/xml/XmlServiceTest.java | 4 ++-- .../apache/maven/caching/xml/cache-buildsdiff-instance.xml | 4 ++-- .../org/apache/maven/caching/xml/cache-report-instance.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java b/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java index f0ce1d5faa17..0a4a913824c0 100644 --- a/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java @@ -22,7 +22,7 @@ import org.apache.maven.caching.xml.buildinfo.BuildInfo; import org.apache.maven.caching.xml.buildsdiff.BuildDiff; import org.apache.maven.caching.xml.config.CacheConfig; -import org.apache.maven.caching.xml.report.CacheReportDto; +import org.apache.maven.caching.xml.report.CacheReport; import org.junit.Test; import java.io.InputStream; @@ -62,7 +62,7 @@ public void testReport() throws Exception { Document doc = db.parse( getClass().getResource( "cache-report-instance.xml" ).toString() ); InputStream is = getClass().getResourceAsStream( "cache-report-instance.xml" ); - final CacheReportDto cacheReport = new XmlService().fromInputStream( CacheReportDto.class, is ); + final CacheReport cacheReport = new XmlService().fromInputStream( CacheReport.class, is ); } @Test diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildsdiff-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildsdiff-instance.xml index 407cd36ccf2d..af43d3d25806 100644 --- a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildsdiff-instance.xml +++ b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildsdiff-instance.xml @@ -19,7 +19,7 @@ specific language governing permissions and limitations under the License. --> - @@ -28,4 +28,4 @@ under the License. - + diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-report-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-report-instance.xml index 9d685bae43ec..af1f64d1f63d 100644 --- a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-report-instance.xml +++ b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-report-instance.xml @@ -19,7 +19,7 @@ specific language governing permissions and limitations under the License. --> - @@ -29,4 +29,4 @@ under the License. - + From 0eca9b6f33858c9fcc249705de47b68d6a098f05 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 17:57:40 +0100 Subject: [PATCH 117/188] [MNG-7324] Rename buildinfo -> build and buildsdiff -> diff --- maven-caching/pom.xml | 4 +- .../maven/caching/ArtifactsRepository.java | 6 +- .../apache/maven/caching/CacheContext.java | 2 +- .../maven/caching/CacheControllerImpl.java | 62 ++++++------ .../org/apache/maven/caching/CacheDiff.java | 24 ++--- .../org/apache/maven/caching/CacheResult.java | 40 ++++---- .../maven/caching/CachingMojoExecutor.java | 14 +-- .../maven/caching/HttpRepositoryImpl.java | 22 ++--- .../caching/LocalArtifactsRepository.java | 8 +- .../maven/caching/LocalRepositoryImpl.java | 56 +++++------ .../maven/caching/MojoExecutionManager.java | 12 +-- .../apache/maven/caching/ProjectUtils.java | 2 +- .../caching/RemoteArtifactsRepository.java | 6 +- .../maven/caching/checksum/DigestUtils.java | 2 +- .../maven/caching/checksum/KeyUtils.java | 2 +- .../caching/checksum/MavenProjectInput.java | 17 ++-- .../xml/{BuildInfo.java => Build.java} | 32 +++---- .../maven/caching/xml/CacheConfigImpl.java | 2 +- .../apache/maven/caching/xml/DtoUtils.java | 8 +- .../apache/maven/caching/xml/XmlService.java | 94 +++++++++++++++---- .../{cache-buildinfo.mdo => cache-build.mdo} | 12 +-- .../{cache-buildsdiff.mdo => cache-diff.mdo} | 14 +-- .../apache/maven/caching/BuildInfoTest.java | 18 ++-- .../maven/caching/xml/XmlServiceTest.java | 28 +++--- ...-instance.xml => cache-build-instance.xml} | 4 +- ...f-instance.xml => cache-diff-instance.xml} | 6 +- 26 files changed, 278 insertions(+), 219 deletions(-) rename maven-caching/src/main/java/org/apache/maven/caching/xml/{BuildInfo.java => Build.java} (88%) rename maven-caching/src/main/mdo/{cache-buildinfo.mdo => cache-build.mdo} (97%) rename maven-caching/src/main/mdo/{cache-buildsdiff.mdo => cache-diff.mdo} (89%) rename maven-caching/src/test/resources/org/apache/maven/caching/xml/{cache-buildinfo-instance.xml => cache-build-instance.xml} (91%) rename maven-caching/src/test/resources/org/apache/maven/caching/xml/{cache-buildsdiff-instance.xml => cache-diff-instance.xml} (80%) diff --git a/maven-caching/pom.xml b/maven-caching/pom.xml index c4ab8fd3cb67..b37f39c8a38c 100644 --- a/maven-caching/pom.xml +++ b/maven-caching/pom.xml @@ -81,8 +81,8 @@ under the License. 1.1.0 src/main/mdo/cache-config.mdo - src/main/mdo/cache-buildinfo.mdo - src/main/mdo/cache-buildsdiff.mdo + src/main/mdo/cache-build.mdo + src/main/mdo/cache-diff.mdo src/main/mdo/cache-report.mdo 1.0.0 diff --git a/maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java index af73bebd9401..f3f45cf5d07b 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java @@ -21,7 +21,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.caching.xml.report.CacheReport; -import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.Build; import org.apache.maven.execution.MavenSession; import java.io.IOException; @@ -32,9 +32,9 @@ public interface ArtifactsRepository { - BuildInfo findBuild( CacheContext context ) throws IOException; + Build findBuild( CacheContext context ) throws IOException; - void saveBuildInfo( CacheResult cacheResult, BuildInfo buildInfo ) throws IOException; + void saveBuildInfo( CacheResult cacheResult, Build build ) throws IOException; void saveArtifactFile( CacheResult cacheResult, Artifact artifact ) throws IOException; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java index 51c1b78fe6d8..d34a78cc2069 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfo; +import org.apache.maven.caching.xml.build.ProjectsInputInfo; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index ed258028639c..cdd6ccddd34c 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -60,17 +60,17 @@ import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; import org.apache.maven.caching.xml.DtoUtils; import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.caching.xml.buildinfo.Artifact; -import org.apache.maven.caching.xml.buildinfo.CompletedExecution; -import org.apache.maven.caching.xml.buildinfo.DigestItem; -import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfo; -import org.apache.maven.caching.xml.buildinfo.Scm; -import org.apache.maven.caching.xml.buildsdiff.BuildDiff; +import org.apache.maven.caching.xml.build.Artifact; +import org.apache.maven.caching.xml.build.CompletedExecution; +import org.apache.maven.caching.xml.build.DigestItem; +import org.apache.maven.caching.xml.build.ProjectsInputInfo; +import org.apache.maven.caching.xml.build.Scm; +import org.apache.maven.caching.xml.diff.Diff; import org.apache.maven.caching.xml.config.PropertyName; import org.apache.maven.caching.xml.config.TrackedProperty; import org.apache.maven.caching.xml.report.CacheReport; @@ -186,7 +186,7 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, private CacheResult findCachedBuild( List mojoExecutions, CacheContext context ) { - BuildInfo cachedBuild = null; + Build cachedBuild = null; try { cachedBuild = localCache.findBuild( context ); @@ -201,7 +201,7 @@ private CacheResult findCachedBuild( List mojoExecutions, CacheCo private CacheResult findLocalBuild( List mojoExecutions, CacheContext context ) { - BuildInfo localBuild = null; + Build localBuild = null; try { localBuild = localCache.findLocalBuild( context ); @@ -214,7 +214,7 @@ private CacheResult findLocalBuild( List mojoExecutions, CacheCon } } - private CacheResult analyzeResult( CacheContext context, List mojoExecutions, BuildInfo info ) + private CacheResult analyzeResult( CacheContext context, List mojoExecutions, Build info ) { try @@ -282,7 +282,7 @@ private CacheResult analyzeResult( CacheContext context, List moj } } - private boolean canIgnoreMissingSegment( BuildInfo info, List mojoExecutions ) + private boolean canIgnoreMissingSegment( Build info, List mojoExecutions ) { final List postCachedSegment = info.getPostCachedSegment( mojoExecutions ); for ( MojoExecution mojoExecution : postCachedSegment ) @@ -299,11 +299,11 @@ private boolean canIgnoreMissingSegment( BuildInfo info, List moj public boolean restoreProjectArtifacts( CacheResult cacheResult ) { - final BuildInfo buildInfo = cacheResult.getBuildInfo(); + final Build build = cacheResult.getBuildInfo(); final CacheContext context = cacheResult.getContext(); final MavenProject project = context.getProject(); - final Artifact artifact = buildInfo.getArtifact(); + final Artifact artifact = build.getArtifact(); artifact.setVersion( project.getVersion() ); try @@ -323,7 +323,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) putChecksum( artifact, context.getInputInfo().getChecksum() ); } - for ( Artifact attachedArtifact : buildInfo.getAttachedArtifacts() ) + for ( Artifact attachedArtifact : build.getAttachedArtifacts() ) { attachedArtifact.setVersion( project.getVersion() ); if ( isNotBlank( attachedArtifact.getFileName() ) ) @@ -433,17 +433,17 @@ public void save( CacheResult cacheResult, List mojoExecutions, List completedExecution = buildExecutionInfo( mojoExecutions, executionEvents ); - final BuildInfo buildInfo = new BuildInfo( session.getGoals(), projectArtifactDto, attachedArtifactDtos, + final Build build = new Build( session.getGoals(), projectArtifactDto, attachedArtifactDtos, context.getInputInfo(), completedExecution, hashFactory.getAlgorithm() ); - populateGitInfo( buildInfo, session ); - buildInfo.getDto().set_final( cacheConfig.isSaveFinal() ); - cacheResults.put( getVersionlessProjectKey( project ), rebuilded( cacheResult, buildInfo ) ); + populateGitInfo( build, session ); + build.getDto().set_final( cacheConfig.isSaveFinal() ); + cacheResults.put( getVersionlessProjectKey( project ), rebuilded( cacheResult, build ) ); // if package phase presence means new artifacts were packaged if ( project.hasLifecyclePhase( "package" ) ) { localCache.beforeSave( context ); - localCache.saveBuildInfo( cacheResult, buildInfo ); + localCache.saveBuildInfo( cacheResult, build ); if ( projectArtifact.getFile() != null ) { localCache.saveArtifactFile( cacheResult, projectArtifact ); @@ -464,12 +464,12 @@ public void save( CacheResult cacheResult, List mojoExecutions, } else { - localCache.saveBuildInfo( cacheResult, buildInfo ); + localCache.saveBuildInfo( cacheResult, build ); } if ( cacheConfig.isBaselineDiffEnabled() ) { - produceDiffReport( cacheResult, buildInfo ); + produceDiffReport( cacheResult, build ); } } @@ -487,17 +487,17 @@ public void save( CacheResult cacheResult, List mojoExecutions, } } - public void produceDiffReport( CacheResult cacheResult, BuildInfo buildInfo ) + public void produceDiffReport( CacheResult cacheResult, Build build ) { MavenProject project = cacheResult.getContext().getProject(); - Optional baselineHolder = remoteCache.findBaselineBuild( project ); + Optional baselineHolder = remoteCache.findBaselineBuild( project ); if ( baselineHolder.isPresent() ) { - BuildInfo baseline = baselineHolder.get(); + Build baseline = baselineHolder.get(); String outputDirectory = project.getBuild().getDirectory(); Path reportOutputDir = Paths.get( outputDirectory, "incremental-maven" ); logInfo( project, "Saving cache builds diff to: " + reportOutputDir ); - BuildDiff diff = new CacheDiff( buildInfo.getDto(), baseline.getDto(), cacheConfig ).compare(); + Diff diff = new CacheDiff( build.getDto(), baseline.getDto(), cacheConfig ).compare(); try { Files.createDirectories( reportOutputDir ); @@ -506,10 +506,10 @@ public void produceDiffReport( CacheResult cacheResult, BuildInfo buildInfo ) Files.write( reportOutputDir.resolve( "buildinfo-baseline-" + checksum + ".xml" ), xmlService.toBytes( baseline.getDto() ), TRUNCATE_EXISTING, CREATE ); Files.write( reportOutputDir.resolve( "buildinfo-" + checksum + ".xml" ), - xmlService.toBytes( buildInfo.getDto() ), TRUNCATE_EXISTING, CREATE ); + xmlService.toBytes( build.getDto() ), TRUNCATE_EXISTING, CREATE ); Files.write( reportOutputDir.resolve( "buildsdiff-" + checksum + ".xml" ), xmlService.toBytes( diff ), TRUNCATE_EXISTING, CREATE ); - final Optional pom = CacheDiff.findPom( buildInfo.getDto().getProjectsInputInfo() ); + final Optional pom = CacheDiff.findPom( build.getDto().getProjectsInputInfo() ); if ( pom.isPresent() ) { Files.write( reportOutputDir.resolve( "effective-pom-" + checksum + ".xml" ), @@ -674,7 +674,7 @@ private boolean isTracked( String propertyName, List trackedPro return false; } - private boolean isCachedSegmentPropertiesPresent( MavenProject project, BuildInfo buildInfo, + private boolean isCachedSegmentPropertiesPresent( MavenProject project, Build build, List mojoExecutions ) { for ( MojoExecution mojoExecution : mojoExecutions ) @@ -682,7 +682,7 @@ private boolean isCachedSegmentPropertiesPresent( MavenProject project, BuildInf // completion of all mojos checked above, so we expect tp have execution info here final List trackedProperties = cacheConfig.getTrackedProperties( mojoExecution ); - final CompletedExecution cachedExecution = buildInfo.findMojoExecutionInfo( mojoExecution ); + final CompletedExecution cachedExecution = build.findMojoExecutionInfo( mojoExecution ); if ( cachedExecution == null ) { @@ -788,7 +788,7 @@ else if ( result.getSource() == CacheSource.BUILD && cacheConfig.isSaveToRemote( } } - private void populateGitInfo( BuildInfo buildInfo, MavenSession session ) throws IOException + private void populateGitInfo( Build build, MavenSession session ) throws IOException { if ( scm == null ) { @@ -808,7 +808,7 @@ private void populateGitInfo( BuildInfo buildInfo, MavenSession session ) throws } } } - buildInfo.getDto().setScm( scm ); + build.getDto().setScm( scm ); } private void zipAndAttachArtifact( MavenProject project, Path dir, String classifier ) throws IOException diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java index c3bde3dbb117..82be28f56d8e 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java @@ -22,13 +22,13 @@ import com.google.common.base.Optional; import com.google.common.collect.Sets; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.xml.buildinfo.BuildInfo; -import org.apache.maven.caching.xml.buildinfo.CompletedExecution; -import org.apache.maven.caching.xml.buildinfo.DigestItem; -import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfo; -import org.apache.maven.caching.xml.buildinfo.PropertyValue; -import org.apache.maven.caching.xml.buildsdiff.BuildDiff; -import org.apache.maven.caching.xml.buildsdiff.Mismatch; +import org.apache.maven.caching.xml.build.Build; +import org.apache.maven.caching.xml.build.CompletedExecution; +import org.apache.maven.caching.xml.build.DigestItem; +import org.apache.maven.caching.xml.build.ProjectsInputInfo; +import org.apache.maven.caching.xml.build.PropertyValue; +import org.apache.maven.caching.xml.diff.Diff; +import org.apache.maven.caching.xml.diff.Mismatch; import org.apache.maven.caching.xml.CacheConfig; import java.util.ArrayList; @@ -44,11 +44,11 @@ public class CacheDiff { private final CacheConfig config; - private final BuildInfo current; - private final BuildInfo baseline; + private final Build current; + private final Build baseline; private final LinkedList report; - public CacheDiff( BuildInfo current, BuildInfo baseline, CacheConfig config ) + public CacheDiff( Build current, Build baseline, CacheConfig config ) { this.current = current; this.baseline = baseline; @@ -56,7 +56,7 @@ public CacheDiff( BuildInfo current, BuildInfo baseline, CacheConfig config ) this.report = new LinkedList<>(); } - public BuildDiff compare() + public Diff compare() { if ( !StringUtils.equals( current.getHashFunction(), baseline.getHashFunction() ) ) @@ -74,7 +74,7 @@ public BuildDiff compare() compareFiles( current.getProjectsInputInfo(), baseline.getProjectsInputInfo() ); compareDependencies( current.getProjectsInputInfo(), baseline.getProjectsInputInfo() ); - final BuildDiff buildDiffType = new BuildDiff(); + final Diff buildDiffType = new Diff(); buildDiffType.getMismatches().addAll( report ); return buildDiffType; } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheResult.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheResult.java index 84038a3311d8..e96abe6bb46e 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheResult.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheResult.java @@ -19,7 +19,7 @@ * under the License. */ -import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheSource; import static java.util.Objects.requireNonNull; @@ -30,13 +30,13 @@ public class CacheResult { private final RestoreStatus status; - private final BuildInfo buildInfo; + private final Build build; private final CacheContext context; - private CacheResult( RestoreStatus status, BuildInfo buildInfo, CacheContext context ) + private CacheResult( RestoreStatus status, Build build, CacheContext context ) { this.status = requireNonNull( status ); - this.buildInfo = buildInfo; + this.build = build; this.context = context; } @@ -51,25 +51,25 @@ public static CacheResult empty() return new CacheResult( RestoreStatus.EMPTY, null, null ); } - public static CacheResult failure( BuildInfo buildInfo, CacheContext context ) + public static CacheResult failure( Build build, CacheContext context ) { - requireNonNull( buildInfo ); + requireNonNull( build ); requireNonNull( context ); - return new CacheResult( RestoreStatus.FAILURE, buildInfo, context ); + return new CacheResult( RestoreStatus.FAILURE, build, context ); } - public static CacheResult success( BuildInfo buildInfo, CacheContext context ) + public static CacheResult success( Build build, CacheContext context ) { - requireNonNull( buildInfo ); + requireNonNull( build ); requireNonNull( context ); - return new CacheResult( RestoreStatus.SUCCESS, buildInfo, context ); + return new CacheResult( RestoreStatus.SUCCESS, build, context ); } - public static CacheResult partialSuccess( BuildInfo buildInfo, CacheContext context ) + public static CacheResult partialSuccess( Build build, CacheContext context ) { - requireNonNull( buildInfo ); + requireNonNull( build ); requireNonNull( context ); - return new CacheResult( RestoreStatus.PARTIAL, buildInfo, context ); + return new CacheResult( RestoreStatus.PARTIAL, build, context ); } public static CacheResult failure( CacheContext context ) @@ -78,11 +78,11 @@ public static CacheResult failure( CacheContext context ) return new CacheResult( RestoreStatus.FAILURE, null, context ); } - public static CacheResult rebuilded( CacheResult orig, BuildInfo buildInfo ) + public static CacheResult rebuilded( CacheResult orig, Build build ) { requireNonNull( orig ); - requireNonNull( buildInfo ); - return new CacheResult( orig.status, buildInfo, orig.context ); + requireNonNull( build ); + return new CacheResult( orig.status, build, orig.context ); } public boolean isSuccess() @@ -90,14 +90,14 @@ public boolean isSuccess() return status == RestoreStatus.SUCCESS; } - public BuildInfo getBuildInfo() + public Build getBuildInfo() { - return buildInfo; + return build; } public CacheSource getSource() { - return buildInfo != null ? buildInfo.getSource() : null; + return build != null ? build.getSource() : null; } public CacheContext getContext() @@ -117,6 +117,6 @@ public RestoreStatus getStatus() public boolean isFinal() { - return buildInfo != null && buildInfo.getDto().is_final(); + return build != null && build.getDto().is_final(); } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java index 49ee294bead9..c45dbae6f0bd 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java @@ -36,7 +36,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter; -import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheState; import org.apache.maven.execution.ExecutionEvent; @@ -248,10 +248,10 @@ private boolean restoreProject( CacheResult cacheResult, PhaseRecorder phaseRecorder ) throws LifecycleExecutionException { - final BuildInfo buildInfo = cacheResult.getBuildInfo(); + final Build build = cacheResult.getBuildInfo(); final MavenProject project = cacheResult.getContext().getProject(); final MavenSession session = cacheResult.getContext().getSession(); - final List cachedSegment = buildInfo.getCachedSegment( mojoExecutions ); + final List cachedSegment = build.getCachedSegment( mojoExecutions ); boolean restored = cacheController.restoreProjectArtifacts( cacheResult ); if ( !restored ) @@ -274,7 +274,7 @@ private boolean restoreProject( CacheResult cacheResult, } else { - restored = verifyCacheConsistency( cacheCandidate, buildInfo, project, session, projectIndex, + restored = verifyCacheConsistency( cacheCandidate, build, project, session, projectIndex, dependencyContext, phaseRecorder ); if ( !restored ) { @@ -297,7 +297,7 @@ private boolean restoreProject( CacheResult cacheResult, } } - for ( MojoExecution mojoExecution : buildInfo.getPostCachedSegment( mojoExecutions ) ) + for ( MojoExecution mojoExecution : build.getPostCachedSegment( mojoExecutions ) ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } @@ -305,7 +305,7 @@ private boolean restoreProject( CacheResult cacheResult, } private boolean verifyCacheConsistency( MojoExecution cacheCandidate, - BuildInfo cachedBuildInfo, + Build cachedBuild, MavenProject project, MavenSession session, ProjectIndex projectIndex, @@ -314,7 +314,7 @@ private boolean verifyCacheConsistency( MojoExecution cacheCandidate, { AtomicBoolean consistent = new AtomicBoolean( true ); - final MojoExecutionManager mojoChecker = new MojoExecutionManager( project, cacheController, cachedBuildInfo, + final MojoExecutionManager mojoChecker = new MojoExecutionManager( project, cacheController, cachedBuild, consistent, logger, cacheConfig ); if ( mojoChecker.needCheck( cacheCandidate, session ) ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java index 686d762e783a..501bd38728b3 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java @@ -43,11 +43,11 @@ import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.maven.caching.checksum.MavenProjectInput; +import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.caching.xml.buildinfo.Artifact; -import org.apache.maven.caching.xml.buildinfo.BuildInfo; +import org.apache.maven.caching.xml.build.Artifact; import org.apache.maven.caching.xml.report.CacheReport; import org.apache.maven.caching.xml.report.ProjectReport; import org.apache.maven.execution.MavenSession; @@ -93,15 +93,15 @@ protected HttpClient initialValue() }; @Override - public org.apache.maven.caching.xml.BuildInfo findBuild( CacheContext context ) + public Build findBuild( CacheContext context ) { final String resourceUrl = getResourceUrl( context, BUILDINFO_XML ); String artifactId = context.getProject().getArtifactId(); if ( exists( artifactId, resourceUrl ) ) { final byte[] bytes = getResourceContent( resourceUrl, artifactId ); - final BuildInfo dto = xmlService.fromBytes( BuildInfo.class, bytes ); - return new org.apache.maven.caching.xml.BuildInfo( dto, CacheSource.REMOTE ); + final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( bytes ); + return new Build( dto, CacheSource.REMOTE ); } return null; } @@ -114,12 +114,12 @@ public byte[] getArtifactContent( CacheContext context, Artifact artifact ) } @Override - public void saveBuildInfo( CacheResult cacheResult, org.apache.maven.caching.xml.BuildInfo buildInfo ) + public void saveBuildInfo( CacheResult cacheResult, Build build ) throws IOException { CacheContext context = cacheResult.getContext(); final String resourceUrl = getResourceUrl( cacheResult.getContext(), BUILDINFO_XML ); - putToRemoteCache( new ByteArrayInputStream( xmlService.toBytes( buildInfo.getDto() ) ), resourceUrl, + putToRemoteCache( new ByteArrayInputStream( xmlService.toBytes( build.getDto() ) ), resourceUrl, context.getProject().getArtifactId() ); } @@ -247,7 +247,7 @@ private void putToRemoteCache( InputStream instream, String url, String logRefer private final AtomicReference>> cacheReportSupplier = new AtomicReference<>(); @Override - public Optional findBaselineBuild( MavenProject project ) + public Optional findBaselineBuild( MavenProject project ) { final Optional> cachedProjectsHolder = findCacheInfo() .transform( CacheReport::getProjects ); @@ -288,8 +288,8 @@ public Optional findBaselineBuild( Maven if ( exists( project.getArtifactId(), url ) ) { byte[] content = getResourceContent( url, project.getArtifactId() ); - final BuildInfo dto = xmlService.fromBytes( BuildInfo.class, content ); - return Optional.of( new org.apache.maven.caching.xml.BuildInfo( dto, CacheSource.REMOTE ) ); + final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( content ); + return Optional.of( new Build( dto, CacheSource.REMOTE ) ); } else { @@ -317,7 +317,7 @@ private Optional findCacheInfo() logInfo( "Downloading baseline cache report from: " + cacheConfig.getBaselineCacheUrl(), "DEBUG" ); byte[] content = getResourceContent( cacheConfig.getBaselineCacheUrl(), "cache-info" ); - CacheReport cacheReportType = xmlService.fromBytes( CacheReport.class, content ); + CacheReport cacheReportType = xmlService.loadCacheReport( content ); return Optional.of( cacheReportType ); } catch ( Exception e ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java index feb091babf3d..7a0530d1cafa 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java @@ -20,9 +20,9 @@ */ import com.google.common.base.Optional; -import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheSource; -import org.apache.maven.caching.xml.buildinfo.Artifact; +import org.apache.maven.caching.xml.build.Artifact; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; @@ -41,7 +41,7 @@ public interface LocalArtifactsRepository extends ArtifactsRepository void clearCache( CacheContext context ); - Optional findBestMatchingBuild( MavenSession session, Dependency dependency ) throws IOException; + Optional findBestMatchingBuild( MavenSession session, Dependency dependency ) throws IOException; - BuildInfo findLocalBuild( CacheContext context ) throws IOException; + Build findLocalBuild( CacheContext context ) throws IOException; } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java index e3935fdcc892..36284dd3fcd0 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java @@ -50,12 +50,12 @@ import com.google.common.collect.Ordering; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.tuple.Pair; +import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.caching.xml.buildinfo.Artifact; -import org.apache.maven.caching.xml.buildinfo.BuildInfo; -import org.apache.maven.caching.xml.buildinfo.Scm; +import org.apache.maven.caching.xml.build.Artifact; +import org.apache.maven.caching.xml.build.Scm; import org.apache.maven.caching.xml.report.CacheReport; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; @@ -88,7 +88,7 @@ public class LocalRepositoryImpl implements LocalArtifactsRepository private static final long ONE_DAY_MILLIS = DAYS.toMillis( 1 ); private static final String EMPTY = ""; private static final LastModifiedComparator LAST_MODIFIED_COMPARATOR = new LastModifiedComparator(); - private static final Function, Long> GET_LAST_MODIFIED = + private static final Function, Long> GET_LAST_MODIFIED = pair -> pair.getRight().lastModified(); @Inject @@ -107,12 +107,12 @@ public class LocalRepositoryImpl implements LocalArtifactsRepository private CacheConfig cacheConfig; private final LoadingCache, - Optional> bestBuildCache = + Optional> bestBuildCache = CacheBuilder.newBuilder().build( CacheLoader.from( new Function, - Optional>() + Optional>() { @Override - public Optional apply( Pair input ) + public Optional apply( Pair input ) { try { @@ -127,7 +127,7 @@ public Optional apply( Pair created + ONE_DAY_MILLIS && now < lastModified + ONE_DAY_MILLIS } } - final org.apache.maven.caching.xml.BuildInfo buildInfo = remoteRepository.findBuild( context ); - if ( buildInfo != null ) + final Build build = remoteRepository.findBuild( context ); + if ( build != null ) { logInfo( context, "Build info downloaded from remote repo, saving to: " + buildInfoPath ); Files.createDirectories( buildInfoPath.getParent() ); - Files.write( buildInfoPath, xmlService.toBytes( buildInfo.getDto() ), CREATE_NEW ); + Files.write( buildInfoPath, xmlService.toBytes( build.getDto() ), CREATE_NEW ); } else { FileUtils.touch( lookupInfoPath.toFile() ); } - return buildInfo; + return build; } catch ( Exception e ) { @@ -270,14 +270,14 @@ public void clearCache( CacheContext context ) } @Override - public Optional findBestMatchingBuild( + public Optional findBestMatchingBuild( MavenSession session, Dependency dependency ) { return bestBuildCache.getUnchecked( Pair.of( session, dependency ) ); } - private Optional findBestMatchingBuildImpl( + private Optional findBestMatchingBuildImpl( Pair dependencySession ) throws IOException { @@ -286,7 +286,7 @@ private Optional findBestMatchingBuildIm final Path artifactCacheDir = artifactCacheDir( session, dependency.getGroupId(), dependency.getArtifactId() ); - final Multimap, Pair> + final Multimap, Pair> filesByVersion = ArrayListMultimap.create(); Files.walkFileTree( artifactCacheDir, new SimpleFileVisitor() @@ -299,9 +299,9 @@ public FileVisitResult visitFile( Path o, BasicFileAttributes basicFileAttribute { try { - final BuildInfo dto = xmlService.fromFile( BuildInfo.class, file ); - final Pair buildInfoAndFile = - Pair.of( new org.apache.maven.caching.xml.BuildInfo( dto, CacheSource.LOCAL ), file ); + final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( file ); + final Pair buildInfoAndFile = + Pair.of( new Build( dto, CacheSource.LOCAL ), file ); final String cachedVersion = dto.getArtifact().getVersion(); final String cachedBranch = getScmRef( dto.getScm() ); filesByVersion.put( Pair.of( cachedVersion, cachedBranch ), buildInfoAndFile ); @@ -331,7 +331,7 @@ public FileVisitResult visitFile( Path o, BasicFileAttributes basicFileAttribute final String currentRef = getScmRef( ProjectUtils.readGitInfo( session ) ); // first lets try by branch and version - Collection> bestMatched = new LinkedList<>(); + Collection> bestMatched = new LinkedList<>(); if ( isNotBlank( currentRef ) ) { bestMatched = filesByVersion.get( Pair.of( dependency.getVersion(), currentRef ) ); @@ -352,7 +352,7 @@ public FileVisitResult visitFile( Path o, BasicFileAttributes basicFileAttribute bestMatched = filesByVersion.values(); } - List> orderedFiles = Ordering.natural().onResultOf( + List> orderedFiles = Ordering.natural().onResultOf( GET_LAST_MODIFIED ).reverse().sortedCopy( bestMatched ); return Optional.of( orderedFiles.get( 0 ).getLeft() ); } @@ -398,14 +398,14 @@ public void beforeSave( CacheContext environment ) } @Override - public void saveBuildInfo( CacheResult cacheResult, org.apache.maven.caching.xml.BuildInfo buildInfo ) + public void saveBuildInfo( CacheResult cacheResult, Build build ) throws IOException { final Path path = localBuildPath( cacheResult.getContext(), BUILDINFO_XML, true ); - Files.write( path, xmlService.toBytes( buildInfo.getDto() ), TRUNCATE_EXISTING, CREATE ); + Files.write( path, xmlService.toBytes( build.getDto() ), TRUNCATE_EXISTING, CREATE ); if ( cacheConfig.isRemoteCacheEnabled() && cacheConfig.isSaveToRemote() && !cacheResult.isFinal() ) { - remoteRepository.saveBuildInfo( cacheResult, buildInfo ); + remoteRepository.saveBuildInfo( cacheResult, build ); } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java index d97e20469080..961a9c4a49f2 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java @@ -20,11 +20,11 @@ */ import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.xml.BuildInfo; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; +import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.config.TrackedProperty; -import org.apache.maven.caching.xml.buildinfo.CompletedExecution; +import org.apache.maven.caching.xml.build.CompletedExecution; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.MojoCheker; @@ -47,21 +47,21 @@ public class MojoExecutionManager implements MojoCheker private final long createdTimestamp; private final Logger logger; private final MavenProject project; - private final BuildInfo buildInfo; + private final Build build; private final AtomicBoolean consistent; private final CacheController cacheController; private final CacheConfig cacheConfig; public MojoExecutionManager( MavenProject project, CacheController cacheController, - BuildInfo buildInfo, + Build build, AtomicBoolean consistent, Logger logger, CacheConfig cacheConfig ) { this.createdTimestamp = System.currentTimeMillis(); this.project = project; this.cacheController = cacheController; - this.buildInfo = buildInfo; + this.build = build; this.consistent = consistent; this.logger = logger; this.cacheConfig = cacheConfig; @@ -86,7 +86,7 @@ public boolean needCheck( MojoExecution mojoExecution, MavenSession session ) public boolean check( MojoExecution execution, Mojo mojo, MavenSession session ) { - final CompletedExecution completedExecution = buildInfo.findMojoExecutionInfo( execution ); + final CompletedExecution completedExecution = build.findMojoExecutionInfo( execution ); final String fullGoalName = execution.getMojoDescriptor().getFullGoalName(); if ( completedExecution != null && !isParamsMatched( project, execution, mojo, completedExecution ) ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java index 49d2bb712400..adb0147a3d9a 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java @@ -25,7 +25,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.caching.xml.buildinfo.Scm; +import org.apache.maven.caching.xml.build.Scm; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.internal.ProjectIndex; import org.apache.maven.lifecycle.internal.builder.BuilderCommon; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java index 5f60b1c5debc..ca4e215d2afb 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java @@ -20,8 +20,8 @@ */ import com.google.common.base.Optional; -import org.apache.maven.caching.xml.BuildInfo; -import org.apache.maven.caching.xml.buildinfo.Artifact; +import org.apache.maven.caching.xml.Build; +import org.apache.maven.caching.xml.build.Artifact; import org.apache.maven.project.MavenProject; import java.io.IOException; @@ -38,5 +38,5 @@ public interface RemoteArtifactsRepository extends ArtifactsRepository String getResourceUrl( CacheContext context, String filename ); - Optional findBaselineBuild( MavenProject project ); + Optional findBaselineBuild( MavenProject project ); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java index 40766d65d7c9..f9fc0dd608bb 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java @@ -22,7 +22,7 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.maven.caching.hash.HashChecksum; -import org.apache.maven.caching.xml.buildinfo.DigestItem; +import org.apache.maven.caching.xml.build.DigestItem; import org.mozilla.universalchardet.UniversalDetector; import java.io.IOException; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java index 48b48c434da4..3fa9d5d8744d 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java @@ -20,7 +20,7 @@ */ import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.xml.buildinfo.Artifact; +import org.apache.maven.caching.xml.build.Artifact; import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 3f4e3a9a0a4b..69c79d586ba2 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -35,16 +35,15 @@ import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashChecksum; -import org.apache.maven.caching.xml.BuildInfo; +import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; -import org.apache.maven.caching.xml.buildinfo.DigestItem; -import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfo; +import org.apache.maven.caching.xml.build.DigestItem; +import org.apache.maven.caching.xml.build.ProjectsInputInfo; import org.apache.maven.caching.xml.config.Exclude; import org.apache.maven.caching.xml.config.Include; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.internal.ProjectIndex; -import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; @@ -175,7 +174,7 @@ public MavenProjectInput( MavenProject project, this.processPlugins = Boolean.parseBoolean( properties.getProperty( CACHE_PROCESS_PLUGINS, config.isProcessPlugins() ) ); - Build build = project.getBuild(); + org.apache.maven.model.Build build = project.getBuild(); filteredOutPaths = new ArrayList<>( Arrays.asList( normalizedPath( build.getDirectory() ), // target by default normalizedPath( build.getOutputDirectory() ), normalizedPath( build.getTestOutputDirectory() ) ) ); @@ -361,7 +360,7 @@ private String getEffectivePom( Model prototype ) throws IOException List plugins = normalizePlugins( prototype.getBuild().getPlugins() ); - Build build = new Build(); + org.apache.maven.model.Build build = new org.apache.maven.model.Build(); build.setPluginManagement( pluginManagement ); build.setPlugins( plugins ); @@ -394,7 +393,7 @@ private SortedSet getInputFiles() HashSet visitedDirs = new HashSet<>(); ArrayList collectedFiles = new ArrayList<>(); - Build build = project.getBuild(); + org.apache.maven.model.Build build = project.getBuild(); final boolean recursive = true; startWalk( Paths.get( build.getSourceDirectory() ), dirGlob, recursive, collectedFiles, visitedDirs ); @@ -798,10 +797,10 @@ private SortedMap getMutableDependencies() throws IOExceptio if ( partOfMultiModule ) { // TODO lookup in remote cache is not necessary for abfx, for versioned projects - make sense - final Optional bestMatchResult = localCache.findBestMatchingBuild( session, dependency ); + final Optional bestMatchResult = localCache.findBestMatchingBuild( session, dependency ); if ( bestMatchResult.isPresent() ) { - final BuildInfo bestMatched = bestMatchResult.get(); + final Build bestMatched = bestMatchResult.get(); resolved = bestMatched.findArtifact( dependency ); } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/BuildInfo.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java similarity index 88% rename from maven-caching/src/main/java/org/apache/maven/caching/xml/BuildInfo.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java index 606cb5276632..72a5021fc1e5 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/BuildInfo.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java @@ -23,10 +23,10 @@ import org.apache.maven.caching.ProjectUtils; import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.hash.HashAlgorithm; -import org.apache.maven.caching.xml.buildinfo.Artifact; -import org.apache.maven.caching.xml.buildinfo.CompletedExecution; -import org.apache.maven.caching.xml.buildinfo.DigestItem; -import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfo; +import org.apache.maven.caching.xml.build.Artifact; +import org.apache.maven.caching.xml.build.CompletedExecution; +import org.apache.maven.caching.xml.build.DigestItem; +import org.apache.maven.caching.xml.build.ProjectsInputInfo; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecution; import org.codehaus.plexus.logging.Logger; @@ -47,20 +47,20 @@ /** * BuildInfo */ -public class BuildInfo +public class Build { - final org.apache.maven.caching.xml.buildinfo.BuildInfo dto; + final org.apache.maven.caching.xml.build.Build dto; CacheSource source; - public BuildInfo( List goals, - Artifact artifact, - List attachedArtifacts, - ProjectsInputInfo projectsInputInfo, - List completedExecutions, - String hashAlgorithm ) + public Build( List goals, + Artifact artifact, + List attachedArtifacts, + ProjectsInputInfo projectsInputInfo, + List completedExecutions, + String hashAlgorithm ) { - this.dto = new org.apache.maven.caching.xml.buildinfo.BuildInfo(); + this.dto = new org.apache.maven.caching.xml.build.Build(); this.dto.setCacheImplementationVersion( MavenProjectInput.CACHE_IMPLMENTATION_VERSION ); this.dto.setBuildTime( new Date() ); try @@ -85,9 +85,9 @@ public CacheSource getSource() return source; } - public BuildInfo( org.apache.maven.caching.xml.buildinfo.BuildInfo buildInfo, CacheSource source ) + public Build( org.apache.maven.caching.xml.build.Build dto, CacheSource source ) { - this.dto = buildInfo; + this.dto = dto; this.source = source; } @@ -181,7 +181,7 @@ public List getAttachedArtifacts() return Collections.emptyList(); } - public org.apache.maven.caching.xml.buildinfo.BuildInfo getDto() + public org.apache.maven.caching.xml.build.Build getDto() { return dto; } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 0ab71bddcd51..71be02ef36a2 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -151,7 +151,7 @@ public synchronized CacheState initialize( MavenProject project, MavenSession se try { logger.info( "Loading cache configuration from " + configPath ); - cacheConfig = xmlService.fromFile( CacheConfig.class, configPath.toFile() ); + cacheConfig = xmlService.loadCacheConfig( configPath.toFile() ); } catch ( Exception e ) { diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java index 74a7540055d1..690b7c19fe01 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java @@ -22,10 +22,10 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.maven.caching.ProjectUtils; -import org.apache.maven.caching.xml.buildinfo.Artifact; -import org.apache.maven.caching.xml.buildinfo.CompletedExecution; -import org.apache.maven.caching.xml.buildinfo.DigestItem; -import org.apache.maven.caching.xml.buildinfo.PropertyValue; +import org.apache.maven.caching.xml.build.Artifact; +import org.apache.maven.caching.xml.build.CompletedExecution; +import org.apache.maven.caching.xml.build.DigestItem; +import org.apache.maven.caching.xml.build.PropertyValue; import org.apache.maven.caching.xml.config.TrackedProperty; import org.apache.maven.model.Dependency; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java index c10b1ee0b330..cde63c1a49ec 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java @@ -29,12 +29,12 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.apache.maven.caching.xml.buildinfo.BuildInfo; -import org.apache.maven.caching.xml.buildinfo.io.xpp3.CacheBuildInfoXpp3Reader; -import org.apache.maven.caching.xml.buildinfo.io.xpp3.CacheBuildInfoXpp3Writer; -import org.apache.maven.caching.xml.buildsdiff.BuildDiff; -import org.apache.maven.caching.xml.buildsdiff.io.xpp3.CacheBuildsDiffXpp3Reader; -import org.apache.maven.caching.xml.buildsdiff.io.xpp3.CacheBuildsDiffXpp3Writer; +import org.apache.maven.caching.xml.build.Build; +import org.apache.maven.caching.xml.build.io.xpp3.CacheBuildXpp3Reader; +import org.apache.maven.caching.xml.build.io.xpp3.CacheBuildXpp3Writer; +import org.apache.maven.caching.xml.diff.Diff; +import org.apache.maven.caching.xml.diff.io.xpp3.CacheDiffXpp3Reader; +import org.apache.maven.caching.xml.diff.io.xpp3.CacheDiffXpp3Writer; import org.apache.maven.caching.xml.config.CacheConfig; import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Reader; import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Writer; @@ -60,20 +60,20 @@ public byte[] toBytes( CacheConfig cache ) throws IOException } } - public byte[] toBytes( BuildInfo buildInfo ) throws IOException + public byte[] toBytes( Build build ) throws IOException { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { - new CacheBuildInfoXpp3Writer().write( baos, buildInfo ); + new CacheBuildXpp3Writer().write( baos, build ); return baos.toByteArray(); } } - public byte[] toBytes( BuildDiff diff ) throws IOException + public byte[] toBytes( Diff diff ) throws IOException { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { - new CacheBuildsDiffXpp3Writer().write( baos, diff ); + new CacheDiffXpp3Writer().write( baos, diff ); return baos.toByteArray(); } } @@ -87,31 +87,91 @@ public byte[] toBytes( CacheReport cacheReportType ) throws IOException } } - public T fromFile( Class clazz, File file ) throws IOException, XmlPullParserException + public Build loadBuild( File file ) throws IOException + { + return fromFile( Build.class, file ); + } + + public Build loadBuild( byte[] bytes ) + { + return fromBytes( Build.class, bytes ); + } + + public Build loadBuild( InputStream inputStream ) + { + return fromInputStream( Build.class, inputStream ); + } + + public CacheConfig loadCacheConfig( File file ) throws IOException + { + return fromFile( CacheConfig.class, file ); + } + + public CacheConfig loadCacheConfig( byte[] bytes ) + { + return fromBytes( CacheConfig.class, bytes ); + } + + public CacheConfig loadCacheConfig( InputStream inputStream ) + { + return fromInputStream( CacheConfig.class, inputStream ); + } + + public CacheReport loadCacheReport( File file ) throws IOException + { + return fromFile( CacheReport.class, file ); + } + + public CacheReport loadCacheReport( byte[] bytes ) + { + return fromBytes( CacheReport.class, bytes ); + } + + public CacheReport loadCacheReport( InputStream inputStream ) + { + return fromInputStream( CacheReport.class, inputStream ); + } + + public Diff loadDiff( File file ) throws IOException + { + return fromFile( Diff.class, file ); + } + + public Diff loadDiff( byte[] bytes ) + { + return fromBytes( Diff.class, bytes ); + } + + public Diff loadDiff( InputStream inputStream ) + { + return fromInputStream( Diff.class, inputStream ); + } + + private T fromFile( Class clazz, File file ) throws IOException { return fromInputStream( clazz, Files.newInputStream( file.toPath() ) ); } - public T fromBytes( Class clazz, byte[] bytes ) + private T fromBytes( Class clazz, byte[] bytes ) { return fromInputStream( clazz, new ByteArrayInputStream( bytes ) ); } - public T fromInputStream( Class clazz, InputStream inputStream ) + private T fromInputStream( Class clazz, InputStream inputStream ) { try { - if ( clazz == BuildInfo.class ) + if ( clazz == Build.class ) { - return clazz.cast( new CacheBuildInfoXpp3Reader().read( inputStream ) ); + return clazz.cast( new CacheBuildXpp3Reader().read( inputStream ) ); } else if ( clazz == CacheConfig.class ) { return clazz.cast( new CacheConfigXpp3Reader().read( inputStream ) ); } - else if ( clazz == BuildDiff.class ) + else if ( clazz == Diff.class ) { - return clazz.cast( new CacheBuildsDiffXpp3Reader().read( inputStream ) ); + return clazz.cast( new CacheDiffXpp3Reader().read( inputStream ) ); } else if ( clazz == CacheReport.class ) { diff --git a/maven-caching/src/main/mdo/cache-buildinfo.mdo b/maven-caching/src/main/mdo/cache-build.mdo similarity index 97% rename from maven-caching/src/main/mdo/cache-buildinfo.mdo rename to maven-caching/src/main/mdo/cache-build.mdo index 4d83fcd8d102..b1d720332bcd 100644 --- a/maven-caching/src/main/mdo/cache-buildinfo.mdo +++ b/maven-caching/src/main/mdo/cache-build.mdo @@ -19,22 +19,22 @@ under the License. - cache-buildinfo - CacheBuildInfo + xml.namespace="http://maven.apache.org/CACHE-BUILD/${version}" + xml.schemaLocation="http://maven.apache.org/xsd/cache-build-${version}.xsd"> + cache-build + CacheBuild lookupinfo.xml or remote buildinfo.xml ]]> package - org.apache.maven.caching.xml.buildinfo + org.apache.maven.caching.xml.build - BuildInfo + Build 1.0.0+ diff --git a/maven-caching/src/main/mdo/cache-buildsdiff.mdo b/maven-caching/src/main/mdo/cache-diff.mdo similarity index 89% rename from maven-caching/src/main/mdo/cache-buildsdiff.mdo rename to maven-caching/src/main/mdo/cache-diff.mdo index a7b55f0c5fdc..9d837362b663 100644 --- a/maven-caching/src/main/mdo/cache-buildsdiff.mdo +++ b/maven-caching/src/main/mdo/cache-diff.mdo @@ -19,16 +19,16 @@ under the License. - cache-buildsdiff - CacheBuildsDiff - buildsdiff-${checksum}.xml + xml.namespace="http://maven.apache.org/CACHE-DIFF/${version}" + xml.schemaLocation="http://maven.apache.org/xsd/cache-diff-${version}.xsd"> + cache-diff + CacheDiff + diff-${checksum}.xml ]]> package - org.apache.maven.caching.xml.buildsdiff + org.apache.maven.caching.xml.diff @@ -40,7 +40,7 @@ under the License. - BuildDiff + Diff mismatches diff --git a/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java b/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java index 5ae2a870ff09..f99934686949 100644 --- a/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java @@ -34,12 +34,12 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.xml.buildinfo.Artifact; -import org.apache.maven.caching.xml.buildinfo.BuildInfo; -import org.apache.maven.caching.xml.buildinfo.CompletedExecution; -import org.apache.maven.caching.xml.buildinfo.DigestItem; -import org.apache.maven.caching.xml.buildinfo.ProjectsInputInfo; -import org.apache.maven.caching.xml.buildinfo.PropertyValue; +import org.apache.maven.caching.xml.Build; +import org.apache.maven.caching.xml.build.Artifact; +import org.apache.maven.caching.xml.build.CompletedExecution; +import org.apache.maven.caching.xml.build.DigestItem; +import org.apache.maven.caching.xml.build.ProjectsInputInfo; +import org.apache.maven.caching.xml.build.PropertyValue; import org.apache.maven.caching.xml.XmlService; import org.junit.Test; @@ -65,7 +65,7 @@ public void name() throws Exception { artifact.setFileSize(123456); artifact.setFileHash("456L"); - BuildInfo buildInfo = new BuildInfo(); + org.apache.maven.caching.xml.build.Build buildInfo = new org.apache.maven.caching.xml.build.Build(); buildInfo.setCacheImplementationVersion("cacheImplementationVersion"); buildInfo.setBuildServer("server"); buildInfo.setBuildTime(new Date()); @@ -73,7 +73,7 @@ public void name() throws Exception { buildInfo.setHashFunction("SHA-256"); buildInfo.setGoals(Lists.newArrayList("install")); final org.apache.maven.artifact.Artifact attachedArtifact = new DefaultArtifact("ag", "aa", "av", "as", "at", "ac", new DefaultArtifactHandler()); - buildInfo.setAttachedArtifacts(org.apache.maven.caching.xml.BuildInfo.createAttachedArtifacts(Lists.newArrayList(attachedArtifact), HashFactory.XX.createAlgorithm())); + buildInfo.setAttachedArtifacts(Build.createAttachedArtifacts(Lists.newArrayList(attachedArtifact), HashFactory.XX.createAlgorithm())); buildInfo.setProjectsInputInfo(main); buildInfo.setExecutions(createExecutions()); @@ -84,7 +84,7 @@ public void name() throws Exception { file.deleteOnExit(); Files.write(tempFilePath, bytes); - BuildInfo buildInfo1 = xmlService.fromFile(BuildInfo.class, file); + org.apache.maven.caching.xml.build.Build buildInfo1 = xmlService.loadBuild(file); System.out.println(buildInfo1); } diff --git a/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java b/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java index 0a4a913824c0..9415d10ab58f 100644 --- a/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java @@ -19,8 +19,8 @@ * under the License. */ -import org.apache.maven.caching.xml.buildinfo.BuildInfo; -import org.apache.maven.caching.xml.buildsdiff.BuildDiff; +import org.apache.maven.caching.xml.build.Build; +import org.apache.maven.caching.xml.diff.Diff; import org.apache.maven.caching.xml.config.CacheConfig; import org.apache.maven.caching.xml.report.CacheReport; import org.junit.Test; @@ -48,7 +48,7 @@ public void testConfig() throws Exception { Document doc = db.parse( getClass().getResource( "cache-config-instance.xml" ).toString() ); InputStream is = getClass().getResourceAsStream( "cache-config-instance.xml" ); - final CacheConfig cache = new XmlService().fromInputStream( CacheConfig.class, is ); + final CacheConfig cache = new XmlService().loadCacheConfig( is ); } @Test @@ -62,34 +62,34 @@ public void testReport() throws Exception { Document doc = db.parse( getClass().getResource( "cache-report-instance.xml" ).toString() ); InputStream is = getClass().getResourceAsStream( "cache-report-instance.xml" ); - final CacheReport cacheReport = new XmlService().fromInputStream( CacheReport.class, is ); + final CacheReport cacheReport = new XmlService().loadCacheReport( is ); } @Test - public void testBuildInfo() throws Exception { + public void testBuild() throws Exception { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - Schema schema = sf.newSchema(getClass().getResource("/cache-buildinfo-1.0.0.xsd")); + Schema schema = sf.newSchema(getClass().getResource("/cache-build-1.0.0.xsd")); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setSchema(schema); DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse( getClass().getResource( "cache-buildinfo-instance.xml" ).toString() ); + Document doc = db.parse( getClass().getResource( "cache-build-instance.xml" ).toString() ); - InputStream is = getClass().getResourceAsStream( "cache-buildinfo-instance.xml" ); - final BuildInfo buildInfo = new XmlService().fromInputStream( BuildInfo.class, is ); + InputStream is = getClass().getResourceAsStream( "cache-build-instance.xml" ); + final Build build = new XmlService().loadBuild( is ); } @Test - public void testBuildsDiff() throws Exception { + public void testDiff() throws Exception { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - Schema schema = sf.newSchema(getClass().getResource("/cache-buildsdiff-1.0.0.xsd")); + Schema schema = sf.newSchema(getClass().getResource("/cache-diff-1.0.0.xsd")); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setSchema(schema); DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse( getClass().getResource( "cache-buildsdiff-instance.xml" ).toString() ); + Document doc = db.parse( getClass().getResource( "cache-diff-instance.xml" ).toString() ); - InputStream is = getClass().getResourceAsStream( "cache-buildsdiff-instance.xml" ); - final BuildDiff buildDiff = new XmlService().fromInputStream( BuildDiff.class, is ); + InputStream is = getClass().getResourceAsStream( "cache-diff-instance.xml" ); + final Diff buildDiff = new XmlService().loadDiff( is ); } } \ No newline at end of file diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildinfo-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-build-instance.xml similarity index 91% rename from maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildinfo-instance.xml rename to maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-build-instance.xml index 94c129ded569..c80e922425e9 100644 --- a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildinfo-instance.xml +++ b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-build-instance.xml @@ -19,9 +19,9 @@ specific language governing permissions and limitations under the License. --> - + xsi:schemaLocation="http://maven.apache.org/CACHE-BUILD/1.0.0 ../../../../../../../../target/generated-sources/modello/cache-build-1.0.0.xsd"> v3 1980-03-23T10:20:15.000 my-server.com diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildsdiff-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-diff-instance.xml similarity index 80% rename from maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildsdiff-instance.xml rename to maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-diff-instance.xml index af43d3d25806..e549ef940756 100644 --- a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-buildsdiff-instance.xml +++ b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-diff-instance.xml @@ -19,13 +19,13 @@ specific language governing permissions and limitations under the License. --> - + xsi:schemaLocation="http://maven.apache.org/CACHE-DIFF/1.0.0 ../../../../../../../../target/generated-sources/modello/cache-diff-1.0.0.xsd"> - + From b80d035c99a9173075433e7114b97582b3672aa0 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 10 Nov 2021 13:23:00 +0100 Subject: [PATCH 118/188] [MNG-7327] Avoid guava usage --- .../apache/maven/caching/CacheContext.java | 8 +- .../maven/caching/CacheControllerImpl.java | 38 ++-- .../org/apache/maven/caching/CacheDiff.java | 81 ++++---- .../maven/caching/HttpRepositoryImpl.java | 58 +++--- .../caching/LocalArtifactsRepository.java | 8 +- .../maven/caching/LocalRepositoryImpl.java | 184 ++++++++---------- .../apache/maven/caching/ProjectUtils.java | 20 +- .../caching/RemoteArtifactsRepository.java | 6 +- .../java/org/apache/maven/caching/Utils.java | 87 +++++++++ .../caching/checksum/MavenProjectInput.java | 71 +++---- .../apache/maven/caching/hash/HexUtils.java | 63 ++++-- .../org/apache/maven/caching/hash/XX.java | 7 +- .../org/apache/maven/caching/hash/XXMM.java | 3 +- .../org/apache/maven/caching/xml/Build.java | 4 +- .../maven/caching/xml/CacheConfigImpl.java | 23 +-- .../apache/maven/caching/BuildInfoTest.java | 6 +- .../maven/caching/hash/HexUtilsTest.java | 20 +- 17 files changed, 383 insertions(+), 304 deletions(-) create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/Utils.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java index d34a78cc2069..81a2a318d166 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java @@ -23,7 +23,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; /** * CacheContext @@ -36,9 +36,9 @@ public class CacheContext public CacheContext( MavenProject project, ProjectsInputInfo inputInfo, MavenSession session ) { - this.project = checkNotNull( project ); - this.inputInfo = checkNotNull( inputInfo ); - this.session = checkNotNull( session ); + this.project = requireNonNull( project ); + this.inputInfo = requireNonNull( inputInfo ); + this.session = requireNonNull( session ); } public MavenProject getProject() diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index d6b6f4a7d3c3..8c0bdbe25fb3 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -34,7 +34,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Properties; +import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.TreeSet; import java.util.UUID; @@ -47,9 +48,6 @@ import javax.inject.Named; import javax.inject.Singleton; -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; @@ -70,9 +68,9 @@ import org.apache.maven.caching.xml.build.DigestItem; import org.apache.maven.caching.xml.build.ProjectsInputInfo; import org.apache.maven.caching.xml.build.Scm; -import org.apache.maven.caching.xml.diff.Diff; import org.apache.maven.caching.xml.config.PropertyName; import org.apache.maven.caching.xml.config.TrackedProperty; +import org.apache.maven.caching.xml.diff.Diff; import org.apache.maven.caching.xml.report.CacheReport; import org.apache.maven.caching.xml.report.ProjectReport; import org.apache.maven.execution.MavenSession; @@ -153,7 +151,7 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, List mojoExecutions ) { - final String highestRequestPhase = Iterables.getLast( mojoExecutions ).getLifecyclePhase(); + final String highestRequestPhase = Utils.getLast( mojoExecutions ).get().getLifecyclePhase(); if ( !ProjectUtils.isLaterPhase( highestRequestPhase, "post-clean" ) ) { return empty(); @@ -255,7 +253,7 @@ private CacheResult analyzeResult( CacheContext context, List moj return failure( info, context ); } - final String highestRequestPhase = Iterables.getLast( mojoExecutions ).getLifecyclePhase(); + final String highestRequestPhase = Utils.getLast( mojoExecutions ).get().getLifecyclePhase(); final String highestCompletedGoal = info.getHighestCompletedGoal(); if ( ProjectUtils.isLaterPhase( highestRequestPhase, highestCompletedGoal ) && !canIgnoreMissingSegment( info, mojoExecutions ) ) @@ -722,27 +720,24 @@ private void logError( MavenProject project, String message, Exception e ) @Override public boolean isForcedExecution( MavenProject project, MojoExecution execution ) { - if ( cacheConfig.isForcedExecution( execution ) ) { return true; } - final Properties properties = project.getProperties(); - final String alwaysRunPlugins = properties.getProperty( "remote.cache.alwaysRunPlugins" ); - ArrayList alwaysRunPluginsList = new ArrayList<>(); + String alwaysRunPlugins = project.getProperties().getProperty( "remote.cache.alwaysRunPlugins" ); if ( alwaysRunPlugins != null ) { - alwaysRunPluginsList = Lists.newArrayList( split( alwaysRunPlugins, "," ) ); - } - for ( String pluginAndGoal : alwaysRunPluginsList ) - { - final String[] tokens = pluginAndGoal.split( ":" ); - final String alwaysRunPlugin = tokens[0]; - String alwaysRunGoal = tokens.length == 1 ? "*" : tokens[1]; - if ( StringUtils.equals( execution.getPlugin().getArtifactId(), alwaysRunPlugin ) && ( "*".equals( - alwaysRunGoal ) || StringUtils.equals( execution.getGoal(), alwaysRunGoal ) ) ) + String[] alwaysRunPluginsList = split( alwaysRunPlugins, "," ); + for ( String pluginAndGoal : alwaysRunPluginsList ) { - return true; + String[] tokens = pluginAndGoal.split( ":" ); + String alwaysRunPlugin = tokens[0]; + String alwaysRunGoal = tokens.length == 1 ? "*" : tokens[1]; + if ( Objects.equals( execution.getPlugin().getArtifactId(), alwaysRunPlugin ) + && ( "*".equals( alwaysRunGoal ) || Objects.equals( execution.getGoal(), alwaysRunGoal ) ) ) + { + return true; + } } } return false; @@ -813,7 +808,6 @@ private void populateGitInfo( Build build, MavenSession session ) throws IOExcep private void zipAndAttachArtifact( MavenProject project, Path dir, String classifier ) throws IOException { - try ( InputStream inputStream = ZipUtils.zipFolder( dir ) ) { File tempFile = File.createTempFile( "maven-incremental", project.getArtifactId() ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java index 82be28f56d8e..550b546f5759 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java @@ -19,8 +19,6 @@ * under the License. */ -import com.google.common.base.Optional; -import com.google.common.collect.Sets; import org.apache.commons.lang3.StringUtils; import org.apache.maven.caching.xml.build.Build; import org.apache.maven.caching.xml.build.CompletedExecution; @@ -36,6 +34,10 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; /** * Utility class for comparing 2 builds @@ -82,10 +84,10 @@ public Diff compare() private void compareEffectivePoms( ProjectsInputInfo current, ProjectsInputInfo baseline ) { Optional currentPom = findPom( current ); - String currentPomHash = currentPom.isPresent() ? currentPom.get().getHash() : null; + String currentPomHash = currentPom.map( DigestItem::getHash ).orElse( null ); Optional baseLinePom = findPom( baseline ); - String baselinePomHash = baseLinePom.isPresent() ? baseLinePom.get().getHash() : null; + String baselinePomHash = baseLinePom.map( DigestItem::getHash ).orElse( null ); if ( !StringUtils.equals( currentPomHash, baselinePomHash ) ) { @@ -108,35 +110,25 @@ public static Optional findPom( ProjectsInputInfo projectInputs ) } } - return Optional.absent(); + return Optional.empty(); } private void compareFiles( ProjectsInputInfo current, ProjectsInputInfo baseline ) { - final Map currentFiles = new HashMap<>(); - for ( DigestItem item : current.getItems() ) - { - if ( "file".equals( item.getType() ) ) - { - currentFiles.put( item.getValue(), item ); - } - } - - final Map baselineFiles = new HashMap<>(); - for ( DigestItem item : baseline.getItems() ) - { - if ( "file".equals( item.getType() ) ) - { - baselineFiles.put( item.getValue(), item ); - } - } + final Map currentFiles = current.getItems().stream() + .filter( item -> "file".equals( item.getType() ) ) + .collect( Collectors.toMap( DigestItem::getValue, item -> item ) ); - final Sets.SetView currentVsBaseline = Sets.difference( currentFiles.keySet(), baselineFiles.keySet() ); - final Sets.SetView baselineVsCurrent = Sets.difference( baselineFiles.keySet(), currentFiles.keySet() ); + final Map baselineFiles = baseline.getItems().stream() + .filter( item -> "file".equals( item.getType() ) ) + .collect( Collectors.toMap( DigestItem::getValue, item -> item ) ); - if ( !currentVsBaseline.isEmpty() || !baselineVsCurrent.isEmpty() ) + if ( !Objects.equals( currentFiles.keySet(), baselineFiles.keySet() ) ) { + Set currentVsBaseline = diff( currentFiles.keySet(), baselineFiles.keySet() ); + Set baselineVsCurrent = diff( baselineFiles.keySet(), currentFiles.keySet() ); + addNewMismatch( "source files", "Remote and local cache contain different sets of input files. " + "Added files: " + currentVsBaseline + ". Removed files: " + baselineVsCurrent, @@ -180,30 +172,19 @@ private void compareFiles( ProjectsInputInfo current, ProjectsInputInfo baseline private void compareDependencies( ProjectsInputInfo current, ProjectsInputInfo baseline ) { - final Map currentDependencies = new HashMap<>(); - for ( DigestItem digestItemType : current.getItems() ) - { - if ( "dependency".equals( digestItemType.getType() ) ) - { - currentDependencies.put( digestItemType.getValue(), digestItemType ); - } - } - final Map baselineDependencies = new HashMap<>(); - for ( DigestItem item : baseline.getItems() ) - { - if ( "dependency".equals( item.getType() ) ) - { - baselineDependencies.put( item.getValue(), item ); - } - } + final Map currentDependencies = current.getItems().stream() + .filter( item -> "dependency".equals( item.getType() ) ) + .collect( Collectors.toMap( DigestItem::getValue, item -> item ) ); - final Sets.SetView currentVsBaseline = - Sets.difference( currentDependencies.keySet(), baselineDependencies.keySet() ); - final Sets.SetView baselineVsCurrent = - Sets.difference( baselineDependencies.keySet(), currentDependencies.keySet() ); + final Map baselineDependencies = baseline.getItems().stream() + .filter( item -> "dependency".equals( item.getType() ) ) + .collect( Collectors.toMap( DigestItem::getValue, item -> item ) ); - if ( !currentVsBaseline.isEmpty() || !baselineVsCurrent.isEmpty() ) + if ( !Objects.equals( currentDependencies.keySet(), baselineDependencies.keySet() ) ) { + Set currentVsBaseline = diff( currentDependencies.keySet(), baselineDependencies.keySet() ); + Set baselineVsCurrent = diff( baselineDependencies.keySet(), currentDependencies.keySet() ); + addNewMismatch( "dependencies files", "Remote and local builds contain different sets of dependencies and cannot be matched. " + "Added dependencies: " + currentVsBaseline + ". Removed dependencies: " @@ -342,4 +323,12 @@ private void addNewMismatch( String property, String reason, String resolution ) mismatchType.setResolution( resolution ); report.add( mismatchType ); } + + private static Set diff( Set a, Set b ) + { + return a.stream() + .filter( v -> !b.contains( v ) ) + .collect( Collectors.toSet() ); + + } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java index 501bd38728b3..8cf57ee8bbcc 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java @@ -24,15 +24,13 @@ import java.io.InputStream; import java.nio.file.Files; import java.util.List; +import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import com.google.common.base.Optional; -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -41,6 +39,7 @@ import org.apache.http.client.methods.HttpHead; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.InputStreamEntity; +import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.xml.Build; @@ -78,19 +77,21 @@ public class HttpRepositoryImpl implements RemoteArtifactsRepository @Inject private CacheConfig cacheConfig; - @SuppressWarnings( {"checkstyle:constantname", "checkstyle:magicnumber"} ) - private static final ThreadLocal httpClient = new ThreadLocal() + @SuppressWarnings( "checkstyle:constantname" ) + private static final ThreadLocal httpClient = + ThreadLocal.withInitial( HttpRepositoryImpl::newHttpClient ); + + @SuppressWarnings( "checkstyle:magicnumber" ) + private static CloseableHttpClient newHttpClient() { - @Override - protected HttpClient initialValue() - { - int timeoutSeconds = 60; - RequestConfig config = RequestConfig.custom().setConnectTimeout( - timeoutSeconds * 1000 ).setConnectionRequestTimeout( timeoutSeconds * 1000 ).setSocketTimeout( - timeoutSeconds * 1000 ).build(); - return HttpClientBuilder.create().setDefaultRequestConfig( config ).build(); - } - }; + int timeoutSeconds = 60; + RequestConfig config = RequestConfig.custom() + .setConnectTimeout( timeoutSeconds * 1000 ) + .setConnectionRequestTimeout( timeoutSeconds * 1000 ) + .setSocketTimeout( timeoutSeconds * 1000 ) + .build(); + return HttpClientBuilder.create().setDefaultRequestConfig( config ).build(); + } @Override public Build findBuild( CacheContext context ) @@ -244,19 +245,19 @@ private void putToRemoteCache( InputStream instream, String url, String logRefer } } - private final AtomicReference>> cacheReportSupplier = new AtomicReference<>(); + private final AtomicReference> cacheReportSupplier = new AtomicReference<>(); @Override public Optional findBaselineBuild( MavenProject project ) { final Optional> cachedProjectsHolder = findCacheInfo() - .transform( CacheReport::getProjects ); + .map( CacheReport::getProjects ); if ( !cachedProjectsHolder.isPresent() ) { - return Optional.absent(); + return Optional.empty(); } - Optional cachedProjectHolder = Optional.absent(); + Optional cachedProjectHolder = Optional.empty(); for ( ProjectReport p : cachedProjectsHolder.get() ) { if ( project.getArtifactId().equals( p.getArtifactId() ) && project.getGroupId().equals( @@ -301,16 +302,16 @@ public Optional findBaselineBuild( MavenProject project ) { logger.warn( "[CACHE][" + project.getArtifactId() + "] Error restoring baseline build at url: " + projectReport.getUrl() + ", skipping diff" ); - return Optional.absent(); + return Optional.empty(); } } - return Optional.absent(); + return Optional.empty(); } private Optional findCacheInfo() { - - Supplier> candidate = Suppliers.memoize( () -> + Optional report = cacheReportSupplier.get(); + if ( report == null ) { try { @@ -318,18 +319,17 @@ private Optional findCacheInfo() "DEBUG" ); byte[] content = getResourceContent( cacheConfig.getBaselineCacheUrl(), "cache-info" ); CacheReport cacheReportType = xmlService.loadCacheReport( content ); - return Optional.of( cacheReportType ); + report = Optional.of( cacheReportType ); } catch ( Exception e ) { logger.error( "Error downloading baseline report from: " + cacheConfig.getBaselineCacheUrl() + ", skipping diff.", e ); - return Optional.absent(); + report = Optional.empty(); } - } ); - cacheReportSupplier.compareAndSet( null, candidate ); - - return cacheReportSupplier.get().get(); + cacheReportSupplier.compareAndSet( null, report ); + } + return report; } private void logInfo( String message, String logReference ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java index 7a0530d1cafa..772846722f3d 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java @@ -19,16 +19,16 @@ * under the License. */ -import com.google.common.base.Optional; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Optional; + import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheSource; import org.apache.maven.caching.xml.build.Artifact; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; -import java.io.IOException; -import java.nio.file.Path; - /** * LocalArtifactsRepository */ diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java index 36284dd3fcd0..b7da9cddb726 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java @@ -28,28 +28,23 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.StandardCopyOption; import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.FileTime; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; -import com.google.common.collect.Ordering; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.tuple.Pair; +import org.apache.maven.caching.Utils.MultiMap; import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; @@ -87,9 +82,6 @@ public class LocalRepositoryImpl implements LocalArtifactsRepository private static final long ONE_MINUTE_MILLIS = MINUTES.toMillis( 1 ); private static final long ONE_DAY_MILLIS = DAYS.toMillis( 1 ); private static final String EMPTY = ""; - private static final LastModifiedComparator LAST_MODIFIED_COMPARATOR = new LastModifiedComparator(); - private static final Function, Long> GET_LAST_MODIFIED = - pair -> pair.getRight().lastModified(); @Inject private Logger logger; @@ -106,25 +98,7 @@ public class LocalRepositoryImpl implements LocalArtifactsRepository @Inject private CacheConfig cacheConfig; - private final LoadingCache, - Optional> bestBuildCache = - CacheBuilder.newBuilder().build( CacheLoader.from( new Function, - Optional>() - { - @Override - public Optional apply( Pair input ) - { - try - { - return findBestMatchingBuildImpl( input ); - } - catch ( IOException e ) - { - logger.error( "Cannot find dependency in cache", e ); - return Optional.absent(); - } - } - } ) ); + private final Map, Optional> bestBuildCache = new ConcurrentHashMap<>(); @Override public Build findLocalBuild( CacheContext context ) throws IOException @@ -177,7 +151,6 @@ public Build findBuild( CacheContext context ) throws IOException try { - Path lookupInfoPath = remoteBuildPath( context, LOOKUPINFO_XML ); if ( Files.exists( lookupInfoPath ) ) { @@ -248,7 +221,7 @@ public void clearCache( CacheContext context ) int maxLocalBuildsCached = cacheConfig.getMaxLocalBuildsCached() - 1; if ( cacheDirs.size() > maxLocalBuildsCached ) { - Collections.sort( cacheDirs, LAST_MODIFIED_COMPARATOR ); + cacheDirs.sort( Comparator.comparing( LocalRepositoryImpl::lastModifiedTime ) ); for ( Path dir : cacheDirs.subList( 0, cacheDirs.size() - maxLocalBuildsCached ) ) { FileUtils.deleteDirectory( dir.toFile() ); @@ -273,88 +246,94 @@ public void clearCache( CacheContext context ) public Optional findBestMatchingBuild( MavenSession session, Dependency dependency ) { - return bestBuildCache.getUnchecked( Pair.of( session, dependency ) ); + return bestBuildCache.computeIfAbsent( Pair.of( session, dependency ), this::findBestMatchingBuildImpl ); } - private Optional findBestMatchingBuildImpl( Pair dependencySession ) - throws IOException { - final MavenSession session = dependencySession.getLeft(); - final Dependency dependency = dependencySession.getRight(); + try + { + final MavenSession session = dependencySession.getLeft(); + final Dependency dependency = dependencySession.getRight(); - final Path artifactCacheDir = artifactCacheDir( session, dependency.getGroupId(), dependency.getArtifactId() ); + final Path artifactCacheDir = + artifactCacheDir( session, dependency.getGroupId(), dependency.getArtifactId() ); - final Multimap, Pair> - filesByVersion = ArrayListMultimap.create(); + final MultiMap, Pair> filesByVersion = new MultiMap<>(); - Files.walkFileTree( artifactCacheDir, new SimpleFileVisitor() - { - @Override - public FileVisitResult visitFile( Path o, BasicFileAttributes basicFileAttributes ) + Files.walkFileTree( artifactCacheDir, new SimpleFileVisitor() { - final File file = o.toFile(); - if ( file.getName().equals( BUILDINFO_XML ) ) + @Override + public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttributes ) { - try + final File file = path.toFile(); + if ( file.getName().equals( BUILDINFO_XML ) ) { - final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( file ); - final Pair buildInfoAndFile = - Pair.of( new Build( dto, CacheSource.LOCAL ), file ); - final String cachedVersion = dto.getArtifact().getVersion(); - final String cachedBranch = getScmRef( dto.getScm() ); - filesByVersion.put( Pair.of( cachedVersion, cachedBranch ), buildInfoAndFile ); - if ( isNotBlank( cachedBranch ) ) + try { - filesByVersion.put( Pair.of( EMPTY, cachedBranch ), buildInfoAndFile ); + final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( file ); + final Pair buildInfoAndFile = + Pair.of( new Build( dto, CacheSource.LOCAL ), path ); + final String cachedVersion = dto.getArtifact().getVersion(); + final String cachedBranch = getScmRef( dto.getScm() ); + filesByVersion.add( Pair.of( cachedVersion, cachedBranch ), buildInfoAndFile ); + if ( isNotBlank( cachedBranch ) ) + { + filesByVersion.add( Pair.of( EMPTY, cachedBranch ), buildInfoAndFile ); + } + if ( isNotBlank( cachedVersion ) ) + { + filesByVersion.add( Pair.of( cachedVersion, EMPTY ), buildInfoAndFile ); + } } - if ( isNotBlank( cachedVersion ) ) + catch ( Exception e ) { - filesByVersion.put( Pair.of( cachedVersion, EMPTY ), buildInfoAndFile ); + // version is unusable nothing we can do here + logger.error( "Build info is not compatible to current maven implementation: " + file ); } } - catch ( Exception e ) - { - // version is unusable nothing we can do here - logger.error( "Build info is not compatible to current maven implementation: " + file ); - } + return FileVisitResult.CONTINUE; } - return FileVisitResult.CONTINUE; + } ); + + if ( filesByVersion.isEmpty() ) + { + return Optional.empty(); } - } ); - if ( filesByVersion.isEmpty() ) - { - return Optional.absent(); - } + final String currentRef = getScmRef( ProjectUtils.readGitInfo( session ) ); + // first lets try by branch and version + Collection> bestMatched = new LinkedList<>(); + if ( isNotBlank( currentRef ) ) + { + bestMatched = filesByVersion.get( Pair.of( dependency.getVersion(), currentRef ) ); + } + if ( bestMatched.isEmpty() ) + { + // then by version + bestMatched = filesByVersion.get( Pair.of( dependency.getVersion(), EMPTY ) ); + } + if ( bestMatched.isEmpty() && isNotBlank( currentRef ) ) + { + // then by branch + bestMatched = filesByVersion.get( Pair.of( EMPTY, currentRef ) ); + } + if ( bestMatched.isEmpty() ) + { + // ok lets take all + bestMatched = filesByVersion.allValues(); + } - final String currentRef = getScmRef( ProjectUtils.readGitInfo( session ) ); - // first lets try by branch and version - Collection> bestMatched = new LinkedList<>(); - if ( isNotBlank( currentRef ) ) - { - bestMatched = filesByVersion.get( Pair.of( dependency.getVersion(), currentRef ) ); - } - if ( Iterables.isEmpty( bestMatched ) ) - { - // then by version - bestMatched = filesByVersion.get( Pair.of( dependency.getVersion(), EMPTY ) ); + return bestMatched.stream() + .max( Comparator.comparing( p -> lastModifiedTime( p.getRight() ) ) ) + .map( Pair::getLeft ); } - if ( Iterables.isEmpty( bestMatched ) && isNotBlank( currentRef ) ) - { - // then by branch - bestMatched = filesByVersion.get( Pair.of( EMPTY, currentRef ) ); - } - if ( Iterables.isEmpty( bestMatched ) ) + catch ( IOException e ) { - // ok lets take all - bestMatched = filesByVersion.values(); + logger.error( "Cannot find dependency in cache", e ); + return Optional.empty(); } - - List> orderedFiles = Ordering.natural().onResultOf( - GET_LAST_MODIFIED ).reverse().sortedCopy( bestMatched ); - return Optional.of( orderedFiles.get( 0 ).getLeft() ); } private String getScmRef( Scm scm ) @@ -487,19 +466,16 @@ private void logInfo( CacheContext context, String message ) logger.info( "[CACHE][" + context.getProject().getArtifactId() + "] " + message ); } - private static class LastModifiedComparator implements Comparator + private static FileTime lastModifiedTime( Path p ) { - @Override - public int compare( Path p1, Path p2 ) + try { - try - { - return Files.getLastModifiedTime( p1 ).compareTo( Files.getLastModifiedTime( p2 ) ); - } - catch ( IOException e ) - { - return 0; - } + return Files.getLastModifiedTime( p ); + } + catch ( IOException e ) + { + return FileTime.fromMillis( 0 ); } } + } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java index adb0147a3d9a..c8b5eeba5ffd 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java @@ -19,8 +19,6 @@ * under the License. */ -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; @@ -38,9 +36,9 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; import static org.apache.commons.lang3.StringUtils.removeStart; import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.maven.artifact.Artifact.LATEST_VERSION; @@ -52,7 +50,7 @@ public class ProjectUtils { - private static final List PHASES = Lists.newArrayList( + private static final List PHASES = Arrays.asList( //clean "pre-clean", "clean", "post-clean", // default @@ -71,8 +69,14 @@ public class ProjectUtils */ public static boolean isLaterPhase( String phase, String other ) { - checkArgument( PHASES.contains( phase ), "Unsupported phase: " + phase ); - checkArgument( PHASES.contains( other ), "Unsupported phase: " + other ); + if ( !PHASES.contains( phase ) ) + { + throw new IllegalArgumentException( "Unsupported phase: " + phase ); + } + if ( !PHASES.contains( other ) ) + { + throw new IllegalArgumentException( "Unsupported phase: " + other ); + } return PHASES.indexOf( phase ) > PHASES.indexOf( other ); } @@ -141,7 +145,7 @@ public static String normalizedName( Artifact artifact ) public static String mojoExecutionKey( MojoExecution mojo ) { - return StringUtils.join( Lists.newArrayList( StringUtils.defaultIfEmpty( mojo.getExecutionId(), "emptyExecId" ), + return StringUtils.join( Arrays.asList( StringUtils.defaultIfEmpty( mojo.getExecutionId(), "emptyExecId" ), StringUtils.defaultIfEmpty( mojo.getGoal(), "emptyGoal" ), StringUtils.defaultIfEmpty( mojo.getLifecyclePhase(), "emptyLifecyclePhase" ), StringUtils.defaultIfEmpty( mojo.getArtifactId(), "emptyArtifactId" ), @@ -189,7 +193,7 @@ public static Scm readGitInfo( MavenSession session ) throws IOException private static String readFirstLine( Path path, String defaultValue ) throws IOException { final List lines = Files.readAllLines( path, StandardCharsets.UTF_8 ); - return Iterables.getFirst( lines, defaultValue ); + return Utils.getFirst( lines ).orElse( defaultValue ); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java index ca4e215d2afb..9c4f8a1304ef 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java @@ -19,13 +19,13 @@ * under the License. */ -import com.google.common.base.Optional; +import java.io.IOException; +import java.util.Optional; + import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.build.Artifact; import org.apache.maven.project.MavenProject; -import java.io.IOException; - /** * RemoteArtifactsRepository */ diff --git a/maven-caching/src/main/java/org/apache/maven/caching/Utils.java b/maven-caching/src/main/java/org/apache/maven/caching/Utils.java new file mode 100644 index 000000000000..57cbd8f18946 --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/Utils.java @@ -0,0 +1,87 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +public class Utils +{ + + public static Optional getFirst( List list ) + { + int size = list.size(); + if ( size > 0 ) + { + return Optional.of( list.get( 0 ) ); + } + return Optional.empty(); + } + + public static Optional getLast( List list ) + { + int size = list.size(); + if ( size > 0 ) + { + return Optional.of( list.get( size - 1 ) ); + } + return Optional.empty(); + } + + public static T getOnlyElement( Collection col ) + { + Iterator iterator = col.iterator(); + T first = iterator.next(); + if ( iterator.hasNext() ) + { + StringBuilder sb = new StringBuilder().append( "expected one element but was: <" ).append( first ); + for ( int i = 0; i < 4 && iterator.hasNext(); i++ ) + { + sb.append( ", " ).append( iterator.next() ); + } + if ( iterator.hasNext() ) + { + sb.append( ", ..." ); + } + sb.append( '>' ); + throw new IllegalArgumentException( sb.toString() ); + } + return first; + } + + public static class MultiMap extends HashMap> + { + public void add( K key, V value ) + { + super.computeIfAbsent( key, k -> new ArrayList<>() ).add( value ); + } + + public Collection allValues() + { + return values().stream().flatMap( Collection::stream ).collect( Collectors.toList() ); + } + } + +} \ No newline at end of file diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 69c79d586ba2..54c45a4ac1e9 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -19,8 +19,35 @@ * under the License. */ -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.nio.file.DirectoryStream; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Properties; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.concurrent.ConcurrentMap; + +import javax.annotation.Nonnull; + import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; @@ -32,9 +59,10 @@ import org.apache.maven.caching.ProjectUtils; import org.apache.maven.caching.RemoteArtifactsRepository; import org.apache.maven.caching.ScanConfigProperties; -import org.apache.maven.caching.hash.HashFactory; +import org.apache.maven.caching.Utils; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashChecksum; +import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; @@ -58,33 +86,6 @@ import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.xml.Xpp3Dom; -import javax.annotation.Nonnull; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.nio.file.DirectoryStream; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.SortedMap; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.concurrent.ConcurrentMap; - import static org.apache.commons.lang3.StringUtils.contains; import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; import static org.apache.commons.lang3.StringUtils.equalsAnyIgnoreCase; @@ -212,11 +213,11 @@ public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOE final List items = new ArrayList<>( count ); final HashChecksum checksum = hashFactory.createChecksum( count ); - Optional baselineHolder = Optional.absent(); + Optional baselineHolder = Optional.empty(); if ( config.isBaselineDiffEnabled() ) { baselineHolder = - remoteCache.findBaselineBuild( project ).transform( b -> b.getDto().getProjectsInputInfo() ); + remoteCache.findBaselineBuild( project ).map( b -> b.getDto().getProjectsInputInfo() ); } DigestItem effectivePomChecksum = DigestUtils.pom( checksum, effectivePom ); @@ -281,7 +282,7 @@ public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOE private void checkEffectivePomMatch( ProjectsInputInfo baselineBuild, DigestItem effectivePomChecksum ) { - Optional pomHolder = Optional.absent(); + Optional pomHolder = Optional.empty(); for ( DigestItem it : baselineBuild.getItems() ) { if ( it.getType().equals( "pom" ) ) @@ -307,7 +308,7 @@ private void checkEffectivePomMatch( ProjectsInputInfo baselineBuild, DigestItem private boolean checkItemMatchesBaseline( ProjectsInputInfo baselineBuild, DigestItem fileDigest ) { - Optional baselineFileDigest = Optional.absent(); + Optional baselineFileDigest = Optional.empty(); for ( DigestItem it : baselineBuild.getItems() ) { if ( it.getType().equals( fileDigest.getType() ) @@ -854,7 +855,7 @@ private DigestItem resolveArtifact( final Artifact dependencyArtifact, + ", expected: 1, actual: " + result.getArtifacts() ); } - final Artifact resolved = Iterables.getOnlyElement( result.getArtifacts() ); + final Artifact resolved = Utils.getOnlyElement( result.getArtifacts() ); final HashAlgorithm algorithm = config.getHashFactory().createAlgorithm(); final String hash = algorithm.hash( resolved.getFile().toPath() ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/HexUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/HexUtils.java index f85d0f9c515c..bff46df7cdf0 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/HexUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/hash/HexUtils.java @@ -19,38 +19,71 @@ * under the License. */ -import com.google.common.base.CharMatcher; -import com.google.common.io.BaseEncoding; +import java.nio.charset.StandardCharsets; /** * HexUtils */ +@SuppressWarnings( "checkstyle:MagicNumber" ) public class HexUtils { - private static final BaseEncoding ENCODING = BaseEncoding.base16().lowerCase(); - private static final CharMatcher MATCHER = CharMatcher.is( '0' ); + private static final byte[] ENC_ARRAY; + private static final byte[] DEC_ARRAY; - public static String encode( byte[] hash ) + static { - return trimLeadingZero( ENCODING.encode( hash ) ); + ENC_ARRAY = new byte[16]; + DEC_ARRAY = new byte[256]; + for ( byte i = 0; i < 10; i++ ) + { + ENC_ARRAY[i] = ( byte ) ( '0' + i ); + DEC_ARRAY['0' + i] = i; + } + for ( byte i = 10; i < 16; i++ ) + { + ENC_ARRAY[i] = ( byte ) ( 'a' + i - 10 ); + DEC_ARRAY['a' + i - 10] = i; + DEC_ARRAY['A' + i - 10] = i; + } } - public static byte[] decode( String hex ) + public static String encode( byte[] hash ) { - return ENCODING.decode( padLeadingZero( hex ) ); + byte[] hexChars = new byte[hash.length * 2]; + for ( int j = 0; j < hash.length; j++ ) + { + int v = hash[j] & 0xFF; + hexChars[j * 2] = ENC_ARRAY[v >>> 4]; + hexChars[j * 2 + 1] = ENC_ARRAY[v & 0x0F]; + } + return new String( hexChars, StandardCharsets.US_ASCII ); } - private static String trimLeadingZero( String hex ) + public static byte[] decode( String hex ) { - String value = MATCHER.trimLeadingFrom( hex ); - return value.isEmpty() ? "0" : value; + int size = hex.length(); + if ( size % 2 != 0 ) + { + throw new IllegalArgumentException( "String length should be even" ); + } + byte[] bytes = new byte[ size / 2 ]; + int idx = 0; + for ( int i = 0; i < size; i += 2 ) + { + bytes[idx++] = ( byte ) ( DEC_ARRAY[hex.charAt( i )] << 4 | DEC_ARRAY[hex.charAt( i + 1 )] ); + } + return bytes; } - private static String padLeadingZero( String hex ) + public static byte[] toByteArray( long value ) { - String value = hex.toLowerCase(); - return value.length() % 2 == 0 ? value : "0" + value; + byte[] result = new byte[8]; + for ( int i = 7; i >= 0; i-- ) + { + result[i] = ( byte ) ( value & 0xFF ); + value >>= 8; + } + return result; } - } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/XX.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/XX.java index 24f9f4bff5e7..8ee08ce443d5 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/XX.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/hash/XX.java @@ -26,8 +26,6 @@ import java.nio.file.Files; import java.nio.file.Path; -import static com.google.common.primitives.Longs.toByteArray; - /** * XX */ @@ -64,7 +62,7 @@ static class Algorithm implements Hash.Algorithm @Override public byte[] hash( byte[] array ) { - return toByteArray( INSTANCE.hashBytes( array ) ); + return HexUtils.toByteArray( INSTANCE.hashBytes( array ) ); } @Override @@ -92,7 +90,8 @@ public void update( byte[] hash ) @Override public byte[] digest() { - return toByteArray( INSTANCE.hashBytes( buffer, 0, buffer.position() ) ); + return HexUtils.toByteArray( INSTANCE.hashBytes( buffer, 0, buffer.position() ) ); } } + } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/XXMM.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/XXMM.java index 7afe2403ffbe..1ca8bac95f63 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/XXMM.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/hash/XXMM.java @@ -23,7 +23,6 @@ import java.nio.channels.FileChannel; import java.nio.file.Path; -import static com.google.common.primitives.Longs.toByteArray; import static java.nio.channels.FileChannel.MapMode.READ_ONLY; import static java.nio.file.StandardOpenOption.READ; @@ -60,7 +59,7 @@ public byte[] hash( Path path ) throws IOException try ( FileChannel channel = FileChannel.open( path, READ ); CloseableBuffer buffer = CloseableBuffer.mappedBuffer( channel, READ_ONLY ) ) { - return toByteArray( XX.INSTANCE.hashBytes( buffer.getBuffer() ) ); + return HexUtils.toByteArray( XX.INSTANCE.hashBytes( buffer.getBuffer() ) ); } } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java index 72a5021fc1e5..5cbf4e75cd86 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java @@ -19,8 +19,8 @@ * under the License. */ -import com.google.common.collect.Iterables; import org.apache.maven.caching.ProjectUtils; +import org.apache.maven.caching.Utils; import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.xml.build.Artifact; @@ -188,7 +188,7 @@ public org.apache.maven.caching.xml.build.Build getDto() public String getHighestCompletedGoal() { - return Iterables.getLast( dto.getGoals() ); + return Utils.getLast( dto.getGoals() ).get(); } public List getCachedSegment( List mojoExecutions ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 71be02ef36a2..96a20e4db44b 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -32,8 +32,6 @@ import javax.inject.Named; import javax.inject.Singleton; -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; import org.apache.commons.lang3.StringUtils; import org.apache.maven.caching.DefaultPluginScanConfig; import org.apache.maven.caching.PluginScanConfig; @@ -66,7 +64,6 @@ import org.apache.maven.project.MavenProject; import org.codehaus.plexus.logging.Logger; -import static com.google.common.base.Preconditions.checkState; import static java.lang.Boolean.TRUE; import static java.lang.Boolean.parseBoolean; import static org.apache.maven.caching.ProjectUtils.getMultimoduleRoot; @@ -98,14 +95,7 @@ public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig private MavenSession session; private MavenProject project; - private final Supplier> excludePatterns = Suppliers.memoize( new Supplier>() - { - @Override - public List get() - { - return compileExcludePatterns(); - } - } ); + private List excludePatterns; @Override @@ -543,7 +533,11 @@ public List getAttachedOutputs() public List getExcludePatterns() { checkInitializedState(); - return excludePatterns.get(); + if ( excludePatterns == null ) + { + excludePatterns = compileExcludePatterns(); + } + return excludePatterns; } private List compileExcludePatterns() @@ -577,7 +571,10 @@ private Configuration getConfiguration() private void checkInitializedState() { - checkState( state == CacheState.INITIALIZED, "Cache is not initialized. Actual state: " + state ); + if ( state != CacheState.INITIALIZED ) + { + throw new IllegalStateException( "Cache is not initialized. Actual state: " + state ); + } } private String getProperty( String key, String defaultValue ) diff --git a/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java b/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java index a6a3ac29f4b5..4d75e80c4624 100644 --- a/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java @@ -27,10 +27,10 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; -import com.google.common.collect.Lists; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.caching.hash.HashFactory; @@ -71,9 +71,9 @@ public void name() throws Exception { buildInfo.setBuildTime(new Date()); buildInfo.setArtifact(artifact); buildInfo.setHashFunction("SHA-256"); - buildInfo.setGoals(Lists.newArrayList("install")); + buildInfo.setGoals(Collections.singletonList("install")); final org.apache.maven.artifact.Artifact attachedArtifact = new DefaultArtifact("ag", "aa", "av", "as", "at", "ac", new DefaultArtifactHandler()); - buildInfo.setAttachedArtifacts(Build.createAttachedArtifacts(Lists.newArrayList(attachedArtifact), HashFactory.XX.createAlgorithm())); + buildInfo.setAttachedArtifacts(Build.createAttachedArtifacts(Collections.singletonList(attachedArtifact), HashFactory.XX.createAlgorithm())); buildInfo.setProjectsInputInfo(main); buildInfo.setExecutions(createExecutions()); diff --git a/maven-caching/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java b/maven-caching/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java index 8f8290de2b62..8ddca35a0cde 100644 --- a/maven-caching/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java @@ -29,22 +29,22 @@ public class HexUtilsTest { @Test public void testEncodeToHex() { //array length = 8 left padded with zeroes - assertEquals("0", HexUtils.encode(new byte[8])); - assertEquals("0", HexUtils.encode(new byte[1])); + assertEquals("0000000000000000", HexUtils.encode(new byte[8])); + assertEquals("00", HexUtils.encode(new byte[1])); - assertEquals("a", HexUtils.encode(new byte[]{10})); - assertEquals("a", HexUtils.encode(new byte[]{0, 0, 0, 0, 0, 0, 0, 10})); + assertEquals("0a", HexUtils.encode(new byte[]{10})); + assertEquals("000000000000000a", HexUtils.encode(new byte[]{0, 0, 0, 0, 0, 0, 0, 10})); - assertEquals("100", HexUtils.encode(new byte[]{1, 0})); - assertEquals("101", HexUtils.encode(new byte[]{0, 0, 0, 0, 0, 0, 1, 1})); + assertEquals("0100", HexUtils.encode(new byte[]{1, 0})); + assertEquals("0000000000000101", HexUtils.encode(new byte[]{0, 0, 0, 0, 0, 0, 1, 1})); } @Test public void testDecodeHex() { - assertArrayEquals(new byte[]{0}, HexUtils.decode("0")); - assertArrayEquals(new byte[]{10}, HexUtils.decode("a")); - assertArrayEquals(new byte[]{10}, HexUtils.decode("A")); - assertArrayEquals(new byte[]{1, 0}, HexUtils.decode("100")); + assertArrayEquals(new byte[]{0}, HexUtils.decode("00")); + assertArrayEquals(new byte[]{10}, HexUtils.decode("0a")); + assertArrayEquals(new byte[]{10}, HexUtils.decode("0A")); + assertArrayEquals(new byte[]{1, 0}, HexUtils.decode("0100")); } } \ No newline at end of file From 00322bf384614a3f68481bc317284d603323e4a4 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 10 Nov 2021 14:39:04 +0100 Subject: [PATCH 119/188] [MNG-5577] Use JSR 330 constructor injection --- .../maven/caching/CacheControllerImpl.java | 61 ++++++++++--------- .../apache/maven/caching/CacheEventSpy.java | 10 ++- .../maven/caching/CachingMojoExecutor.java | 49 +++++++-------- .../maven/caching/HttpRepositoryImpl.java | 21 ++++--- .../maven/caching/LocalRepositoryImpl.java | 33 +++++----- .../maven/caching/MojoParametersListener.java | 7 ++- .../maven/caching/xml/CacheConfigImpl.java | 13 ++-- 7 files changed, 109 insertions(+), 85 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 8c0bdbe25fb3..d20b810a4e33 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -112,39 +112,42 @@ public class CacheControllerImpl implements CacheController private static final String GENERATEDSOURCES = "generatedsources"; private static final String GENERATEDSOURCES_PREFIX = GENERATEDSOURCES + FILE_SEPARATOR_SUBST; - @Inject - private Logger logger; - - @Inject - private MavenPluginManager mavenPluginManager; - - @Inject - private MavenProjectHelper projectHelper; - - @Inject - private LocalArtifactsRepository localCache; - - @Inject - private RemoteArtifactsRepository remoteCache; - - @Inject - private CacheConfig cacheConfig; - - @Inject - private RepositorySystem repoSystem; - - @Inject - private ArtifactHandlerManager artifactHandlerManager; - - @Inject - private XmlService xmlService; - + private final Logger logger; + private final MavenPluginManager mavenPluginManager; + private final MavenProjectHelper projectHelper; + private final LocalArtifactsRepository localCache; + private final RemoteArtifactsRepository remoteCache; + private final CacheConfig cacheConfig; + private final RepositorySystem repoSystem; + private final ArtifactHandlerManager artifactHandlerManager; + private final XmlService xmlService; private final ConcurrentMap artifactDigestByKey = new ConcurrentHashMap<>(); - private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); - private volatile Scm scm; + @Inject + public CacheControllerImpl( + Logger logger, + MavenPluginManager mavenPluginManager, + MavenProjectHelper projectHelper, + LocalArtifactsRepository localCache, + RemoteArtifactsRepository remoteCache, + CacheConfig cacheConfig, + RepositorySystem repoSystem, + ArtifactHandlerManager artifactHandlerManager, + XmlService xmlService ) + { + this.logger = logger; + this.mavenPluginManager = mavenPluginManager; + this.projectHelper = projectHelper; + this.localCache = localCache; + this.remoteCache = remoteCache; + this.cacheConfig = cacheConfig; + this.repoSystem = repoSystem; + this.artifactHandlerManager = artifactHandlerManager; + this.xmlService = xmlService; + } + @Override @Nonnull public CacheResult findCachedBuild( MavenSession session, MavenProject project, ProjectIndex projectIndex, diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java index 39b83d6b70a3..cb5a80f08c34 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java @@ -34,11 +34,15 @@ @Named public class CacheEventSpy extends AbstractEventSpy { - @Inject - private CacheConfig cacheConfig; + private final CacheConfig cacheConfig; + private final CacheController cacheController; @Inject - private CacheController cacheController; + public CacheEventSpy( CacheConfig cacheConfig, CacheController cacheController ) + { + this.cacheConfig = cacheConfig; + this.cacheController = cacheController; + } @Override public void onEvent( Object event ) throws Exception diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java index 09f3253b19d9..53133568934f 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java @@ -83,33 +83,34 @@ @Priority( 10 ) public class CachingMojoExecutor implements IMojoExecutor { + private final Logger logger; + private final BuildPluginManager pluginManager; + private final MavenPluginManager mavenPluginManager; + private final LifecycleDependencyResolver lifeCycleDependencyResolver; + private final ExecutionEventCatapult eventCatapult; + private final CacheController cacheController; + private final CacheConfig cacheConfig; + private final MojoParametersListener mojoListener; @Inject - private Logger logger; - - @Inject - private BuildPluginManager pluginManager; - - @Inject - private MavenPluginManager mavenPluginManager; - - @Inject - private LifecycleDependencyResolver lifeCycleDependencyResolver; - - @Inject - private ExecutionEventCatapult eventCatapult; - - @Inject - private CacheController cacheController; - - @Inject - private CacheConfig cacheConfig; - - @Inject - private MojoParametersListener mojoListener; - - public CachingMojoExecutor() + public CachingMojoExecutor( + Logger logger, + BuildPluginManager pluginManager, + MavenPluginManager mavenPluginManager, + LifecycleDependencyResolver lifeCycleDependencyResolver, + ExecutionEventCatapult eventCatapult, + CacheController cacheController, + CacheConfig cacheConfig, + MojoParametersListener mojoListener ) { + this.logger = logger; + this.pluginManager = pluginManager; + this.mavenPluginManager = mavenPluginManager; + this.lifeCycleDependencyResolver = lifeCycleDependencyResolver; + this.eventCatapult = eventCatapult; + this.cacheController = cacheController; + this.cacheConfig = cacheConfig; + this.mojoListener = mojoListener; } public DependencyContext newDependencyContext( MavenSession session, List mojoExecutions ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java index 8cf57ee8bbcc..9cf169d1dc4c 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java @@ -65,17 +65,20 @@ public class HttpRepositoryImpl implements RemoteArtifactsRepository public static final String BUILDINFO_XML = "buildinfo.xml"; public static final String CACHE_REPORT_XML = "cache-report.xml"; - @Inject - private Logger logger; - - @Inject - LegacySupport legacySupport; + private final Logger logger; + private final LegacySupport legacySupport; + private final XmlService xmlService; + private final CacheConfig cacheConfig; @Inject - XmlService xmlService; - - @Inject - private CacheConfig cacheConfig; + public HttpRepositoryImpl( Logger logger, LegacySupport legacySupport, + XmlService xmlService, CacheConfig cacheConfig ) + { + this.logger = logger; + this.legacySupport = legacySupport; + this.xmlService = xmlService; + this.cacheConfig = cacheConfig; + } @SuppressWarnings( "checkstyle:constantname" ) private static final ThreadLocal httpClient = diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java index b7da9cddb726..c162e09115fe 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java @@ -83,22 +83,27 @@ public class LocalRepositoryImpl implements LocalArtifactsRepository private static final long ONE_DAY_MILLIS = DAYS.toMillis( 1 ); private static final String EMPTY = ""; - @Inject - private Logger logger; - - @Inject - private LegacySupport legacySupport; - - @Inject - private RemoteArtifactsRepository remoteRepository; - - @Inject - private XmlService xmlService; + private final Logger logger; + private final LegacySupport legacySupport; + private final RemoteArtifactsRepository remoteRepository; + private final XmlService xmlService; + private final CacheConfig cacheConfig; + private final Map, Optional> bestBuildCache = new ConcurrentHashMap<>(); @Inject - private CacheConfig cacheConfig; - - private final Map, Optional> bestBuildCache = new ConcurrentHashMap<>(); + public LocalRepositoryImpl( + Logger logger, + LegacySupport legacySupport, + RemoteArtifactsRepository remoteRepository, + XmlService xmlService, + CacheConfig cacheConfig ) + { + this.logger = logger; + this.legacySupport = legacySupport; + this.remoteRepository = remoteRepository; + this.xmlService = xmlService; + this.cacheConfig = cacheConfig; + } @Override public Build findLocalBuild( CacheContext context ) throws IOException diff --git a/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java index 78c81befdfdd..9f1de6d23d95 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java @@ -44,8 +44,13 @@ public class MojoParametersListener implements MojoExecutionListener private final ConcurrentMap> projectExecutions = new ConcurrentHashMap<>(); + private final Logger logger; + @Inject - private Logger logger; + public MojoParametersListener( Logger logger ) + { + this.logger = logger; + } @Override public void beforeMojoExecution( MojoExecutionEvent event ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 96a20e4db44b..c433117fac94 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -83,11 +83,8 @@ public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig public static final String FAIL_FAST_PROPERTY_NAME = "remote.cache.failFast"; public static final String BASELINE_BUILD_URL_PROPERTY_NAME = "remote.cache.baselineUrl"; - @Inject - private Logger logger; - - @Inject - private XmlService xmlService; + private final Logger logger; + private final XmlService xmlService; private volatile CacheState state = CacheState.NOT_INITIALIZED; private volatile CacheConfig cacheConfig; @@ -97,6 +94,12 @@ public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig private List excludePatterns; + @Inject + public CacheConfigImpl( Logger logger, XmlService xmlService ) + { + this.logger = logger; + this.xmlService = xmlService; + } @Override public synchronized CacheState initialize( MavenProject project, MavenSession session ) From 2463099e46f7f785b9ecffba7d1db830e887d966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 11 Nov 2021 17:11:34 +0100 Subject: [PATCH 120/188] [MNG-7321] cleanup build --- maven-caching/pom.xml | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/maven-caching/pom.xml b/maven-caching/pom.xml index 2641af6138ce..34a3397c7baa 100644 --- a/maven-caching/pom.xml +++ b/maven-caching/pom.xml @@ -69,37 +69,7 @@ under the License. - - - src/main/resources - true - - - - - - org.apache.rat - apache-rat-plugin - - - lifecycle-executor.txt - plugin-manager.txt - project-builder.txt - src/site/resources/design/** - - - - - - - org.codehaus.plexus - plexus-component-metadata - - - org.eclipse.sisu - sisu-maven-plugin - org.codehaus.modello modello-maven-plugin @@ -121,9 +91,6 @@ under the License. xpp3-reader xpp3-writer - - ${basedir}/target/generated-sources/modello - modello-cache-xsd @@ -132,7 +99,7 @@ under the License. xsd - ${basedir}/target/generated-resources/modello + ${basedir}/target/generated-test-resources/modello @@ -146,12 +113,12 @@ under the License. add-resources generate-resources - add-resource + add-test-resource - ${basedir}/target/generated-resources/modello + ${basedir}/target/generated-test-resources/modello From fe3463789821b299afa7308f59269135d5a05570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 11 Nov 2021 17:27:23 +0100 Subject: [PATCH 121/188] [MNG-7321] move documentation to maven-caching module --- README.md | 2 +- maven-caching/src/site/apt/index.apt | 30 +++++++++++ .../src/site/markdown}/CACHE-HOWTO.md | 0 .../src/site/markdown}/CACHE-PARAMETERS.md | 0 .../src/site/markdown}/CACHE-REMOTE.md | 0 .../src/site/markdown}/CACHE.md | 0 .../src/site/markdown}/maven-cache-config.xml | 0 maven-caching/src/site/site.xml | 53 +++++++++++++++++++ 8 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 maven-caching/src/site/apt/index.apt rename {Documentation => maven-caching/src/site/markdown}/CACHE-HOWTO.md (100%) rename {Documentation => maven-caching/src/site/markdown}/CACHE-PARAMETERS.md (100%) rename {Documentation => maven-caching/src/site/markdown}/CACHE-REMOTE.md (100%) rename {Documentation => maven-caching/src/site/markdown}/CACHE.md (100%) rename {Documentation => maven-caching/src/site/markdown}/maven-cache-config.xml (100%) create mode 100644 maven-caching/src/site/site.xml diff --git a/README.md b/README.md index a5a193bd63fa..03fe9c239330 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ If you think you have found a bug, please file an issue in the [Maven Issue Trac Incremental Build and Cache ------------- This maven version supports Incremental Build feature which calculates out-of-date modules in the build dependencies graph and improves build times by avoiding re-building unnecessary modules. -Read [cache guide](Documentation/CACHE.md) for more details +Read [cache guide](maven-caching/src/site/markdown/CACHE.md) for more details. Documentation ------------- diff --git a/maven-caching/src/site/apt/index.apt b/maven-caching/src/site/apt/index.apt new file mode 100644 index 000000000000..db29a8d8eeae --- /dev/null +++ b/maven-caching/src/site/apt/index.apt @@ -0,0 +1,30 @@ +~~ Licensed to the Apache Software Foundation (ASF) under one +~~ or more contributor license agreements. See the NOTICE file +~~ distributed with this work for additional information +~~ regarding copyright ownership. The ASF licenses this file +~~ to you under the Apache License, Version 2.0 (the +~~ "License"); you may not use this file except in compliance +~~ with the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, +~~ software distributed under the License is distributed on an +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +~~ KIND, either express or implied. See the License for the +~~ specific language governing permissions and limitations +~~ under the License. + + ----- + Introduction + ----- + Hervé Boutemy + ----- + 2021-11-11 + ----- + +Maven Caching + + Maven Incremental Build and Cache (local and remote). + + Read {{{./CACHE.html} more documentation}}. diff --git a/Documentation/CACHE-HOWTO.md b/maven-caching/src/site/markdown/CACHE-HOWTO.md similarity index 100% rename from Documentation/CACHE-HOWTO.md rename to maven-caching/src/site/markdown/CACHE-HOWTO.md diff --git a/Documentation/CACHE-PARAMETERS.md b/maven-caching/src/site/markdown/CACHE-PARAMETERS.md similarity index 100% rename from Documentation/CACHE-PARAMETERS.md rename to maven-caching/src/site/markdown/CACHE-PARAMETERS.md diff --git a/Documentation/CACHE-REMOTE.md b/maven-caching/src/site/markdown/CACHE-REMOTE.md similarity index 100% rename from Documentation/CACHE-REMOTE.md rename to maven-caching/src/site/markdown/CACHE-REMOTE.md diff --git a/Documentation/CACHE.md b/maven-caching/src/site/markdown/CACHE.md similarity index 100% rename from Documentation/CACHE.md rename to maven-caching/src/site/markdown/CACHE.md diff --git a/Documentation/maven-cache-config.xml b/maven-caching/src/site/markdown/maven-cache-config.xml similarity index 100% rename from Documentation/maven-cache-config.xml rename to maven-caching/src/site/markdown/maven-cache-config.xml diff --git a/maven-caching/src/site/site.xml b/maven-caching/src/site/site.xml new file mode 100644 index 000000000000..aa24fb501585 --- /dev/null +++ b/maven-caching/src/site/site.xml @@ -0,0 +1,53 @@ + + + + + + + ${project.scm.url} + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 0061bfe55242cd142158fe74d53dcf4fa9c42817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 11 Nov 2021 18:01:05 +0100 Subject: [PATCH 122/188] [MNG-7321] fix javadoc --- maven-caching/src/main/mdo/cache-build.mdo | 2 +- maven-caching/src/main/mdo/cache-config.mdo | 8 ++++---- .../java/org/apache/maven/wrapper/WrapperExecutor.java | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/maven-caching/src/main/mdo/cache-build.mdo b/maven-caching/src/main/mdo/cache-build.mdo index b1d720332bcd..01c28a64df41 100644 --- a/maven-caching/src/main/mdo/cache-build.mdo +++ b/maven-caching/src/main/mdo/cache-build.mdo @@ -46,7 +46,7 @@ under the License. String - + _final 1.0.0+ Boolean diff --git a/maven-caching/src/main/mdo/cache-config.mdo b/maven-caching/src/main/mdo/cache-config.mdo index 6f3c3398f8b4..2276bd77a419 100644 --- a/maven-caching/src/main/mdo/cache-config.mdo +++ b/maven-caching/src/main/mdo/cache-config.mdo @@ -879,11 +879,11 @@ under the License. logAll boolean true - Controls if all plugin properties to be logged (true is default). All the properties logged + @@ -1020,14 +1020,14 @@ under the License. logAllProperties boolean true - + diff --git a/maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java b/maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java index 42d5677f50c7..69a27b18789d 100644 --- a/maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java +++ b/maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java @@ -28,8 +28,8 @@ import java.util.Properties; /** - * Wrapper executor, running {@link Installer} to get a Maven distribution ready, followed by {@BootstrapMainStarter} - * to launch the Maven bootstrap. + * Wrapper executor, running {@link Installer} to get a Maven distribution ready, followed by + * {@link BootstrapMainStarter} to launch the Maven bootstrap. * * @author Hans Dockter */ From bbc8ed75e5f43f29c66ae7883c2217f38b58bbf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 11 Nov 2021 18:48:07 +0100 Subject: [PATCH 123/188] [MNG-7129] rename (Artifacts/Local)Repository to *CacheRepository --- .../apache/maven/caching/CacheControllerImpl.java | 10 +++++----- ...ArtifactsRepository.java => CacheRepository.java} | 4 ++-- ...ositoryImpl.java => HttpCacheRepositoryImpl.java} | 8 ++++---- ...actsRepository.java => LocalCacheRepository.java} | 4 ++-- ...sitoryImpl.java => LocalCacheRepositoryImpl.java} | 12 ++++++------ ...ctsRepository.java => RemoteCacheRepository.java} | 4 ++-- .../maven/caching/checksum/MavenProjectInput.java | 12 ++++++------ 7 files changed, 27 insertions(+), 27 deletions(-) rename maven-caching/src/main/java/org/apache/maven/caching/{ArtifactsRepository.java => CacheRepository.java} (95%) rename maven-caching/src/main/java/org/apache/maven/caching/{HttpRepositoryImpl.java => HttpCacheRepositoryImpl.java} (97%) rename maven-caching/src/main/java/org/apache/maven/caching/{LocalArtifactsRepository.java => LocalCacheRepository.java} (94%) rename maven-caching/src/main/java/org/apache/maven/caching/{LocalRepositoryImpl.java => LocalCacheRepositoryImpl.java} (98%) rename maven-caching/src/main/java/org/apache/maven/caching/{RemoteArtifactsRepository.java => RemoteCacheRepository.java} (93%) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index d20b810a4e33..26c1643528bc 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -96,7 +96,7 @@ import static org.apache.maven.caching.CacheResult.partialSuccess; import static org.apache.maven.caching.CacheResult.rebuilded; import static org.apache.maven.caching.CacheResult.success; -import static org.apache.maven.caching.HttpRepositoryImpl.BUILDINFO_XML; +import static org.apache.maven.caching.HttpCacheRepositoryImpl.BUILDINFO_XML; import static org.apache.maven.caching.checksum.KeyUtils.getVersionlessProjectKey; import static org.apache.maven.caching.checksum.MavenProjectInput.CACHE_IMPLMENTATION_VERSION; @@ -115,8 +115,8 @@ public class CacheControllerImpl implements CacheController private final Logger logger; private final MavenPluginManager mavenPluginManager; private final MavenProjectHelper projectHelper; - private final LocalArtifactsRepository localCache; - private final RemoteArtifactsRepository remoteCache; + private final LocalCacheRepository localCache; + private final RemoteCacheRepository remoteCache; private final CacheConfig cacheConfig; private final RepositorySystem repoSystem; private final ArtifactHandlerManager artifactHandlerManager; @@ -130,8 +130,8 @@ public CacheControllerImpl( Logger logger, MavenPluginManager mavenPluginManager, MavenProjectHelper projectHelper, - LocalArtifactsRepository localCache, - RemoteArtifactsRepository remoteCache, + LocalCacheRepository localCache, + RemoteCacheRepository remoteCache, CacheConfig cacheConfig, RepositorySystem repoSystem, ArtifactHandlerManager artifactHandlerManager, diff --git a/maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheRepository.java similarity index 95% rename from maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java rename to maven-caching/src/main/java/org/apache/maven/caching/CacheRepository.java index f3f45cf5d07b..d1930bac79d0 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/ArtifactsRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheRepository.java @@ -27,9 +27,9 @@ import java.io.IOException; /** - * ArtifactsRepository + * Cache repository. */ -public interface ArtifactsRepository +public interface CacheRepository { Build findBuild( CacheContext context ) throws IOException; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java similarity index 97% rename from maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java rename to maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java index 9cf169d1dc4c..3b74e3c345d7 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java @@ -55,11 +55,11 @@ import org.codehaus.plexus.logging.Logger; /** - * HttpRepositoryImpl + * HTTP remote cache repository implementation. */ @Singleton @Named -public class HttpRepositoryImpl implements RemoteArtifactsRepository +public class HttpCacheRepositoryImpl implements RemoteCacheRepository { public static final String BUILDINFO_XML = "buildinfo.xml"; @@ -71,7 +71,7 @@ public class HttpRepositoryImpl implements RemoteArtifactsRepository private final CacheConfig cacheConfig; @Inject - public HttpRepositoryImpl( Logger logger, LegacySupport legacySupport, + public HttpCacheRepositoryImpl( Logger logger, LegacySupport legacySupport, XmlService xmlService, CacheConfig cacheConfig ) { this.logger = logger; @@ -82,7 +82,7 @@ public HttpRepositoryImpl( Logger logger, LegacySupport legacySupport, @SuppressWarnings( "checkstyle:constantname" ) private static final ThreadLocal httpClient = - ThreadLocal.withInitial( HttpRepositoryImpl::newHttpClient ); + ThreadLocal.withInitial( HttpCacheRepositoryImpl::newHttpClient ); @SuppressWarnings( "checkstyle:magicnumber" ) private static CloseableHttpClient newHttpClient() diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepository.java similarity index 94% rename from maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java rename to maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepository.java index 772846722f3d..c2b55d42ab60 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalArtifactsRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepository.java @@ -30,9 +30,9 @@ import org.apache.maven.model.Dependency; /** - * LocalArtifactsRepository + * Local cache repository. */ -public interface LocalArtifactsRepository extends ArtifactsRepository +public interface LocalCacheRepository extends CacheRepository { void beforeSave( CacheContext environment ) throws IOException; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java similarity index 98% rename from maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java rename to maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java index c162e09115fe..e6589c19d645 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java @@ -69,11 +69,11 @@ import static org.apache.maven.caching.checksum.MavenProjectInput.CACHE_IMPLMENTATION_VERSION; /** - * LocalRepositoryImpl + * Local cache repository implementation. */ @Singleton @Named -public class LocalRepositoryImpl implements LocalArtifactsRepository +public class LocalCacheRepositoryImpl implements LocalCacheRepository { private static final String BUILDINFO_XML = "buildinfo.xml"; @@ -85,16 +85,16 @@ public class LocalRepositoryImpl implements LocalArtifactsRepository private final Logger logger; private final LegacySupport legacySupport; - private final RemoteArtifactsRepository remoteRepository; + private final RemoteCacheRepository remoteRepository; private final XmlService xmlService; private final CacheConfig cacheConfig; private final Map, Optional> bestBuildCache = new ConcurrentHashMap<>(); @Inject - public LocalRepositoryImpl( + public LocalCacheRepositoryImpl( Logger logger, LegacySupport legacySupport, - RemoteArtifactsRepository remoteRepository, + RemoteCacheRepository remoteRepository, XmlService xmlService, CacheConfig cacheConfig ) { @@ -226,7 +226,7 @@ public void clearCache( CacheContext context ) int maxLocalBuildsCached = cacheConfig.getMaxLocalBuildsCached() - 1; if ( cacheDirs.size() > maxLocalBuildsCached ) { - cacheDirs.sort( Comparator.comparing( LocalRepositoryImpl::lastModifiedTime ) ); + cacheDirs.sort( Comparator.comparing( LocalCacheRepositoryImpl::lastModifiedTime ) ); for ( Path dir : cacheDirs.subList( 0, cacheDirs.size() - maxLocalBuildsCached ) ) { FileUtils.deleteDirectory( dir.toFile() ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java similarity index 93% rename from maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java rename to maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java index 9c4f8a1304ef..f2b3fffe16db 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/RemoteArtifactsRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java @@ -27,9 +27,9 @@ import org.apache.maven.project.MavenProject; /** - * RemoteArtifactsRepository + * Remote cache repository. */ -public interface RemoteArtifactsRepository extends ArtifactsRepository +public interface RemoteCacheRepository extends CacheRepository { byte[] getArtifactContent( CacheContext context, Artifact artifact ) throws IOException; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 54c45a4ac1e9..bcfd6a2e7cee 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -54,10 +54,10 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.caching.Clock; -import org.apache.maven.caching.LocalArtifactsRepository; +import org.apache.maven.caching.LocalCacheRepository; import org.apache.maven.caching.PluginScanConfig; import org.apache.maven.caching.ProjectUtils; -import org.apache.maven.caching.RemoteArtifactsRepository; +import org.apache.maven.caching.RemoteCacheRepository; import org.apache.maven.caching.ScanConfigProperties; import org.apache.maven.caching.Utils; import org.apache.maven.caching.hash.HashAlgorithm; @@ -133,8 +133,8 @@ public class MavenProjectInput private final Logger logger; private final MavenProject project; private final MavenSession session; - private final LocalArtifactsRepository localCache; - private final RemoteArtifactsRepository remoteCache; + private final LocalCacheRepository localCache; + private final RemoteCacheRepository remoteCache; private final RepositorySystem repoSystem; private final ArtifactHandlerManager artifactHandlerManager; private final CacheConfig config; @@ -156,8 +156,8 @@ public MavenProjectInput( MavenProject project, RepositorySystem repoSystem, ArtifactHandlerManager artifactHandlerManager, Logger logger, - LocalArtifactsRepository localCache, - RemoteArtifactsRepository remoteCache ) + LocalCacheRepository localCache, + RemoteCacheRepository remoteCache ) { this.project = project; this.session = session; From eee28e2758c03d532ac8710e329d752134cac374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 11 Nov 2021 18:59:53 +0100 Subject: [PATCH 124/188] [MNG-7129] fix typos --- .../{AllExternalSrategy.java => AllExternalStrategy.java} | 4 ++-- .../java/org/apache/maven/caching/xml/CacheConfigImpl.java | 4 ++-- ...nelVersionStartegy.java => SentinelVersionStrategy.java} | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) rename maven-caching/src/main/java/org/apache/maven/caching/xml/{AllExternalSrategy.java => AllExternalStrategy.java} (92%) rename maven-caching/src/main/java/org/apache/maven/caching/xml/{SentinelVersionStartegy.java => SentinelVersionStrategy.java} (91%) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/AllExternalStrategy.java similarity index 92% rename from maven-caching/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/AllExternalStrategy.java index 00c1d4d84ac8..97d7691d81a2 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/AllExternalSrategy.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/AllExternalStrategy.java @@ -24,9 +24,9 @@ import org.apache.maven.model.Dependency; /** - * AllExternalSrategy + * AllExternalStrategy */ -public class AllExternalSrategy implements MultimoduleDiscoveryStrategy +public class AllExternalStrategy implements MultimoduleDiscoveryStrategy { @Override public boolean isPartOfMultiModule( Dependency dependency ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index c433117fac94..6c74b8950cbc 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -392,9 +392,9 @@ public MultimoduleDiscoveryStrategy getMultimoduleDiscoveryStrategy() cacheConfig.getConfiguration().getProjectDiscoveryStrategy(); if ( projectDiscoveryStrategy != null && projectDiscoveryStrategy.getSpecificVersion() != null ) { - return new SentinelVersionStartegy( projectDiscoveryStrategy.getSpecificVersion() ); + return new SentinelVersionStrategy( projectDiscoveryStrategy.getSpecificVersion() ); } - return new AllExternalSrategy(); + return new AllExternalStrategy(); } @Nonnull diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStrategy.java similarity index 91% rename from maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java rename to maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStrategy.java index 6d332308cc07..e198899097f3 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStartegy.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStrategy.java @@ -25,13 +25,13 @@ import org.codehaus.plexus.util.StringUtils; /** - * SentinelVersionStartegy + * SentinelVersionStrategy */ -public class SentinelVersionStartegy implements MultimoduleDiscoveryStrategy +public class SentinelVersionStrategy implements MultimoduleDiscoveryStrategy { private final String version; - public SentinelVersionStartegy( String version ) + public SentinelVersionStrategy( String version ) { this.version = version; } From 1723cfd05fa400431b6f0825beac12af85c5fb93 Mon Sep 17 00:00:00 2001 From: Alexander Ashitkin Date: Mon, 1 Nov 2021 15:32:53 -0400 Subject: [PATCH 125/188] [MNG-7129] Changes in maven core required to support incremental maven build - maven 4 port [MNG-7129] Changes in maven core required to support incremental maven build - master [MNG-7129] Changes in maven core required to support incremental maven build - master [MNG-7129] Changes in maven core required to support incremental maven build - master --- .../lifecycle/internal/MojoExecutor.java | 18 +++++--- .../plugin/DefaultMojosExecutionStrategy.java | 46 +++++++++++++++++++ .../maven/plugin/MojoExecutionRunner.java | 37 +++++++++++++++ .../maven/plugin/MojosExecutionStrategy.java | 45 ++++++++++++++++++ .../internal/DefaultMavenPluginManager.java | 15 ++++++ .../internal/stub/MojoExecutorStub.java | 16 ++----- 6 files changed, 159 insertions(+), 18 deletions(-) create mode 100644 maven-core/src/main/java/org/apache/maven/plugin/DefaultMojosExecutionStrategy.java create mode 100644 maven-core/src/main/java/org/apache/maven/plugin/MojoExecutionRunner.java create mode 100644 maven-core/src/main/java/org/apache/maven/plugin/MojosExecutionStrategy.java diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java index 946bffb0a104..7e41d103dede 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java @@ -43,6 +43,7 @@ import org.apache.maven.plugin.MavenPluginManager; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojosExecutionStrategy; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.PluginConfigurationException; import org.apache.maven.plugin.PluginIncompatibleException; @@ -71,18 +72,22 @@ public class MojoExecutor private final MavenPluginManager mavenPluginManager; private final LifecycleDependencyResolver lifeCycleDependencyResolver; private final ExecutionEventCatapult eventCatapult; + private final MojosExecutionStrategy mojosExecutionStrategy; @Inject public MojoExecutor( BuildPluginManager pluginManager, MavenPluginManager mavenPluginManager, LifecycleDependencyResolver lifeCycleDependencyResolver, - ExecutionEventCatapult eventCatapult ) + ExecutionEventCatapult eventCatapult, + MojosExecutionStrategy mojosExecutionStrategy + ) { this.pluginManager = pluginManager; this.mavenPluginManager = mavenPluginManager; this.lifeCycleDependencyResolver = lifeCycleDependencyResolver; this.eventCatapult = eventCatapult; + this.mojosExecutionStrategy = mojosExecutionStrategy; } public DependencyContext newDependencyContext( MavenSession session, List mojoExecutions ) @@ -140,21 +145,22 @@ else if ( Artifact.SCOPE_TEST.equals( classpath ) ) return Collections.unmodifiableCollection( scopes ); } - public void execute( MavenSession session, List mojoExecutions, ProjectIndex projectIndex ) - throws LifecycleExecutionException + public void execute( final MavenSession session, + List mojoExecutions, + final ProjectIndex projectIndex ) throws LifecycleExecutionException { DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); - for ( MojoExecution mojoExecution : mojoExecutions ) + mojosExecutionStrategy.execute( mojoExecutions, session, mojoExecution -> { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); - } + } ); } - public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, + private void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, DependencyContext dependencyContext, PhaseRecorder phaseRecorder ) throws LifecycleExecutionException { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultMojosExecutionStrategy.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultMojosExecutionStrategy.java new file mode 100644 index 000000000000..9507c7ad17c0 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultMojosExecutionStrategy.java @@ -0,0 +1,46 @@ +package org.apache.maven.plugin; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.LifecycleExecutionException; + +import javax.inject.Named; +import javax.inject.Singleton; +import java.util.List; + +/** + * Default mojo execution strategy. It just iterates over mojo executions and runs one by one + */ +@Named +@Singleton +public class DefaultMojosExecutionStrategy implements MojosExecutionStrategy +{ + @Override + public void execute( List mojos, MavenSession session, MojoExecutionRunner mojoRunner ) + throws LifecycleExecutionException + { + for ( MojoExecution mojoExecution : mojos ) + { + mojoRunner.run( mojoExecution ); + } + + } +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecutionRunner.java b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecutionRunner.java new file mode 100644 index 000000000000..ea29df495c19 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecutionRunner.java @@ -0,0 +1,37 @@ +package org.apache.maven.plugin; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.lifecycle.LifecycleExecutionException; + +/** + * Provides context for mojo execution. Invocation of #run will result in actual execution + */ +@FunctionalInterface +public interface MojoExecutionRunner +{ + /** + * Runs mojo execution + * + * @param execution mojo execution + * @throws LifecycleExecutionException + */ + void run( MojoExecution execution ) throws LifecycleExecutionException; +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MojosExecutionStrategy.java b/maven-core/src/main/java/org/apache/maven/plugin/MojosExecutionStrategy.java new file mode 100644 index 000000000000..e4babf68d7db --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/plugin/MojosExecutionStrategy.java @@ -0,0 +1,45 @@ +package org.apache.maven.plugin; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.LifecycleExecutionException; + +import java.util.List; + +/** + * Interface allows overriding default mojo execution strategy For example it is possible wrap some mojo execution to + * decorate default functionality or skip some executions + */ +public interface MojosExecutionStrategy +{ + + /** + * Entry point to the execution strategy + * + * @param mojos list of mojos representing a project build + * @param session current session + * @param mojoExecutionRunner mojo execution task which must be invoked by a strategy to actually run it + * @throws LifecycleExecutionException + */ + void execute( List mojos, MavenSession session, MojoExecutionRunner mojoExecutionRunner ) + throws LifecycleExecutionException; + +} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java index 7da8ea88fa29..88813e6c9bdb 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java @@ -492,6 +492,21 @@ public T getConfiguredMojo( Class mojoInterface, MavenSession session, Mo ClassRealm pluginRealm = pluginDescriptor.getClassRealm(); + if ( pluginRealm == null ) + { + try + { + setupPluginRealm( pluginDescriptor, session, null, null, null ); + } + catch ( PluginResolutionException e ) + { + String msg = "Cannot setup plugin realm [mojoDescriptor=" + mojoDescriptor.getId() + + ", pluginDescriptor=" + pluginDescriptor.getId() + "]"; + throw new PluginConfigurationException( pluginDescriptor, msg, e ); + } + pluginRealm = pluginDescriptor.getClassRealm(); + } + if ( logger.isDebugEnabled() ) { logger.debug( "Configuring mojo " + mojoDescriptor.getId() + " from plugin realm " + pluginRealm ); diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java index f0353510fc64..6e7880867d98 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java @@ -17,15 +17,14 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.LifecycleExecutionException; -import org.apache.maven.lifecycle.internal.DependencyContext; import org.apache.maven.lifecycle.internal.ExecutionEventCatapult; import org.apache.maven.lifecycle.internal.LifecycleDependencyResolver; import org.apache.maven.lifecycle.internal.MojoExecutor; -import org.apache.maven.lifecycle.internal.PhaseRecorder; import org.apache.maven.lifecycle.internal.ProjectIndex; import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MavenPluginManager; import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.MojosExecutionStrategy; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; @@ -46,17 +45,10 @@ public MojoExecutorStub( BuildPluginManager pluginManager, MavenPluginManager mavenPluginManager, LifecycleDependencyResolver lifeCycleDependencyResolver, - ExecutionEventCatapult eventCatapult ) + ExecutionEventCatapult eventCatapult, + MojosExecutionStrategy mojosExecutionStrategy ) { - super( pluginManager, mavenPluginManager, lifeCycleDependencyResolver, eventCatapult ); - } - - @Override - public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, - DependencyContext dependencyContext, PhaseRecorder phaseRecorder ) - throws LifecycleExecutionException - { - executions.add( mojoExecution ); + super( pluginManager, mavenPluginManager, lifeCycleDependencyResolver, eventCatapult, mojosExecutionStrategy ); } @Override From 6a20fd5eec7697869916d7a62241059bc154f0fc Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 10 Nov 2021 14:12:22 +0100 Subject: [PATCH 126/188] [MNG-7329] Upgrade maven-enforcer-plugin --- maven-bom/pom.xml | 12 ++++++++++++ pom.xml | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/maven-bom/pom.xml b/maven-bom/pom.xml index edc6eb002f29..ed4808e6567e 100644 --- a/maven-bom/pom.xml +++ b/maven-bom/pom.xml @@ -153,6 +153,18 @@ under the License. + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0 + + + org.codehaus.mojo + extra-enforcer-rules + 1.4 + + + maven-site-plugin diff --git a/pom.xml b/pom.xml index 900af5c39ee3..74798704b6ec 100644 --- a/pom.xml +++ b/pom.xml @@ -649,6 +649,14 @@ under the License. org.apache.maven.plugins maven-enforcer-plugin + 3.0.0 + + + org.codehaus.mojo + extra-enforcer-rules + 1.4 + + From 6057a33674dec9ac966f0f835bd88b76c30a36b2 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Fri, 12 Nov 2021 18:58:57 +0100 Subject: [PATCH 127/188] [MNG-7331] Upgrade Jansi to 2.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 74798704b6ec..e4a98e69e8f2 100644 --- a/pom.xml +++ b/pom.xml @@ -310,7 +310,7 @@ under the License. org.fusesource.jansi jansi - 2.3.4 + 2.4.0 org.slf4j From 1a1c16c8b789c186515a481b1a20056969e74908 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 15 Nov 2021 13:10:09 +0100 Subject: [PATCH 128/188] [MNG-7334] Make the cache singletons reusable across maven sessions --- .../maven/caching/CacheControllerFactory.java | 86 ++++++++++ .../maven/caching/CacheControllerImpl.java | 40 ++--- .../apache/maven/caching/CacheEventSpy.java | 23 ++- .../maven/caching/CachingMojoExecutor.java | 30 ++-- .../caching/HttpCacheRepositoryImpl.java | 7 - .../caching/LocalCacheRepositoryFactory.java | 64 +++++++ .../caching/LocalCacheRepositoryImpl.java | 7 - .../caching/RemoteCacheRepositoryFactory.java | 59 +++++++ .../apache/maven/caching/SessionUtils.java | 48 ++++++ .../apache/maven/caching/xml/CacheConfig.java | 5 +- .../maven/caching/xml/CacheConfigFactory.java | 52 ++++++ .../maven/caching/xml/CacheConfigImpl.java | 156 ++++++++---------- 12 files changed, 431 insertions(+), 146 deletions(-) create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/SessionUtils.java create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java new file mode 100644 index 000000000000..878f34c480c3 --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java @@ -0,0 +1,86 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.caching.xml.CacheConfigFactory; +import org.apache.maven.caching.xml.XmlService; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.MavenPluginManager; +import org.apache.maven.project.MavenProjectHelper; +import org.apache.maven.repository.RepositorySystem; +import org.codehaus.plexus.logging.Logger; + +@Singleton +@Named +public class CacheControllerFactory +{ + + private static final Object KEY = CacheControllerFactory.class.getName(); + + private final Logger logger; + private final XmlService xmlService; + private final MavenPluginManager mavenPluginManager; + private final MavenProjectHelper projectHelper; + private final ArtifactHandlerManager artifactHandlerManager; + private final RepositorySystem repoSystem; + private final CacheConfigFactory cacheConfigFactory; + private final LocalCacheRepositoryFactory localCacheRepositoryFactory; + private final RemoteCacheRepositoryFactory remoteCacheRepositoryFactory; + + @Inject + public CacheControllerFactory( Logger logger, + XmlService xmlService, + MavenPluginManager mavenPluginManager, + MavenProjectHelper projectHelper, + ArtifactHandlerManager artifactHandlerManager, + RepositorySystem repoSystem, + CacheConfigFactory cacheConfigFactory, + LocalCacheRepositoryFactory localCacheRepositoryFactory, + RemoteCacheRepositoryFactory remoteCacheRepositoryFactory ) + { + this.logger = logger; + this.xmlService = xmlService; + this.mavenPluginManager = mavenPluginManager; + this.projectHelper = projectHelper; + this.artifactHandlerManager = artifactHandlerManager; + this.repoSystem = repoSystem; + this.cacheConfigFactory = cacheConfigFactory; + this.localCacheRepositoryFactory = localCacheRepositoryFactory; + this.remoteCacheRepositoryFactory = remoteCacheRepositoryFactory; + } + + public CacheController getCacheContoller( MavenSession session ) + { + return SessionUtils.getOrCreate( session, KEY, + () -> new CacheControllerImpl( logger, + mavenPluginManager, projectHelper, + repoSystem, artifactHandlerManager, + xmlService, + localCacheRepositoryFactory.getLocalCacheRepository( session ), + remoteCacheRepositoryFactory.getRemoteCacheRepository( session ), + cacheConfigFactory.getCacheConfig( session ) ) ); + } + +} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 26c1643528bc..cd9f7f7fed03 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -44,9 +44,6 @@ import java.util.regex.Pattern; import javax.annotation.Nonnull; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; @@ -103,8 +100,6 @@ /** * CacheControllerImpl */ -@Singleton -@Named public class CacheControllerImpl implements CacheController { @@ -112,30 +107,29 @@ public class CacheControllerImpl implements CacheController private static final String GENERATEDSOURCES = "generatedsources"; private static final String GENERATEDSOURCES_PREFIX = GENERATEDSOURCES + FILE_SEPARATOR_SUBST; - private final Logger logger; - private final MavenPluginManager mavenPluginManager; - private final MavenProjectHelper projectHelper; - private final LocalCacheRepository localCache; - private final RemoteCacheRepository remoteCache; - private final CacheConfig cacheConfig; - private final RepositorySystem repoSystem; + private final Logger logger; + private final MavenPluginManager mavenPluginManager; + private final MavenProjectHelper projectHelper; + private final RepositorySystem repoSystem; private final ArtifactHandlerManager artifactHandlerManager; private final XmlService xmlService; + private final CacheConfig cacheConfig; + private final LocalCacheRepository localCache; + private final RemoteCacheRepository remoteCache; private final ConcurrentMap artifactDigestByKey = new ConcurrentHashMap<>(); private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); private volatile Scm scm; - @Inject public CacheControllerImpl( - Logger logger, - MavenPluginManager mavenPluginManager, - MavenProjectHelper projectHelper, - LocalCacheRepository localCache, + Logger logger, + MavenPluginManager mavenPluginManager, + MavenProjectHelper projectHelper, + RepositorySystem repoSystem, + ArtifactHandlerManager artifactHandlerManager, + XmlService xmlService, + LocalCacheRepository localCache, RemoteCacheRepository remoteCache, - CacheConfig cacheConfig, - RepositorySystem repoSystem, - ArtifactHandlerManager artifactHandlerManager, - XmlService xmlService ) + CacheConfig cacheConfig ) { this.logger = logger; this.mavenPluginManager = mavenPluginManager; @@ -150,7 +144,8 @@ public CacheControllerImpl( @Override @Nonnull - public CacheResult findCachedBuild( MavenSession session, MavenProject project, ProjectIndex projectIndex, + public CacheResult findCachedBuild( MavenSession session, MavenProject project, + ProjectIndex projectIndex, List mojoExecutions ) { @@ -751,7 +746,6 @@ public void saveCacheReport( MavenSession session ) { try { - CacheReport cacheReport = new CacheReport(); for ( CacheResult result : cacheResults.values() ) { diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java index cb5a80f08c34..b0ffe050db04 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java @@ -24,8 +24,10 @@ import javax.inject.Singleton; import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.CacheConfigFactory; import org.apache.maven.eventspy.AbstractEventSpy; import org.apache.maven.execution.ExecutionEvent; +import org.apache.maven.execution.MavenSession; /** * Triggers cache report generation on build completion @@ -34,26 +36,29 @@ @Named public class CacheEventSpy extends AbstractEventSpy { - private final CacheConfig cacheConfig; - private final CacheController cacheController; + private final CacheConfigFactory cacheConfigFactory; + private final CacheControllerFactory cacheControllerFactory; @Inject - public CacheEventSpy( CacheConfig cacheConfig, CacheController cacheController ) + public CacheEventSpy( CacheConfigFactory cacheConfigFactory, CacheControllerFactory cacheControllerFactory ) { - this.cacheConfig = cacheConfig; - this.cacheController = cacheController; + this.cacheConfigFactory = cacheConfigFactory; + this.cacheControllerFactory = cacheControllerFactory; } @Override public void onEvent( Object event ) throws Exception { - if ( cacheConfig.isEnabled() ) + if ( event instanceof ExecutionEvent ) { - if ( event instanceof ExecutionEvent ) + ExecutionEvent executionEvent = (ExecutionEvent) event; + if ( executionEvent.getType() == ExecutionEvent.Type.SessionEnded ) { - ExecutionEvent executionEvent = (ExecutionEvent) event; - if ( executionEvent.getType() == ExecutionEvent.Type.SessionEnded ) + MavenSession session = executionEvent.getSession(); + CacheConfig cacheConfig = cacheConfigFactory.getCacheConfig( session ); + if ( cacheConfig.isEnabled() ) { + CacheController cacheController = cacheControllerFactory.getCacheContoller( session ); cacheController.saveCacheReport( executionEvent.getSession() ); } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java index 53133568934f..e66622c9c0ca 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java @@ -38,6 +38,7 @@ import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter; import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.CacheConfigFactory; import org.apache.maven.caching.xml.CacheState; import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.MavenSession; @@ -88,8 +89,8 @@ public class CachingMojoExecutor implements IMojoExecutor private final MavenPluginManager mavenPluginManager; private final LifecycleDependencyResolver lifeCycleDependencyResolver; private final ExecutionEventCatapult eventCatapult; - private final CacheController cacheController; - private final CacheConfig cacheConfig; + private final CacheControllerFactory cacheControllerFactory; + private final CacheConfigFactory cacheConfigFactory; private final MojoParametersListener mojoListener; @Inject @@ -99,8 +100,8 @@ public CachingMojoExecutor( MavenPluginManager mavenPluginManager, LifecycleDependencyResolver lifeCycleDependencyResolver, ExecutionEventCatapult eventCatapult, - CacheController cacheController, - CacheConfig cacheConfig, + CacheControllerFactory cacheControllerFactory, + CacheConfigFactory cacheConfigFactory, MojoParametersListener mojoListener ) { this.logger = logger; @@ -108,8 +109,8 @@ public CachingMojoExecutor( this.mavenPluginManager = mavenPluginManager; this.lifeCycleDependencyResolver = lifeCycleDependencyResolver; this.eventCatapult = eventCatapult; - this.cacheController = cacheController; - this.cacheConfig = cacheConfig; + this.cacheControllerFactory = cacheControllerFactory; + this.cacheConfigFactory = cacheConfigFactory; this.mojoListener = mojoListener; } @@ -171,6 +172,7 @@ else if ( Artifact.SCOPE_TEST.equals( classpath ) ) public void execute( MavenSession session, List mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { + CacheController cacheController = cacheControllerFactory.getCacheContoller( session ); DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); @@ -179,6 +181,7 @@ public void execute( MavenSession session, List mojoExecutions, P final Source source = getSource( mojoExecutions ); // execute clean bound goals before restoring to not interfere/slowdown clean + CacheConfig cacheConfig = cacheConfigFactory.getCacheConfig( session ); CacheState cacheState = DISABLED; CacheResult result = CacheResult.empty(); if ( source == Source.LIFECYCLE ) @@ -188,7 +191,7 @@ public void execute( MavenSession session, List mojoExecutions, P { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } - cacheState = cacheConfig.initialize( project, session ); + cacheState = cacheConfig.getState(); if ( cacheState == INITIALIZED ) { result = cacheController.findCachedBuild( session, project, projectIndex, mojoExecutions ); @@ -199,7 +202,8 @@ public void execute( MavenSession session, List mojoExecutions, P boolean restored = result.isSuccess(); // if partially restored need to save increment if ( restorable ) { - restored &= restoreProject( result, mojoExecutions, projectIndex, dependencyContext, phaseRecorder ); + restored &= restoreProject( result, mojoExecutions, projectIndex, + dependencyContext, phaseRecorder, cacheConfig ); } else { @@ -246,13 +250,15 @@ private boolean restoreProject( CacheResult cacheResult, List mojoExecutions, ProjectIndex projectIndex, DependencyContext dependencyContext, - PhaseRecorder phaseRecorder ) throws LifecycleExecutionException + PhaseRecorder phaseRecorder, + CacheConfig cacheConfig ) throws LifecycleExecutionException { final Build build = cacheResult.getBuildInfo(); final MavenProject project = cacheResult.getContext().getProject(); final MavenSession session = cacheResult.getContext().getSession(); final List cachedSegment = build.getCachedSegment( mojoExecutions ); + CacheController cacheController = cacheControllerFactory.getCacheContoller( session ); boolean restored = cacheController.restoreProjectArtifacts( cacheResult ); if ( !restored ) @@ -276,7 +282,7 @@ private boolean restoreProject( CacheResult cacheResult, else { restored = verifyCacheConsistency( cacheCandidate, build, project, session, projectIndex, - dependencyContext, phaseRecorder ); + dependencyContext, phaseRecorder, cacheConfig ); if ( !restored ) { break; @@ -311,9 +317,11 @@ private boolean verifyCacheConsistency( MojoExecution cacheCandidate, MavenSession session, ProjectIndex projectIndex, DependencyContext dependencyContext, - PhaseRecorder phaseRecorder ) throws LifecycleExecutionException + PhaseRecorder phaseRecorder, + CacheConfig cacheConfig ) throws LifecycleExecutionException { + CacheController cacheController = cacheControllerFactory.getCacheContoller( session ); AtomicBoolean consistent = new AtomicBoolean( true ); final MojoExecutionManager mojoChecker = new MojoExecutionManager( project, cacheController, cachedBuild, consistent, logger, cacheConfig ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java index 3b74e3c345d7..de289d61d148 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java @@ -27,10 +27,6 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -57,8 +53,6 @@ /** * HTTP remote cache repository implementation. */ -@Singleton -@Named public class HttpCacheRepositoryImpl implements RemoteCacheRepository { @@ -70,7 +64,6 @@ public class HttpCacheRepositoryImpl implements RemoteCacheRepository private final XmlService xmlService; private final CacheConfig cacheConfig; - @Inject public HttpCacheRepositoryImpl( Logger logger, LegacySupport legacySupport, XmlService xmlService, CacheConfig cacheConfig ) { diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java new file mode 100644 index 000000000000..cce17d63af6b --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java @@ -0,0 +1,64 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.apache.maven.caching.xml.CacheConfigFactory; +import org.apache.maven.caching.xml.XmlService; +import org.apache.maven.execution.MavenSession; +import org.codehaus.plexus.logging.Logger; + +@Singleton +@Named +public class LocalCacheRepositoryFactory +{ + + private static final Object KEY = LocalCacheRepository.class.getName(); + + private final Logger logger; + private final XmlService xmlService; + private final CacheConfigFactory cacheConfigFactory; + private final RemoteCacheRepositoryFactory remoteCacheRepositoryFactory; + + @Inject + public LocalCacheRepositoryFactory( Logger logger, XmlService xmlService, + CacheConfigFactory cacheConfigFactory, + RemoteCacheRepositoryFactory remoteCacheRepositoryFactory ) + { + this.logger = logger; + this.xmlService = xmlService; + this.cacheConfigFactory = cacheConfigFactory; + this.remoteCacheRepositoryFactory = remoteCacheRepositoryFactory; + } + + public LocalCacheRepository getLocalCacheRepository( MavenSession session ) + { + return SessionUtils.getOrCreate( session, KEY, + () -> new LocalCacheRepositoryImpl( logger, + null, + remoteCacheRepositoryFactory.getRemoteCacheRepository( session ), + xmlService, + cacheConfigFactory.getCacheConfig( session ) ) ); + } + +} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java index e6589c19d645..2b03b5657f87 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java @@ -38,10 +38,6 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.maven.caching.Utils.MultiMap; @@ -71,8 +67,6 @@ /** * Local cache repository implementation. */ -@Singleton -@Named public class LocalCacheRepositoryImpl implements LocalCacheRepository { @@ -90,7 +84,6 @@ public class LocalCacheRepositoryImpl implements LocalCacheRepository private final CacheConfig cacheConfig; private final Map, Optional> bestBuildCache = new ConcurrentHashMap<>(); - @Inject public LocalCacheRepositoryImpl( Logger logger, LegacySupport legacySupport, diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java new file mode 100644 index 000000000000..0601a021e642 --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java @@ -0,0 +1,59 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.apache.maven.caching.xml.CacheConfigFactory; +import org.apache.maven.caching.xml.XmlService; +import org.apache.maven.execution.MavenSession; +import org.codehaus.plexus.logging.Logger; + +@Singleton +@Named +public class RemoteCacheRepositoryFactory +{ + + private static final Object KEY = RemoteCacheRepositoryFactory.class.getName(); + + private final Logger logger; + private final XmlService xmlService; + private final CacheConfigFactory cacheConfigFactory; + + @Inject + public RemoteCacheRepositoryFactory( Logger logger, XmlService xmlService, CacheConfigFactory cacheConfigFactory ) + { + this.logger = logger; + this.xmlService = xmlService; + this.cacheConfigFactory = cacheConfigFactory; + } + + public RemoteCacheRepository getRemoteCacheRepository( MavenSession session ) + { + return SessionUtils.getOrCreate( session, KEY, + () -> new HttpCacheRepositoryImpl( logger, + null, + xmlService, + cacheConfigFactory.getCacheConfig( session ) ) ); + } + +} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/SessionUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/SessionUtils.java new file mode 100644 index 000000000000..a0ca30c0524f --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/SessionUtils.java @@ -0,0 +1,48 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.function.Supplier; + +import org.apache.maven.execution.MavenSession; +import org.eclipse.aether.SessionData; + +public final class SessionUtils +{ + + public static T getOrCreate( MavenSession session, Object key, Supplier supplier ) + { + SessionData data = session.getRepositorySession().getData(); + while ( true ) + { + T t = (T) data.get( key ); + if ( t == null ) + { + t = supplier.get(); + if ( data.set( key, null, t ) ) + { + continue; + } + } + return t; + } + } + +} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java index 16a300bfbb9f..273b2283260c 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java @@ -26,11 +26,9 @@ import org.apache.maven.caching.xml.config.Include; import org.apache.maven.caching.xml.config.PropertyName; import org.apache.maven.caching.xml.config.TrackedProperty; -import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.project.MavenProject; import javax.annotation.Nonnull; import java.util.List; @@ -42,7 +40,8 @@ public interface CacheConfig { - CacheState initialize( MavenProject project, MavenSession session ); + @Nonnull + CacheState getState(); @Nonnull List getTrackedProperties( MojoExecution mojoExecution ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java new file mode 100644 index 000000000000..980bb610033e --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java @@ -0,0 +1,52 @@ +package org.apache.maven.caching.xml; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.apache.maven.caching.SessionUtils; +import org.apache.maven.execution.MavenSession; +import org.codehaus.plexus.logging.Logger; + +@Singleton +@Named +public class CacheConfigFactory +{ + + private static final Object KEY = CacheConfigFactory.class.getName(); + + private final Logger logger; + private final XmlService xmlService; + + @Inject + public CacheConfigFactory( Logger logger, XmlService xmlService ) + { + this.logger = logger; + this.xmlService = xmlService; + } + + public CacheConfig getCacheConfig( MavenSession session ) + { + return SessionUtils.getOrCreate( session, KEY, () -> new CacheConfigImpl( logger, xmlService, session ) ); + } + +} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 6c74b8950cbc..1adb5d426045 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -28,9 +28,6 @@ import java.util.regex.Pattern; import javax.annotation.Nonnull; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; import org.apache.commons.lang3.StringUtils; import org.apache.maven.caching.DefaultPluginScanConfig; @@ -61,7 +58,6 @@ import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.project.MavenProject; import org.codehaus.plexus.logging.Logger; import static java.lang.Boolean.TRUE; @@ -71,8 +67,6 @@ /** * CacheConfigImpl */ -@Singleton -@Named public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig { @@ -83,34 +77,14 @@ public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig public static final String FAIL_FAST_PROPERTY_NAME = "remote.cache.failFast"; public static final String BASELINE_BUILD_URL_PROPERTY_NAME = "remote.cache.baselineUrl"; - private final Logger logger; - private final XmlService xmlService; + private final MavenSession session; + private final CacheState state; + private final CacheConfig cacheConfig; + private final HashFactory hashFactory; + private final List excludePatterns; - private volatile CacheState state = CacheState.NOT_INITIALIZED; - private volatile CacheConfig cacheConfig; - private volatile HashFactory hashFactory; - private MavenSession session; - private MavenProject project; - - private List excludePatterns; - - @Inject - public CacheConfigImpl( Logger logger, XmlService xmlService ) + public CacheConfigImpl( Logger logger, XmlService xmlService, MavenSession session ) { - this.logger = logger; - this.xmlService = xmlService; - } - - @Override - public synchronized CacheState initialize( MavenProject project, MavenSession session ) - { - - if ( state != CacheState.NOT_INITIALIZED ) - { - return state; - } - - this.project = project; this.session = session; final String enabled = getProperty( CACHE_ENABLED_PROPERTY_NAME, "true" ); @@ -118,59 +92,77 @@ public synchronized CacheState initialize( MavenProject project, MavenSession se { logger.info( "Cache disabled by command line flag, project will be built fully and not cached" ); state = CacheState.DISABLED; - return state; - } - - Path configPath; - - String configPathText = getProperty( CONFIG_PATH_PROPERTY_NAME, null ); - if ( StringUtils.isNotBlank( configPathText ) ) - { - configPath = Paths.get( configPathText ); + cacheConfig = null; + hashFactory = null; + excludePatterns = null; } else { - configPath = getMultimoduleRoot( session ).resolve( ".mvn" ).resolve( "maven-cache-config.xml" ); - } + Path configPath; - if ( !Files.exists( configPath ) ) - { - logger.warn( - "Cache configuration is not available at configured path " + configPath + ", cache is disabled" ); - state = CacheState.DISABLED; - return state; - } - - try - { - logger.info( "Loading cache configuration from " + configPath ); - cacheConfig = xmlService.loadCacheConfig( configPath.toFile() ); - } - catch ( Exception e ) - { - throw new IllegalArgumentException( - "Cannot initialize cache because xml config is not valid or not available", e ); - } + String configPathText = getProperty( CONFIG_PATH_PROPERTY_NAME, null ); + if ( StringUtils.isNotBlank( configPathText ) ) + { + configPath = Paths.get( configPathText ); + } + else + { + configPath = getMultimoduleRoot( session ).resolve( ".mvn" ).resolve( "maven-cache-config.xml" ); + } - if ( !cacheConfig.getConfiguration().isEnabled() ) - { - state = CacheState.DISABLED; - return state; - } + if ( !Files.exists( configPath ) ) + { + logger.warn( "Cache configuration is not available at configured path " + + configPath + ", cache is disabled" ); + state = CacheState.DISABLED; + cacheConfig = null; + hashFactory = null; + excludePatterns = null; + } + else + { + try + { + logger.info( "Loading cache configuration from " + configPath ); + cacheConfig = xmlService.loadCacheConfig( configPath.toFile() ); + } + catch ( Exception e ) + { + throw new IllegalArgumentException( + "Cannot initialize cache because xml config is not valid or not available", e ); + } - String hashAlgorithm = null; - try - { - hashAlgorithm = getConfiguration().getHashAlgorithm(); - hashFactory = HashFactory.of( hashAlgorithm ); - logger.info( "Using " + hashAlgorithm + " hash algorithm for cache" ); - } - catch ( Exception e ) - { - throw new IllegalArgumentException( "Unsupported hashing algorithm: " + hashAlgorithm, e ); + if ( !cacheConfig.getConfiguration().isEnabled() ) + { + state = CacheState.DISABLED; + hashFactory = null; + excludePatterns = null; + } + else + { + String hashAlgorithm = null; + try + { + hashAlgorithm = getConfiguration().getHashAlgorithm(); + hashFactory = HashFactory.of( hashAlgorithm ); + logger.info( "Using " + hashAlgorithm + " hash algorithm for cache" ); + } + catch ( Exception e ) + { + throw new IllegalArgumentException( "Unsupported hashing algorithm: " + hashAlgorithm, e ); + } + + excludePatterns = compileExcludePatterns(); + state = CacheState.INITIALIZED; + } + } } + } - state = CacheState.INITIALIZED; + @Nonnull + @Override + public CacheState getState() + { return state; } @@ -536,10 +528,6 @@ public List getAttachedOutputs() public List getExcludePatterns() { checkInitializedState(); - if ( excludePatterns == null ) - { - excludePatterns = compileExcludePatterns(); - } return excludePatterns; } @@ -588,11 +576,7 @@ private String getProperty( String key, String defaultValue ) value = session.getSystemProperties().getProperty( key ); if ( value == null ) { - value = project.getProperties().getProperty( key ); - if ( value == null ) - { - value = defaultValue; - } + value = defaultValue; } } return value; From 7d05973b16d3a41147bdf05a91bd280bfb45f04b Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 15 Nov 2021 17:45:40 +0100 Subject: [PATCH 129/188] [MNG-7129] Remove references to unused LegacySupport, fix typo --- .../maven/caching/HttpCacheRepositoryImpl.java | 13 +++++-------- .../maven/caching/LocalCacheRepositoryImpl.java | 8 ++------ .../maven/caching/checksum/MavenProjectInput.java | 5 +++-- .../java/org/apache/maven/caching/xml/Build.java | 2 +- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java index de289d61d148..5cb3046574a9 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java @@ -46,7 +46,6 @@ import org.apache.maven.caching.xml.report.CacheReport; import org.apache.maven.caching.xml.report.ProjectReport; import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.LegacySupport; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.logging.Logger; @@ -60,15 +59,13 @@ public class HttpCacheRepositoryImpl implements RemoteCacheRepository public static final String CACHE_REPORT_XML = "cache-report.xml"; private final Logger logger; - private final LegacySupport legacySupport; private final XmlService xmlService; private final CacheConfig cacheConfig; - public HttpCacheRepositoryImpl( Logger logger, LegacySupport legacySupport, + public HttpCacheRepositoryImpl( Logger logger, XmlService xmlService, CacheConfig cacheConfig ) { this.logger = logger; - this.legacySupport = legacySupport; this.xmlService = xmlService; this.cacheConfig = cacheConfig; } @@ -125,7 +122,7 @@ public void saveBuildInfo( CacheResult cacheResult, Build build ) public void saveCacheReport( String buildId, MavenSession session, CacheReport cacheReport ) throws IOException { MavenProject rootProject = session.getTopLevelProject(); - final String resourceUrl = cacheConfig.getUrl() + "/" + MavenProjectInput.CACHE_IMPLMENTATION_VERSION + final String resourceUrl = cacheConfig.getUrl() + "/" + MavenProjectInput.CACHE_IMPLEMENTATION_VERSION + "/" + rootProject.getGroupId() + "/" + rootProject.getArtifactId() + "/" + buildId @@ -212,7 +209,7 @@ public String getResourceUrl( CacheContext context, String filename ) private String getResourceUrl( String filename, String groupId, String artifactId, String checksum ) { - return cacheConfig.getUrl() + "/" + MavenProjectInput.CACHE_IMPLMENTATION_VERSION + "/" + groupId + "/" + return cacheConfig.getUrl() + "/" + MavenProjectInput.CACHE_IMPLEMENTATION_VERSION + "/" + groupId + "/" + artifactId + "/" + checksum + "/" + filename; } @@ -256,8 +253,8 @@ public Optional findBaselineBuild( MavenProject project ) Optional cachedProjectHolder = Optional.empty(); for ( ProjectReport p : cachedProjectsHolder.get() ) { - if ( project.getArtifactId().equals( p.getArtifactId() ) && project.getGroupId().equals( - p.getGroupId() ) ) + if ( project.getArtifactId().equals( p.getArtifactId() ) + && project.getGroupId().equals( p.getGroupId() ) ) { cachedProjectHolder = Optional.of( p ); break; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java index 2b03b5657f87..2d864a97cafc 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java @@ -50,7 +50,6 @@ import org.apache.maven.caching.xml.report.CacheReport; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; -import org.apache.maven.plugin.LegacySupport; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.logging.Logger; @@ -62,7 +61,7 @@ import static java.util.concurrent.TimeUnit.MINUTES; import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.maven.caching.ProjectUtils.getMultimoduleRoot; -import static org.apache.maven.caching.checksum.MavenProjectInput.CACHE_IMPLMENTATION_VERSION; +import static org.apache.maven.caching.checksum.MavenProjectInput.CACHE_IMPLEMENTATION_VERSION; /** * Local cache repository implementation. @@ -78,7 +77,6 @@ public class LocalCacheRepositoryImpl implements LocalCacheRepository private static final String EMPTY = ""; private final Logger logger; - private final LegacySupport legacySupport; private final RemoteCacheRepository remoteRepository; private final XmlService xmlService; private final CacheConfig cacheConfig; @@ -86,13 +84,11 @@ public class LocalCacheRepositoryImpl implements LocalCacheRepository public LocalCacheRepositoryImpl( Logger logger, - LegacySupport legacySupport, RemoteCacheRepository remoteRepository, XmlService xmlService, CacheConfig cacheConfig ) { this.logger = logger; - this.legacySupport = legacySupport; this.remoteRepository = remoteRepository; this.xmlService = xmlService; this.cacheConfig = cacheConfig; @@ -425,7 +421,7 @@ private Path buildCacheDir( CacheContext context ) throws IOException private Path artifactCacheDir( MavenSession session, String groupId, String artifactId ) throws IOException { final String localRepositoryRoot = session.getLocalRepository().getBasedir(); - final Path path = Paths.get( localRepositoryRoot, "..", "cache", CACHE_IMPLMENTATION_VERSION, groupId, + final Path path = Paths.get( localRepositoryRoot, "..", "cache", CACHE_IMPLEMENTATION_VERSION, groupId, artifactId ).normalize(); if ( !Files.exists( path ) ) { diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index bcfd6a2e7cee..e17811e8e4a2 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -103,9 +103,9 @@ public class MavenProjectInput { /** - * Version ov hashing algorithm implementation. It is recommended to change to simplify remote cache maintenance + * Version of hashing algorithm implementation. It is recommended to change to simplify remote cache maintenance */ - public static final String CACHE_IMPLMENTATION_VERSION = "v10"; + public static final String CACHE_IMPLEMENTATION_VERSION = "v1"; /** * property name to pass glob value. The glob to be used to list directory files in plugins scanning @@ -130,6 +130,7 @@ public class MavenProjectInput * Flag to control if we should check values from plugin configs as file system objects */ private static final String CACHE_PROCESS_PLUGINS = "remote.cache.processPlugins"; + private final Logger logger; private final MavenProject project; private final MavenSession session; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java index 5cbf4e75cd86..d00750a6b410 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java @@ -61,7 +61,7 @@ public Build( List goals, String hashAlgorithm ) { this.dto = new org.apache.maven.caching.xml.build.Build(); - this.dto.setCacheImplementationVersion( MavenProjectInput.CACHE_IMPLMENTATION_VERSION ); + this.dto.setCacheImplementationVersion( MavenProjectInput.CACHE_IMPLEMENTATION_VERSION ); this.dto.setBuildTime( new Date() ); try { From fdab508a77b7808a9455af2194e91518e5975873 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 15 Nov 2021 17:46:47 +0100 Subject: [PATCH 130/188] [MNG-7336] Define a Feature for caching --- .../java/org/apache/maven/caching/xml/CacheConfigImpl.java | 5 ++--- .../src/main/java/org/apache/maven/feature/Features.java | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 1adb5d426045..7ea2fa38932e 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -55,6 +55,7 @@ import org.apache.maven.caching.xml.config.Remote; import org.apache.maven.caching.xml.config.TrackedProperty; import org.apache.maven.execution.MavenSession; +import org.apache.maven.feature.Features; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; import org.apache.maven.plugin.MojoExecution; @@ -71,7 +72,6 @@ public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig { public static final String CONFIG_PATH_PROPERTY_NAME = "remote.cache.configPath"; - public static final String CACHE_ENABLED_PROPERTY_NAME = "remote.cache.enabled"; public static final String SAVE_TO_REMOTE_PROPERTY_NAME = "remote.cache.save.enabled"; public static final String SAVE_NON_OVERRIDEABLE_NAME = "remote.cache.save.final"; public static final String FAIL_FAST_PROPERTY_NAME = "remote.cache.failFast"; @@ -87,8 +87,7 @@ public CacheConfigImpl( Logger logger, XmlService xmlService, MavenSession sessi { this.session = session; - final String enabled = getProperty( CACHE_ENABLED_PROPERTY_NAME, "true" ); - if ( !parseBoolean( enabled ) ) + if ( !Features.caching( session.getUserProperties() ).isActive() ) { logger.info( "Cache disabled by command line flag, project will be built fully and not cached" ); state = CacheState.DISABLED; diff --git a/maven-model-builder/src/main/java/org/apache/maven/feature/Features.java b/maven-model-builder/src/main/java/org/apache/maven/feature/Features.java index 47608a6a0186..5c9156349d0e 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/feature/Features.java +++ b/maven-model-builder/src/main/java/org/apache/maven/feature/Features.java @@ -38,6 +38,11 @@ public static Feature buildConsumer( Properties userProperties ) return new Feature( userProperties, "maven.experimental.buildconsumer", "true" ); } + public static Feature caching( Properties userProperties ) + { + return new Feature( userProperties, "maven.experimental.caching", "true" ); + } + /** * Represents some feature * From a057014fa112ba1ec188cb87b19555fabb70265b Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 15 Nov 2021 17:52:37 +0100 Subject: [PATCH 131/188] [MNG-7129] fix compilation --- .../java/org/apache/maven/caching/CacheControllerImpl.java | 6 +++--- .../apache/maven/caching/LocalCacheRepositoryFactory.java | 1 - .../apache/maven/caching/RemoteCacheRepositoryFactory.java | 1 - .../java/org/apache/maven/caching/xml/CacheConfigImpl.java | 1 - 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index cd9f7f7fed03..fdb52e5a8e16 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -95,7 +95,7 @@ import static org.apache.maven.caching.CacheResult.success; import static org.apache.maven.caching.HttpCacheRepositoryImpl.BUILDINFO_XML; import static org.apache.maven.caching.checksum.KeyUtils.getVersionlessProjectKey; -import static org.apache.maven.caching.checksum.MavenProjectInput.CACHE_IMPLMENTATION_VERSION; +import static org.apache.maven.caching.checksum.MavenProjectInput.CACHE_IMPLEMENTATION_VERSION; /** * CacheControllerImpl @@ -229,11 +229,11 @@ private CacheResult analyzeResult( CacheContext context, List moj } final String cacheImplementationVersion = info.getCacheImplementationVersion(); - if ( !CACHE_IMPLMENTATION_VERSION.equals( cacheImplementationVersion ) ) + if ( !CACHE_IMPLEMENTATION_VERSION.equals( cacheImplementationVersion ) ) { logger.warn( "Maven and cached build implementations mismatch, caching might not work correctly. " - + "Implementation version: " + CACHE_IMPLMENTATION_VERSION + ", cached build: " + + "Implementation version: " + CACHE_IMPLEMENTATION_VERSION + ", cached build: " + info.getCacheImplementationVersion() ); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java index cce17d63af6b..7c362d38cbad 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java @@ -55,7 +55,6 @@ public LocalCacheRepository getLocalCacheRepository( MavenSession session ) { return SessionUtils.getOrCreate( session, KEY, () -> new LocalCacheRepositoryImpl( logger, - null, remoteCacheRepositoryFactory.getRemoteCacheRepository( session ), xmlService, cacheConfigFactory.getCacheConfig( session ) ) ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java index 0601a021e642..80bda4d526a1 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java @@ -51,7 +51,6 @@ public RemoteCacheRepository getRemoteCacheRepository( MavenSession session ) { return SessionUtils.getOrCreate( session, KEY, () -> new HttpCacheRepositoryImpl( logger, - null, xmlService, cacheConfigFactory.getCacheConfig( session ) ) ); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 7ea2fa38932e..3baf510003a6 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -62,7 +62,6 @@ import org.codehaus.plexus.logging.Logger; import static java.lang.Boolean.TRUE; -import static java.lang.Boolean.parseBoolean; import static org.apache.maven.caching.ProjectUtils.getMultimoduleRoot; /** From 3d4fba33dc5fb896f3164213d60449944583ba4c Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 16 Nov 2021 10:14:21 +0100 Subject: [PATCH 132/188] [MNG-7129] More complete fix for missing lifecycle phases, avoid warnings which cause ITs to fail --- .../java/org/apache/maven/caching/CachingMojoExecutor.java | 7 +++++-- .../java/org/apache/maven/caching/xml/CacheConfigImpl.java | 2 +- .../internal/DefaultLifecycleExecutionPlanCalculator.java | 2 -- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java index e66622c9c0ca..94ed65db5a88 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java @@ -209,7 +209,9 @@ public void execute( MavenSession session, List mojoExecutions, P { for ( MojoExecution mojoExecution : mojoExecutions ) { - if ( source == Source.CLI || isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) + if ( source == Source.CLI + || mojoExecution.getLifecyclePhase() == null + || isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } @@ -356,7 +358,8 @@ private List getCleanPhase( List mojoExecutions ) List list = new ArrayList<>(); for ( MojoExecution mojoExecution : mojoExecutions ) { - if ( isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) + if ( mojoExecution.getLifecyclePhase() == null + || isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) { break; } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 3baf510003a6..877e9c014eec 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -110,7 +110,7 @@ public CacheConfigImpl( Logger logger, XmlService xmlService, MavenSession sessi if ( !Files.exists( configPath ) ) { - logger.warn( "Cache configuration is not available at configured path " + logger.info( "Cache configuration is not available at configured path " + configPath + ", cache is disabled" ); state = CacheState.DISABLED; cacheConfig = null; diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java index 269267fdbf07..f22f028a85eb 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java @@ -591,8 +591,6 @@ private List calculateForkedGoal( MojoExecution mojoExecution, Ma MojoExecution forkedExecution = new MojoExecution( forkedMojoDescriptor, forkedGoal ); - forkedExecution.setLifecyclePhase( mojoExecution.getLifecyclePhase() ); - mojoExecutionConfigurator( forkedExecution ).configure( project, forkedExecution, true ); finalizeMojoConfiguration( forkedExecution ); From 3786a38f33debb143381f88ed15adf763696867e Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 16 Nov 2021 13:38:21 +0100 Subject: [PATCH 133/188] [MNG-7337] Remove usage of plexus logger --- .../maven/caching/CacheControllerFactory.java | 8 +- .../maven/caching/CacheControllerImpl.java | 124 ++++++--------- .../maven/caching/CachingMojoExecutor.java | 29 ++-- .../caching/HttpCacheRepositoryImpl.java | 56 +++---- .../caching/LocalCacheRepositoryFactory.java | 11 +- .../caching/LocalCacheRepositoryImpl.java | 47 +++--- .../maven/caching/MojoExecutionManager.java | 61 +++----- .../maven/caching/MojoParametersListener.java | 29 +--- .../maven/caching/RemoteCacheRepository.java | 2 +- .../caching/RemoteCacheRepositoryFactory.java | 7 +- .../caching/checksum/MavenProjectInput.java | 144 ++++++------------ .../org/apache/maven/caching/xml/Build.java | 19 +-- .../maven/caching/xml/CacheConfigFactory.java | 7 +- .../maven/caching/xml/CacheConfigImpl.java | 15 +- 14 files changed, 199 insertions(+), 360 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java index 878f34c480c3..c600c5652b27 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java @@ -30,7 +30,6 @@ import org.apache.maven.plugin.MavenPluginManager; import org.apache.maven.project.MavenProjectHelper; import org.apache.maven.repository.RepositorySystem; -import org.codehaus.plexus.logging.Logger; @Singleton @Named @@ -39,7 +38,6 @@ public class CacheControllerFactory private static final Object KEY = CacheControllerFactory.class.getName(); - private final Logger logger; private final XmlService xmlService; private final MavenPluginManager mavenPluginManager; private final MavenProjectHelper projectHelper; @@ -50,8 +48,7 @@ public class CacheControllerFactory private final RemoteCacheRepositoryFactory remoteCacheRepositoryFactory; @Inject - public CacheControllerFactory( Logger logger, - XmlService xmlService, + public CacheControllerFactory( XmlService xmlService, MavenPluginManager mavenPluginManager, MavenProjectHelper projectHelper, ArtifactHandlerManager artifactHandlerManager, @@ -60,7 +57,6 @@ public CacheControllerFactory( Logger logger, LocalCacheRepositoryFactory localCacheRepositoryFactory, RemoteCacheRepositoryFactory remoteCacheRepositoryFactory ) { - this.logger = logger; this.xmlService = xmlService; this.mavenPluginManager = mavenPluginManager; this.projectHelper = projectHelper; @@ -74,7 +70,7 @@ public CacheControllerFactory( Logger logger, public CacheController getCacheContoller( MavenSession session ) { return SessionUtils.getOrCreate( session, KEY, - () -> new CacheControllerImpl( logger, + () -> new CacheControllerImpl( mavenPluginManager, projectHelper, repoSystem, artifactHandlerManager, xmlService, diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index fdb52e5a8e16..87f499d21c6f 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -80,8 +80,9 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.apache.maven.repository.RepositorySystem; -import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.ReflectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static java.nio.file.StandardOpenOption.CREATE; import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; @@ -107,7 +108,8 @@ public class CacheControllerImpl implements CacheController private static final String GENERATEDSOURCES = "generatedsources"; private static final String GENERATEDSOURCES_PREFIX = GENERATEDSOURCES + FILE_SEPARATOR_SUBST; - private final Logger logger; + private static final Logger LOGGER = LoggerFactory.getLogger( CacheControllerImpl.class ); + private final MavenPluginManager mavenPluginManager; private final MavenProjectHelper projectHelper; private final RepositorySystem repoSystem; @@ -121,7 +123,6 @@ public class CacheControllerImpl implements CacheController private volatile Scm scm; public CacheControllerImpl( - Logger logger, MavenPluginManager mavenPluginManager, MavenProjectHelper projectHelper, RepositorySystem repoSystem, @@ -131,7 +132,6 @@ public CacheControllerImpl( RemoteCacheRepository remoteCache, CacheConfig cacheConfig ) { - this.logger = logger; this.mavenPluginManager = mavenPluginManager; this.projectHelper = projectHelper; this.localCache = localCache; @@ -155,7 +155,7 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, return empty(); } - logInfo( project, "Attempting to restore project from build cache" ); + LOGGER.info( "Attempting to restore project from build cache" ); ProjectsInputInfo inputInfo = calculateInput( project, session, projectIndex ); @@ -166,7 +166,7 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, if ( !result.isSuccess() && result.getContext() != null ) { - logDebug( project, "Remote cache is incomplete or missing, trying local build" ); + LOGGER.debug( "Remote cache is incomplete or missing, trying local build" ); CacheResult localBuild = findLocalBuild( mojoExecutions, context ); @@ -190,7 +190,7 @@ private CacheResult findCachedBuild( List mojoExecutions, CacheCo } catch ( Exception e ) { - logError( context.getProject(), "Cannot read cached build", e ); + LOGGER.error( "Cannot read cached build", e ); return cachedBuild != null ? failure( cachedBuild, context ) : failure( context ); } } @@ -205,49 +205,44 @@ private CacheResult findLocalBuild( List mojoExecutions, CacheCon } catch ( Exception e ) { - logError( context.getProject(), "Cannot read local build", e ); + LOGGER.error( "Cannot read local build", e ); return localBuild != null ? failure( localBuild, context ) : failure( context ); } } private CacheResult analyzeResult( CacheContext context, List mojoExecutions, Build info ) { - try { if ( info != null ) { - final MavenProject project = context.getProject(); final ProjectsInputInfo inputInfo = context.getInputInfo(); - logInfo( project, "Found cached build, restoring from cache " + inputInfo.getChecksum() ); - - if ( logger.isDebugEnabled() ) - { - logDebug( project, "Cached build details: " + info.toString() ); - } + LOGGER.info( "Found cached build, restoring from cache {}", inputInfo.getChecksum() ); + LOGGER.debug( "Cached build details: {}", info ); final String cacheImplementationVersion = info.getCacheImplementationVersion(); if ( !CACHE_IMPLEMENTATION_VERSION.equals( cacheImplementationVersion ) ) { - logger.warn( - "Maven and cached build implementations mismatch, caching might not work correctly. " - + "Implementation version: " + CACHE_IMPLEMENTATION_VERSION + ", cached build: " - + info.getCacheImplementationVersion() ); + LOGGER.warn( + "Maven and cached build implementations mismatch, caching might not work correctly. " + + "Implementation version: " + CACHE_IMPLEMENTATION_VERSION + ", cached build: {}", + info.getCacheImplementationVersion() ); } final List cachedSegment = info.getCachedSegment( mojoExecutions ); - - if ( !info.isAllExecutionsPresent( cachedSegment, logger ) ) + final List missingMojos = info.getMissingExecutions( cachedSegment ); + if ( !missingMojos.isEmpty() ) { - logInfo( project, "Cached build doesn't contains all requested plugin executions, cannot restore" ); + LOGGER.warn( "Cached build doesn't contains all requested plugin executions " + + "(missing: {}), cannot restore", missingMojos ); return failure( info, context ); } - if ( !isCachedSegmentPropertiesPresent( project, info, cachedSegment ) ) + if ( !isCachedSegmentPropertiesPresent( context.getProject(), info, cachedSegment ) ) { - logInfo( project, "Cached build violates cache rules, cannot restore" ); + LOGGER.info( "Cached build violates cache rules, cannot restore" ); return failure( info, context ); } @@ -256,9 +251,8 @@ private CacheResult analyzeResult( CacheContext context, List moj if ( ProjectUtils.isLaterPhase( highestRequestPhase, highestCompletedGoal ) && !canIgnoreMissingSegment( info, mojoExecutions ) ) { - logInfo( project, - "Project restored partially. Highest cached goal: " + highestCompletedGoal + ", requested: " - + highestRequestPhase ); + LOGGER.info( "Project restored partially. Highest cached goal: {}, requested: {}", + highestCompletedGoal, highestRequestPhase ); return partialSuccess( info, context ); } @@ -266,13 +260,13 @@ private CacheResult analyzeResult( CacheContext context, List moj } else { - logInfo( context.getProject(), "Project is not found in cache" ); + LOGGER.info( "Project is not found in cache" ); return empty( context ); } } catch ( Exception e ) { - logger.error( "Failed to restore project", e ); + LOGGER.error( "Failed to restore project", e ); localCache.clearCache( context ); return empty( context ); } @@ -310,10 +304,10 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) final Path artifactFile = localCache.getArtifactFile( context, cacheResult.getSource(), artifact ); if ( !Files.exists( artifactFile ) ) { - logInfo( project, "Missing file for cached build, cannot restore. File: " + artifactFile ); + LOGGER.info( "Missing file for cached build, cannot restore. File: {}", artifactFile ); return false; } - logDebug( project, "Setting project artifact " + artifact.getArtifactId() + " from: " + artifactFile ); + LOGGER.debug( "Setting project artifact {} from {}", artifact.getArtifactId(), artifactFile ); project.getArtifact().setFile( artifactFile.toFile() ); project.getArtifact().setResolved( true ); putChecksum( artifact, context.getInputInfo().getChecksum() ); @@ -328,16 +322,15 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) attachedArtifact ); if ( !Files.exists( attachedArtifactFile ) ) { - logInfo( project, - "Missing file for cached build, cannot restore project. File: " - + attachedArtifactFile ); + LOGGER.info( "Missing file for cached build, cannot restore. File: {}", + attachedArtifactFile ); project.getArtifact().setFile( null ); project.getArtifact().setResolved( false ); project.getAttachedArtifacts().clear(); return false; } - logDebug( project, - "Attaching artifact " + artifact.getArtifactId() + " from: " + attachedArtifactFile ); + LOGGER.debug( "Attaching artifact {} from {}", + artifact.getArtifactId(), attachedArtifactFile ); if ( StringUtils.startsWith( attachedArtifact.getClassifier(), GENERATEDSOURCES_PREFIX ) ) { // generated sources artifact @@ -357,7 +350,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) project.getArtifact().setFile( null ); project.getArtifact().setResolved( false ); project.getAttachedArtifacts().clear(); - logError( project, "Cannot restore cache, continuing with normal build.", e ); + LOGGER.error( "Cannot restore cache, continuing with normal build.", e ); return false; } @@ -388,7 +381,7 @@ private ProjectsInputInfo calculateInput( MavenProject project, MavenSession ses try { final MavenProjectInput inputs = new MavenProjectInput( project, session, cacheConfig, projectIndex, - artifactDigestByKey, repoSystem, artifactHandlerManager, logger, localCache, remoteCache ); + artifactDigestByKey, repoSystem, artifactHandlerManager, localCache, remoteCache ); return inputs.calculateChecksum( cacheConfig.getHashFactory() ); } catch ( Exception e ) @@ -406,7 +399,7 @@ public void save( CacheResult cacheResult, List mojoExecutions, if ( context == null || context.getInputInfo() == null ) { - logger.info( "Cannot save project in cache, skipping" ); + LOGGER.info( "Cannot save project in cache, skipping" ); return; } @@ -471,14 +464,14 @@ public void save( CacheResult cacheResult, List mojoExecutions, } catch ( Exception e ) { + LOGGER.error( "Failed to save project, cleaning cache. Project: {}", project, e ); try { - logger.error( "Failed to save project, cleaning cache. Project: " + project, e ); localCache.clearCache( context ); } catch ( Exception ex ) { - logger.error( "Failed to clean cache due to unexpected error:", e ); + LOGGER.error( "Failed to clean cache due to unexpected error:", ex ); } } } @@ -492,7 +485,7 @@ public void produceDiffReport( CacheResult cacheResult, Build build ) Build baseline = baselineHolder.get(); String outputDirectory = project.getBuild().getDirectory(); Path reportOutputDir = Paths.get( outputDirectory, "incremental-maven" ); - logInfo( project, "Saving cache builds diff to: " + reportOutputDir ); + LOGGER.info( "Saving cache builds diff to: {}", reportOutputDir ); Diff diff = new CacheDiff( build.getDto(), baseline.getDto(), cacheConfig ).compare(); try { @@ -523,12 +516,12 @@ public void produceDiffReport( CacheResult cacheResult, Build build ) } catch ( IOException e ) { - logError( project, "Cannot produce build diff for project", e ); + LOGGER.error( "Cannot produce build diff for project", e ); } } else { - logInfo( project, "Cannot find project in baseline build, skipping diff" ); + LOGGER.info( "Cannot find project in baseline build, skipping diff" ); } } @@ -615,13 +608,11 @@ private void recordMojoProperties( CompletedExecution execution, MojoExecutionEv } catch ( IllegalAccessException e ) { - logInfo( executionEvent.getProject(), - "Cannot get property " + propertyName + " value from " + mojo + ": " + e.getMessage() ); + LOGGER.info( "Cannot get property {} value from {}: {}", propertyName, mojo, e.getMessage() ); if ( tracked ) { - throw new IllegalArgumentException( - "Property configured in cache introspection config for " + mojo + " is not accessible: " - + propertyName ); + throw new IllegalArgumentException( "Property configured in cache introspection config " + + "for " + mojo + " is not accessible: " + propertyName ); } } } @@ -682,39 +673,21 @@ private boolean isCachedSegmentPropertiesPresent( MavenProject project, Build bu if ( cachedExecution == null ) { - logInfo( project, - "Execution is not cached. Plugin: " + mojoExecution.getExecutionId() + ", goal" - + mojoExecution.getGoal() ); + LOGGER.info( "Execution is not cached. Plugin: {}, goal {}", + mojoExecution.getExecutionId(), mojoExecution.getGoal() ); return false; } if ( !DtoUtils.containsAllProperties( cachedExecution, trackedProperties ) ) { - logInfo( project, "Build info doesn't match rules. Plugin: " + mojoExecution.getExecutionId() ); + LOGGER.info( "Build info doesn't match rules. Plugin: {}", + mojoExecution.getExecutionId() ); return false; } } return true; } - private void logDebug( MavenProject project, String message ) - { - if ( logger.isDebugEnabled() ) - { - logger.debug( "[CACHE][" + project.getArtifactId() + "] " + message ); - } - } - - private void logInfo( MavenProject project, String message ) - { - logger.info( "[CACHE][" + project.getArtifactId() + "] " + message ); - } - - private void logError( MavenProject project, String message, Exception e ) - { - logger.error( "[CACHE][" + project.getArtifactId() + "] " + message, e ); - } - @Override public boolean isForcedExecution( MavenProject project, MojoExecution execution ) { @@ -776,7 +749,7 @@ else if ( result.getSource() == CacheSource.BUILD && cacheConfig.isSaveToRemote( } catch ( Exception e ) { - logger.error( "Cannot save incremental build aggregated report", e ); + LOGGER.error( "Cannot save incremental build aggregated report", e ); } } @@ -795,7 +768,7 @@ private void populateGitInfo( Build build, MavenSession session ) throws IOExcep catch ( IOException e ) { scm = new Scm(); - logger.error( "Cannot populate git info", e ); + LOGGER.error( "Cannot populate git info", e ); } } } @@ -903,7 +876,7 @@ private void attachDirIfNotEmpty( Path candidateSubDir, Path parentDir, MavenPro final Path relativePath = parentDir.relativize( candidateSubDir ); final String classifier = pathToClassifier( relativePath ); zipAndAttachArtifact( project, candidateSubDir, classifier ); - logDebug( project, "Attached directory: " + candidateSubDir ); + LOGGER.debug( "Attached directory: {}", candidateSubDir ); } } @@ -934,4 +907,5 @@ private boolean isOutputArtifact( String name ) } return true; } + } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java index 94ed65db5a88..8cfc2bd0ed67 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java @@ -64,9 +64,10 @@ import org.apache.maven.plugin.PluginManagerException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; import org.eclipse.sisu.Priority; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.apache.maven.caching.ProjectUtils.isLaterPhase; import static org.apache.maven.caching.checksum.KeyUtils.getVersionlessProjectKey; @@ -84,7 +85,8 @@ @Priority( 10 ) public class CachingMojoExecutor implements IMojoExecutor { - private final Logger logger; + private static final Logger LOGGER = LoggerFactory.getLogger( CachingMojoExecutor.class ); + private final BuildPluginManager pluginManager; private final MavenPluginManager mavenPluginManager; private final LifecycleDependencyResolver lifeCycleDependencyResolver; @@ -95,8 +97,7 @@ public class CachingMojoExecutor implements IMojoExecutor @Inject public CachingMojoExecutor( - Logger logger, - BuildPluginManager pluginManager, + BuildPluginManager pluginManager, MavenPluginManager mavenPluginManager, LifecycleDependencyResolver lifeCycleDependencyResolver, ExecutionEventCatapult eventCatapult, @@ -104,7 +105,6 @@ public CachingMojoExecutor( CacheConfigFactory cacheConfigFactory, MojoParametersListener mojoListener ) { - this.logger = logger; this.pluginManager = pluginManager; this.mavenPluginManager = mavenPluginManager; this.lifeCycleDependencyResolver = lifeCycleDependencyResolver; @@ -265,9 +265,7 @@ private boolean restoreProject( CacheResult cacheResult, boolean restored = cacheController.restoreProjectArtifacts( cacheResult ); if ( !restored ) { - logger.info( - "[CACHE][" + project.getArtifactId() - + "] Cannot restore project artifacts, continuing with non cached build" ); + LOGGER.info( "Cannot restore project artifacts, continuing with non cached build" ); return false; } @@ -276,9 +274,8 @@ private boolean restoreProject( CacheResult cacheResult, if ( cacheController.isForcedExecution( project, cacheCandidate ) ) { - logger.info( - "[CACHE][" + project.getArtifactId() + "] Mojo execution is forced by project property: " - + cacheCandidate.getMojoDescriptor().getFullGoalName() ); + LOGGER.info( "Mojo execution is forced by project property: {}", + cacheCandidate.getMojoDescriptor().getFullGoalName() ); execute( session, cacheCandidate, projectIndex, dependencyContext, phaseRecorder ); } else @@ -323,10 +320,9 @@ private boolean verifyCacheConsistency( MojoExecution cacheCandidate, CacheConfig cacheConfig ) throws LifecycleExecutionException { - CacheController cacheController = cacheControllerFactory.getCacheContoller( session ); AtomicBoolean consistent = new AtomicBoolean( true ); - final MojoExecutionManager mojoChecker = new MojoExecutionManager( project, cacheController, cachedBuild, - consistent, logger, cacheConfig ); + final MojoExecutionManager mojoChecker = new MojoExecutionManager( project, cachedBuild, + consistent, cacheConfig ); if ( mojoChecker.needCheck( cacheCandidate, session ) ) { @@ -345,9 +341,8 @@ private boolean verifyCacheConsistency( MojoExecution cacheCandidate, } else { - logger.info( - "[CACHE][" + project.getArtifactId() + "] Skipping plugin execution (cached): " - + cacheCandidate.getMojoDescriptor().getFullGoalName() ); + LOGGER.info( "Skipping plugin execution (cached): {}", + cacheCandidate.getMojoDescriptor().getFullGoalName() ); } return consistent.get(); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java index 5cb3046574a9..5e0297175825 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java @@ -47,7 +47,8 @@ import org.apache.maven.caching.xml.report.ProjectReport; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.logging.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * HTTP remote cache repository implementation. @@ -58,14 +59,13 @@ public class HttpCacheRepositoryImpl implements RemoteCacheRepository public static final String BUILDINFO_XML = "buildinfo.xml"; public static final String CACHE_REPORT_XML = "cache-report.xml"; - private final Logger logger; + private static final Logger LOGGER = LoggerFactory.getLogger( HttpCacheRepositoryImpl.class ); + private final XmlService xmlService; private final CacheConfig cacheConfig; - public HttpCacheRepositoryImpl( Logger logger, - XmlService xmlService, CacheConfig cacheConfig ) + public HttpCacheRepositoryImpl( XmlService xmlService, CacheConfig cacheConfig ) { - this.logger = logger; this.xmlService = xmlService; this.cacheConfig = cacheConfig; } @@ -90,10 +90,9 @@ private static CloseableHttpClient newHttpClient() public Build findBuild( CacheContext context ) { final String resourceUrl = getResourceUrl( context, BUILDINFO_XML ); - String artifactId = context.getProject().getArtifactId(); - if ( exists( artifactId, resourceUrl ) ) + if ( exists( resourceUrl ) ) { - final byte[] bytes = getResourceContent( resourceUrl, artifactId ); + final byte[] bytes = getResourceContent( resourceUrl ); final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( bytes ); return new Build( dto, CacheSource.REMOTE ); } @@ -103,8 +102,7 @@ public Build findBuild( CacheContext context ) @Override public byte[] getArtifactContent( CacheContext context, Artifact artifact ) { - return getResourceContent( getResourceUrl( context, artifact.getFileName() ), - context.getProject().getArtifactId() ); + return getResourceContent( getResourceUrl( context, artifact.getFileName() ) ); } @Override @@ -144,7 +142,7 @@ public void saveArtifactFile( CacheResult cacheResult, } @SuppressWarnings( "checkstyle:magicnumber" ) - private boolean exists( String logReference, String url ) + private boolean exists( String url ) { HttpHead head = null; try @@ -152,7 +150,7 @@ private boolean exists( String logReference, String url ) head = new HttpHead( url ); HttpResponse response = httpClient.get().execute( head ); int statusCode = response.getStatusLine().getStatusCode(); - logger.info( "[CACHE][" + logReference + "] Checking " + url + ". Status: " + statusCode ); + LOGGER.info( "Checking {}. Status: {}", url, statusCode ); return statusCode == 200; } catch ( IOException e ) @@ -169,7 +167,7 @@ private boolean exists( String logReference, String url ) } @SuppressWarnings( "checkstyle:magicnumber" ) - public byte[] getResourceContent( String url, String logReference ) + public byte[] getResourceContent( String url ) { HttpGet get = null; try @@ -177,7 +175,7 @@ public byte[] getResourceContent( String url, String logReference ) get = new HttpGet( url ); HttpResponse response = httpClient.get().execute( get ); int statusCode = response.getStatusLine().getStatusCode(); - logger.info( "[CACHE][" + logReference + "] Downloading " + url + ". Status: " + statusCode ); + LOGGER.info( "Downloading {}. Status: {}", url, statusCode ); if ( statusCode != 200 ) { throw new RuntimeException( "Cannot download " + url + ", unexpected status code: " + statusCode ); @@ -227,7 +225,7 @@ private void putToRemoteCache( InputStream instream, String url, String logRefer httpPut.setEntity( new InputStreamEntity( instream ) ); HttpResponse response = httpClient.get().execute( httpPut ); int statusCode = response.getStatusLine().getStatusCode(); - logInfo( "Saved to remote cache " + url + ". RESPONSE CODE: " + statusCode, logReference ); + LOGGER.info( "Saved to remote cache {}. Status: {}", url, statusCode ); } finally { @@ -268,33 +266,32 @@ public Optional findBaselineBuild( MavenProject project ) if ( projectReport.getUrl() != null ) { url = cachedProjectHolder.get().getUrl(); - logInfo( "Retrieving baseline buildinfo: " + projectReport.getUrl(), project.getArtifactId() ); + LOGGER.info( "Retrieving baseline buildinfo: {}", projectReport.getUrl() ); } else { url = getResourceUrl( BUILDINFO_XML, project.getGroupId(), project.getArtifactId(), projectReport.getChecksum() ); - logInfo( "Baseline project record doesn't have url, trying default location", project.getArtifactId() ); + LOGGER.info( "Baseline project record doesn't have url, trying default location" ); } try { - if ( exists( project.getArtifactId(), url ) ) + if ( exists( url ) ) { - byte[] content = getResourceContent( url, project.getArtifactId() ); + byte[] content = getResourceContent( url ); final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( content ); return Optional.of( new Build( dto, CacheSource.REMOTE ) ); } else { - logInfo( "Project buildinfo not found, skipping diff", - project.getArtifactId() ); + LOGGER.info( "Project buildinfo not found, skipping diff" ); } } catch ( Exception e ) { - logger.warn( "[CACHE][" + project.getArtifactId() + "] Error restoring baseline build at url: " - + projectReport.getUrl() + ", skipping diff" ); + LOGGER.warn( "Error restoring baseline build at url: {}, skipping diff", + projectReport.getUrl() ); return Optional.empty(); } } @@ -308,16 +305,15 @@ private Optional findCacheInfo() { try { - logInfo( "Downloading baseline cache report from: " + cacheConfig.getBaselineCacheUrl(), - "DEBUG" ); - byte[] content = getResourceContent( cacheConfig.getBaselineCacheUrl(), "cache-info" ); + LOGGER.info( "Downloading baseline cache report from: {}", cacheConfig.getBaselineCacheUrl() ); + byte[] content = getResourceContent( cacheConfig.getBaselineCacheUrl() ); CacheReport cacheReportType = xmlService.loadCacheReport( content ); report = Optional.of( cacheReportType ); } catch ( Exception e ) { - logger.error( "Error downloading baseline report from: " + cacheConfig.getBaselineCacheUrl() - + ", skipping diff.", e ); + LOGGER.error( "Error downloading baseline report from: {}, skipping diff.", + cacheConfig.getBaselineCacheUrl(), e ); report = Optional.empty(); } cacheReportSupplier.compareAndSet( null, report ); @@ -325,8 +321,4 @@ private Optional findCacheInfo() return report; } - private void logInfo( String message, String logReference ) - { - logger.info( "[CACHE][" + logReference + "] " + message ); - } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java index 7c362d38cbad..618700750fa1 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java @@ -26,7 +26,8 @@ import org.apache.maven.caching.xml.CacheConfigFactory; import org.apache.maven.caching.xml.XmlService; import org.apache.maven.execution.MavenSession; -import org.codehaus.plexus.logging.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Singleton @Named @@ -35,17 +36,17 @@ public class LocalCacheRepositoryFactory private static final Object KEY = LocalCacheRepository.class.getName(); - private final Logger logger; + private static final Logger LOGGER = LoggerFactory.getLogger( LocalCacheRepositoryFactory.class ); + private final XmlService xmlService; private final CacheConfigFactory cacheConfigFactory; private final RemoteCacheRepositoryFactory remoteCacheRepositoryFactory; @Inject - public LocalCacheRepositoryFactory( Logger logger, XmlService xmlService, + public LocalCacheRepositoryFactory( XmlService xmlService, CacheConfigFactory cacheConfigFactory, RemoteCacheRepositoryFactory remoteCacheRepositoryFactory ) { - this.logger = logger; this.xmlService = xmlService; this.cacheConfigFactory = cacheConfigFactory; this.remoteCacheRepositoryFactory = remoteCacheRepositoryFactory; @@ -54,7 +55,7 @@ public LocalCacheRepositoryFactory( Logger logger, XmlService xmlService, public LocalCacheRepository getLocalCacheRepository( MavenSession session ) { return SessionUtils.getOrCreate( session, KEY, - () -> new LocalCacheRepositoryImpl( logger, + () -> new LocalCacheRepositoryImpl( remoteCacheRepositoryFactory.getRemoteCacheRepository( session ), xmlService, cacheConfigFactory.getCacheConfig( session ) ) ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java index 2d864a97cafc..53a3857eecde 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java @@ -51,7 +51,8 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.logging.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static java.nio.file.StandardOpenOption.CREATE; import static java.nio.file.StandardOpenOption.CREATE_NEW; @@ -76,19 +77,18 @@ public class LocalCacheRepositoryImpl implements LocalCacheRepository private static final long ONE_DAY_MILLIS = DAYS.toMillis( 1 ); private static final String EMPTY = ""; - private final Logger logger; + private static final Logger LOGGER = LoggerFactory.getLogger( LocalCacheRepositoryImpl.class ); + private final RemoteCacheRepository remoteRepository; private final XmlService xmlService; private final CacheConfig cacheConfig; private final Map, Optional> bestBuildCache = new ConcurrentHashMap<>(); public LocalCacheRepositoryImpl( - Logger logger, RemoteCacheRepository remoteRepository, XmlService xmlService, CacheConfig cacheConfig ) { - this.logger = logger; this.remoteRepository = remoteRepository; this.xmlService = xmlService; this.cacheConfig = cacheConfig; @@ -98,10 +98,10 @@ public LocalCacheRepositoryImpl( public Build findLocalBuild( CacheContext context ) throws IOException { Path localBuildInfoPath = localBuildPath( context, BUILDINFO_XML, false ); - logDebug( context, "Checking local build info: " + localBuildInfoPath ); + LOGGER.debug( "Checking local build info: {}", localBuildInfoPath ); if ( Files.exists( localBuildInfoPath ) ) { - logInfo( context, "Local build found by checksum " + context.getInputInfo().getChecksum() ); + LOGGER.info( "Local build found by checksum {}", context.getInputInfo().getChecksum() ); try { org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( localBuildInfoPath.toFile() ); @@ -109,7 +109,7 @@ public Build findLocalBuild( CacheContext context ) throws IOException } catch ( Exception e ) { - logger.error( "Local build info is not valid, deleting: " + localBuildInfoPath, e ); + LOGGER.info( "Local build info is not valid, deleting: {}", localBuildInfoPath, e ); Files.delete( localBuildInfoPath ); } } @@ -121,11 +121,11 @@ public Build findBuild( CacheContext context ) throws IOException { Path buildInfoPath = remoteBuildPath( context, BUILDINFO_XML ); - logDebug( context, "Checking if build is already downloaded: " + buildInfoPath ); + LOGGER.debug( "Checking if build is already downloaded: {}", buildInfoPath ); if ( Files.exists( buildInfoPath ) ) { - logInfo( context, "Downloaded build found by checksum " + context.getInputInfo().getChecksum() ); + LOGGER.info( "Downloaded build found by checksum {}", context.getInputInfo().getChecksum() ); try { org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( buildInfoPath.toFile() ); @@ -133,7 +133,7 @@ public Build findBuild( CacheContext context ) throws IOException } catch ( Exception e ) { - logger.error( "Downloaded build info is not valid, deleting: " + buildInfoPath, e ); + LOGGER.info( "Downloaded build info is not valid, deleting: {}", buildInfoPath, e ); Files.delete( buildInfoPath ); } } @@ -156,17 +156,17 @@ public Build findBuild( CacheContext context ) throws IOException // throttle remote cache calls, maven like if ( now < created + ONE_HOUR_MILLIS && now < lastModified + ONE_MINUTE_MILLIS ) { // fresh file, allow lookup every minute - logInfo( context, "Skipping remote lookup, last unsuccessful lookup less than 1m ago." ); + LOGGER.info( "Skipping remote lookup, last unsuccessful lookup less than 1m ago." ); return null; } else if ( now < created + ONE_DAY_MILLIS && now < lastModified + ONE_HOUR_MILLIS ) { // less than 1 day file, allow 1 per hour lookup - logInfo( context, "Skipping remote lookup, last unsuccessful lookup less than 1h ago." ); + LOGGER.info( "Skipping remote lookup, last unsuccessful lookup less than 1h ago." ); return null; } else if ( now > created + ONE_DAY_MILLIS && now < lastModified + ONE_DAY_MILLIS ) { // more than 1 day file, allow 1 per day lookup - logInfo( context, "Skipping remote lookup, last unsuccessful lookup less than 1d ago." ); + LOGGER.info( "Skipping remote lookup, last unsuccessful lookup less than 1d ago." ); return null; } } @@ -174,7 +174,7 @@ else if ( now > created + ONE_DAY_MILLIS && now < lastModified + ONE_DAY_MILLIS final Build build = remoteRepository.findBuild( context ); if ( build != null ) { - logInfo( context, "Build info downloaded from remote repo, saving to: " + buildInfoPath ); + LOGGER.info( "Build info downloaded from remote repo, saving to: {}", buildInfoPath ); Files.createDirectories( buildInfoPath.getParent() ); Files.write( buildInfoPath, xmlService.toBytes( build.getDto() ), CREATE_NEW ); } @@ -186,7 +186,7 @@ else if ( now > created + ONE_DAY_MILLIS && now < lastModified + ONE_DAY_MILLIS } catch ( Exception e ) { - logger.error( "Remote build info is not valid, cached data is not compatible", e ); + LOGGER.error( "Remote build info is not valid, cached data is not compatible", e ); return null; } } @@ -284,7 +284,8 @@ public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttrib catch ( Exception e ) { // version is unusable nothing we can do here - logger.error( "Build info is not compatible to current maven implementation: " + file ); + LOGGER.info( "Build info is not compatible to current maven " + + "implementation: {}", file, e ); } } return FileVisitResult.CONTINUE; @@ -325,7 +326,7 @@ public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttrib } catch ( IOException e ) { - logger.error( "Cannot find dependency in cache", e ); + LOGGER.info( "Cannot find dependency in cache", e ); return Optional.empty(); } } @@ -391,7 +392,7 @@ public void saveCacheReport( String buildId, MavenSession session, CacheReport c TRUNCATE_EXISTING, CREATE ); if ( cacheConfig.isRemoteCacheEnabled() && cacheConfig.isSaveToRemote() ) { - logger.info( "[CACHE] Saving cache report on build completion" ); + LOGGER.info( "Saving cache report on build completion" ); remoteRepository.saveCacheReport( buildId, session, cacheReport ); } } @@ -450,16 +451,6 @@ private Path localBuildDir( CacheContext context ) throws IOException return buildCacheDir( context ).resolve( "local" ); } - private void logDebug( CacheContext context, String message ) - { - logger.debug( "[CACHE][" + context.getProject().getArtifactId() + "] " + message ); - } - - private void logInfo( CacheContext context, String message ) - { - logger.info( "[CACHE][" + context.getProject().getArtifactId() + "] " + message ); - } - private static FileTime lastModifiedTime( Path p ) { try diff --git a/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java index 961a9c4a49f2..3da8eaad5a50 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java @@ -30,8 +30,9 @@ import org.apache.maven.plugin.MojoCheker; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.ReflectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -44,26 +45,23 @@ public class MojoExecutionManager implements MojoCheker { + private static final Logger LOGGER = LoggerFactory.getLogger( MojoExecutionManager.class ); + private final long createdTimestamp; - private final Logger logger; private final MavenProject project; private final Build build; private final AtomicBoolean consistent; - private final CacheController cacheController; private final CacheConfig cacheConfig; public MojoExecutionManager( MavenProject project, - CacheController cacheController, Build build, AtomicBoolean consistent, - Logger logger, CacheConfig cacheConfig ) + CacheConfig cacheConfig ) { this.createdTimestamp = System.currentTimeMillis(); this.project = project; - this.cacheController = cacheController; this.build = build; this.consistent = consistent; - this.logger = logger; this.cacheConfig = cacheConfig; } @@ -85,38 +83,31 @@ public boolean needCheck( MojoExecution mojoExecution, MavenSession session ) @Override public boolean check( MojoExecution execution, Mojo mojo, MavenSession session ) { - final CompletedExecution completedExecution = build.findMojoExecutionInfo( execution ); final String fullGoalName = execution.getMojoDescriptor().getFullGoalName(); - if ( completedExecution != null && !isParamsMatched( project, execution, mojo, completedExecution ) ) + if ( completedExecution != null && !isParamsMatched( execution, mojo, completedExecution ) ) { - logInfo( project, - "Mojo cached parameters mismatch with actual, forcing full project build. Mojo: " + fullGoalName ); + LOGGER.info( "Mojo cached parameters mismatch with actual, forcing full project build. Mojo: {}", + fullGoalName ); consistent.set( false ); } if ( consistent.get() ) { long elapsed = System.currentTimeMillis() - createdTimestamp; - logInfo( project, "Skipping plugin execution (reconciled in " + elapsed + " millis): " + fullGoalName ); + LOGGER.info( "Skipping plugin execution (reconciled in {} millis): {}", elapsed, fullGoalName ); } - if ( logger.isDebugEnabled() ) - { - logger.debug( - "[CACHE][" + project.getArtifactId() + "] Checked " + fullGoalName + ", resolved mojo: " + mojo - + ", cached params:" + completedExecution ); - } + LOGGER.debug( "Checked {}, resolved mojo: {}, cached params: {}", + fullGoalName, mojo, completedExecution ); return false; } - private boolean isParamsMatched( MavenProject project, - MojoExecution mojoExecution, + private boolean isParamsMatched( MojoExecution mojoExecution, Mojo mojo, CompletedExecution completedExecution ) { - List tracked = cacheConfig.getTrackedProperties( mojoExecution ); for ( TrackedProperty trackedProperty : tracked ) @@ -136,7 +127,7 @@ private boolean isParamsMatched( MavenProject project, } catch ( IllegalAccessException e ) { - logError( project, "Cannot extract plugin property " + propertyName + " from mojo " + mojo, e ); + LOGGER.error( "Cannot extract plugin property {} from mojo {}", propertyName, mojo, e ); return false; } @@ -144,35 +135,19 @@ private boolean isParamsMatched( MavenProject project, { if ( !StringUtils.equals( currentValue, trackedProperty.getSkipValue() ) ) { - logInfo( project, - "Plugin parameter mismatch found. Parameter: " + propertyName + ", expected: " - + expectedValue + ", actual: " + currentValue ); + LOGGER.info( "Plugin parameter mismatch found. Parameter: {}, expected: {}, actual: {}", + propertyName, expectedValue, currentValue ); return false; } else { - logWarn( project, - "Cache contains plugin execution with skip flag and might be incomplete. Property: " - + propertyName + ", execution: " + mojoExecutionKey( mojoExecution ) ); + LOGGER.warn( "Cache contains plugin execution with skip flag and might be incomplete. " + + "Property: {}, execution {}", + propertyName, mojoExecutionKey( mojoExecution ) ); } } } return true; } - private void logInfo( MavenProject project, String message ) - { - logger.info( "[CACHE][" + project.getArtifactId() + "] " + message ); - } - - private void logError( MavenProject project, String message, Exception e ) - { - logger.error( "[CACHE][" + project.getArtifactId() + "] " + message, e ); - } - - private void logWarn( MavenProject project, String message ) - { - logger.warn( "[CACHE][" + project.getArtifactId() + "] " + message ); - } - } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java index 9f1de6d23d95..cdea6cd48c88 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java @@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -31,7 +30,8 @@ import org.apache.maven.execution.MojoExecutionListener; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.logging.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * MojoParametersListener @@ -41,23 +41,16 @@ public class MojoParametersListener implements MojoExecutionListener { + private static final Logger LOGGER = LoggerFactory.getLogger( MojoParametersListener.class ); + private final ConcurrentMap> projectExecutions = new ConcurrentHashMap<>(); - private final Logger logger; - - @Inject - public MojoParametersListener( Logger logger ) - { - this.logger = logger; - } - @Override public void beforeMojoExecution( MojoExecutionEvent event ) { final String executionKey = ProjectUtils.mojoExecutionKey( event.getExecution() ); - logDebug( event.getProject(), - "Starting mojo execution: " + executionKey + ", class: " + event.getMojo().getClass() ); + LOGGER.debug( "Starting mojo execution: {}, class: {}", executionKey, event.getMojo().getClass() ); final MavenProject project = event.getProject(); Map projectEvents = projectExecutions.get( project ); if ( projectEvents == null ) @@ -94,16 +87,4 @@ public void remove( MavenProject project ) projectExecutions.remove( project ); } - private void logDebug( MavenProject project, String message ) - { - if ( logger.isDebugEnabled() ) - { - logger.debug( "[CACHE][" + project.getArtifactId() + "] " + message ); - } - } - - // private void logInfo(String message) { - // logger.info("[CACHE][" + project.getArtifactId() + "] " + message); - // } - } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java index f2b3fffe16db..c09f71193ecf 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java @@ -34,7 +34,7 @@ public interface RemoteCacheRepository extends CacheRepository byte[] getArtifactContent( CacheContext context, Artifact artifact ) throws IOException; - byte[] getResourceContent( String resourceUrl, String logReference ); + byte[] getResourceContent( String resourceUrl ); String getResourceUrl( CacheContext context, String filename ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java index 80bda4d526a1..d2743d7334b7 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java @@ -26,7 +26,6 @@ import org.apache.maven.caching.xml.CacheConfigFactory; import org.apache.maven.caching.xml.XmlService; import org.apache.maven.execution.MavenSession; -import org.codehaus.plexus.logging.Logger; @Singleton @Named @@ -35,14 +34,12 @@ public class RemoteCacheRepositoryFactory private static final Object KEY = RemoteCacheRepositoryFactory.class.getName(); - private final Logger logger; private final XmlService xmlService; private final CacheConfigFactory cacheConfigFactory; @Inject - public RemoteCacheRepositoryFactory( Logger logger, XmlService xmlService, CacheConfigFactory cacheConfigFactory ) + public RemoteCacheRepositoryFactory( XmlService xmlService, CacheConfigFactory cacheConfigFactory ) { - this.logger = logger; this.xmlService = xmlService; this.cacheConfigFactory = cacheConfigFactory; } @@ -50,7 +47,7 @@ public RemoteCacheRepositoryFactory( Logger logger, XmlService xmlService, Cache public RemoteCacheRepository getRemoteCacheRepository( MavenSession session ) { return SessionUtils.getOrCreate( session, KEY, - () -> new HttpCacheRepositoryImpl( logger, + () -> new HttpCacheRepositoryImpl( xmlService, cacheConfigFactory.getCacheConfig( session ) ) ); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index e17811e8e4a2..9f909f55f99c 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -32,7 +32,6 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; @@ -81,10 +80,11 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; -import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.apache.commons.lang3.StringUtils.contains; import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; @@ -131,7 +131,8 @@ public class MavenProjectInput */ private static final String CACHE_PROCESS_PLUGINS = "remote.cache.processPlugins"; - private final Logger logger; + private static final Logger LOGGER = LoggerFactory.getLogger( MavenProjectInput.class ); + private final MavenProject project; private final MavenSession session; private final LocalCacheRepository localCache; @@ -156,7 +157,6 @@ public MavenProjectInput( MavenProject project, ConcurrentMap artifactsByKey, RepositorySystem repoSystem, ArtifactHandlerManager artifactHandlerManager, - Logger logger, LocalCacheRepository localCache, RemoteCacheRepository remoteCache ) { @@ -168,7 +168,6 @@ public MavenProjectInput( MavenProject project, this.baseDirPath = project.getBasedir().toPath().toAbsolutePath(); this.repoSystem = repoSystem; this.artifactHandlerManager = artifactHandlerManager; - this.logger = logger; this.localCache = localCache; this.remoteCache = remoteCache; Properties properties = project.getProperties(); @@ -241,7 +240,7 @@ public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOE } if ( compareWithBaseline ) { - logInfo( "Source code: " + ( sourcesMatched ? "MATCHED" : "OUT OF DATE" ) ); + LOGGER.info( "Source code: {}", sourcesMatched ? "MATCHED" : "OUT OF DATE" ); } boolean dependenciesMatched = true; @@ -258,7 +257,7 @@ public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOE if ( compareWithBaseline ) { - logInfo( "Dependencies: " + ( dependenciesMatched ? "MATCHED" : "OUT OF DATE" ) ); + LOGGER.info( "Dependencies: {}", dependenciesMatched ? "MATCHED" : "OUT OF DATE" ); } final ProjectsInputInfo projectsInputInfoType = new ProjectsInputInfo(); @@ -267,17 +266,12 @@ public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOE final long checksumTime = Clock.elapsed( time ); - if ( logger.isDebugEnabled() ) + for ( DigestItem item : projectsInputInfoType.getItems() ) { - for ( DigestItem item : projectsInputInfoType.getItems() ) - { - logger.debug( "Hash calculated, item: " + item.getType() + ", hash: " + item.getHash() ); - } + LOGGER.debug( "Hash calculated, item: {}, hash: {}", item.getType(), item.getHash() ); } - logInfo( - "Project inputs calculated in " + inputTime + " ms. " + hashFactory.getAlgorithm() - + " checksum [" + projectsInputInfoType.getChecksum() + "] calculated in " - + checksumTime + " ms." ); + LOGGER.info( "Project inputs calculated in {} ms. {} checksum [{}] calculated in {} ms.", + inputTime, hashFactory.getAlgorithm(), projectsInputInfoType.getChecksum(), checksumTime ); return projectsInputInfoType; } @@ -299,11 +293,10 @@ private void checkEffectivePomMatch( ProjectsInputInfo baselineBuild, DigestItem final boolean matches = StringUtils.equals( pomItem.getHash(), effectivePomChecksum.getHash() ); if ( !matches ) { - logInfo( - "Mismatch in effective poms. Current: " + effectivePomChecksum.getHash() + ", remote: " - + pomItem.getHash() ); + LOGGER.info( "Mismatch in effective poms. Current: {}, remote: {}", + effectivePomChecksum.getHash(), pomItem.getHash() ); } - logInfo( "Effective pom: " + ( matches ? "MATCHED" : "OUT OF DATE" ) ); + LOGGER.info( "Effective pom: {}", matches ? "MATCHED" : "OUT OF DATE" ); } } @@ -327,16 +320,14 @@ private boolean checkItemMatchesBaseline( ProjectsInputInfo baselineBuild, Diges matched = StringUtils.equals( hash, fileDigest.getHash() ); if ( !matched ) { - logInfo( - "Mismatch in " + fileDigest.getType() + ": " + fileDigest.getValue() + ". Local hash: " - + fileDigest.getHash() + ", remote: " + hash ); + LOGGER.info( "Mismatch in {}: {}. Local hash: {}, remote: {}", + fileDigest.getType(), fileDigest.getValue(), fileDigest.getHash(), hash ); } } else { - logInfo( - "Mismatch in " + fileDigest.getType() + ": " + fileDigest.getValue() - + ". Not found in remote cache" ); + LOGGER.info( "Mismatch in {}: {}. Not found in remote cache", + fileDigest.getType(), fileDigest.getValue() ); } return matched; } @@ -354,7 +345,7 @@ private String getEffectivePom( Model prototype ) throws IOException toHash.setVersion( prototype.getVersion() ); toHash.setModules( prototype.getModules() ); - Collections.sort( prototype.getDependencies(), dependencyComparator ); + prototype.getDependencies().sort( dependencyComparator ); toHash.setDependencies( prototype.getDependencies() ); PluginManagement pluginManagement = prototype.getBuild().getPluginManagement(); @@ -430,9 +421,9 @@ private SortedSet getInputFiles() long walkKnownPathsFinished = System.currentTimeMillis() - start; - String message = processPlugins ? "enabled, values will be checked for presence in file system" : "disabled, " - + "only tags with attribute " + CACHE_INPUT_NAME + "=\"true\" will be added"; - logInfo( "Scanning plugins configurations to find input files. Probing is " + message ); + LOGGER.info( "Scanning plugins configurations to find input files. Probing is {}", processPlugins + ? "enabled, values will be checked for presence in file system" + : "disabled, only tags with attribute " + CACHE_INPUT_NAME + "=\"true\" will be added" ); if ( processPlugins ) { @@ -440,7 +431,7 @@ private SortedSet getInputFiles() } else { - logInfo( "Skipping check plugins scan (probing is disabled by config)" ); + LOGGER.info( "Skipping check plugins scan (probing is disabled by config)" ); } long pluginsFinished = System.currentTimeMillis() - start - walkKnownPathsFinished; @@ -451,13 +442,9 @@ private SortedSet getInputFiles() sorted.add( collectedFile.normalize().toAbsolutePath() ); } - logInfo( - "Found " + sorted.size() + " input files. Project dir processing: " + walkKnownPathsFinished - + ", plugins: " + pluginsFinished + " millis" ); - if ( logger.isDebugEnabled() ) - { - logDebug( "Src input: " + sorted ); - } + LOGGER.info( "Found {} input files. Project dir processing: {}, plugins: {} millis", + sorted.size(), walkKnownPathsFinished, pluginsFinished ); + LOGGER.debug( "Src input: {}", sorted ); return sorted; } @@ -500,10 +487,7 @@ private void startWalk( Path candidate, { if ( !isFilteredOutSubpath( normalized ) ) { - if ( logger.isDebugEnabled() ) - { - logDebug( "Adding: " + normalized ); - } + LOGGER.debug( "Adding: {}", normalized ); collectedFiles.add( normalized ); } } @@ -525,12 +509,12 @@ private void collectFromPlugins( List files, HashSet visitedDirs if ( scanConfig.isSkip() ) { - logDebug( "Skipping plugin config scan (skip by config): " + plugin.getArtifactId() ); + LOGGER.debug( "Skipping plugin config scan (skip by config): {}", plugin.getArtifactId() ); continue; } Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); - logDebug( "Processing plugin config: " + plugin.getArtifactId() ); + LOGGER.debug( "Processing plugin config: {}", plugin.getArtifactId() ); if ( configuration != null ) { addInputsFromPluginConfigs( configuration.getChildren(), scanConfig, files, visitedDirs ); @@ -544,14 +528,13 @@ private void collectFromPlugins( List files, HashSet visitedDirs if ( mergedConfig.isSkip() ) { - logDebug( - "Skipping plugin execution config scan (skip by config): " - + plugin.getArtifactId() + ", execId: " + exec.getId() ); + LOGGER.debug( "Skipping plugin execution config scan (skip by config): {}, execId: {}", + plugin.getArtifactId(), exec.getId() ); continue; } Xpp3Dom execConfiguration = (Xpp3Dom) exec.getConfiguration(); - logDebug( "Processing plugin: " + plugin.getArtifactId() + ", execution: " + exec.getId() ); + LOGGER.debug( "Processing plugin: {}, execution: {}", plugin.getArtifactId(), exec.getId() ); if ( execConfiguration != null ) { @@ -575,26 +558,17 @@ public FileVisitResult preVisitDirectory( Path path, key.isRecursive() ); if ( isHidden( path ) ) { - if ( logger.isDebugEnabled() ) - { - logDebug( "Skipping subtree (hidden): " + path ); - } + LOGGER.debug( "Skipping subtree (hidden): {}", path ); return FileVisitResult.SKIP_SUBTREE; } else if ( isFilteredOutSubpath( path ) ) { - if ( logger.isDebugEnabled() ) - { - logDebug( "Skipping subtree (blacklisted): " + path ); - } + LOGGER.debug( "Skipping subtree (blacklisted): {}", path ); return FileVisitResult.SKIP_SUBTREE; } else if ( visitedDirs.contains( currentDirKey ) ) { - if ( logger.isDebugEnabled() ) - { - logDebug( "Skipping subtree (visited): " + path ); - } + LOGGER.debug( "Skipping subtree (visited): {}", path ); return FileVisitResult.SKIP_SUBTREE; } @@ -602,17 +576,11 @@ else if ( visitedDirs.contains( currentDirKey ) ) if ( !key.isRecursive() ) { - if ( logger.isDebugEnabled() ) - { - logDebug( "Skipping subtree (non recursive): " + path ); - } + LOGGER.debug( "Skipping subtree (non recursive): {}", path ); return FileVisitResult.SKIP_SUBTREE; } - if ( logger.isDebugEnabled() ) - { - logDebug( "Visiting subtree: " + path ); - } + LOGGER.debug( "Visiting subtree: {}", path ); return FileVisitResult.CONTINUE; } } ); @@ -631,16 +599,17 @@ private void addInputsFromPluginConfigs( Xpp3Dom[] configurationChildren, for ( Xpp3Dom configChild : configurationChildren ) { - String tagValue = configChild.getValue(); String tagName = configChild.getName(); + String tagValue = configChild.getValue(); if ( !scanConfig.accept( tagName ) ) { - logDebug( "Skipping property (scan config)): " + tagName + ", value: " + stripToEmpty( tagValue ) ); + LOGGER.debug( "Skipping property (scan config)): {}, value: {}", + tagName, stripToEmpty( tagValue ) ); continue; } - logDebug( "Checking xml tag. Tag: " + tagName + ", value: " + stripToEmpty( tagValue ) ); + LOGGER.debug( "Checking xml tag. Tag: {}, value: {}", tagName, stripToEmpty( tagValue ) ); addInputsFromPluginConfigs( configChild.getChildren(), scanConfig, files, visitedDirs ); @@ -648,9 +617,8 @@ private void addInputsFromPluginConfigs( Xpp3Dom[] configurationChildren, final String glob = defaultIfEmpty( propertyConfig.getGlob(), dirGlob ); if ( "true".equals( configChild.getAttribute( CACHE_INPUT_NAME ) ) ) { - logInfo( - "Found tag marked with " + CACHE_INPUT_NAME + " attribute. Tag: " + tagName - + ", value: " + tagValue ); + LOGGER.info( "Found tag marked with {} attribute. Tag: {}, value: {}", + CACHE_INPUT_NAME, tagName, tagValue ); startWalk( Paths.get( tagValue ), glob, propertyConfig.isRecursive(), files, visitedDirs ); } else @@ -690,29 +658,10 @@ private Path getPathOrNull( String text ) { } } - if ( logger.isDebugEnabled() ) - { - logDebug( text + ( blacklisted ? ": skipped(blacklisted literal)" : ": invalid path" ) ); - } + LOGGER.debug( "{}: {}", text, blacklisted ? "skipped(blacklisted literal)" : "invalid path" ); return null; } - private void logDebug( String message ) - { - if ( logger.isDebugEnabled() ) - { - logger.debug( "[CACHE][" + project.getArtifactId() + "] " + message ); - } - } - - private void logInfo( String message ) - { - if ( logger.isInfoEnabled() ) - { - logger.info( "[CACHE][" + project.getArtifactId() + "] " + message ); - } - } - static void walkDirectoryFiles( Path dir, List collectedFiles, String glob ) { if ( !Files.isDirectory( dir ) ) @@ -905,7 +854,7 @@ private List normalizePlugins( List plugins ) Xpp3Dom config = (Xpp3Dom) execution.getConfiguration(); removeBlacklistedAttributes( config, excludeProperties ); } - Collections.sort( plugin.getDependencies(), dependencyComparator ); + plugin.getDependencies().sort( dependencyComparator ); } return plugins; } @@ -930,11 +879,6 @@ private void removeBlacklistedAttributes( Xpp3Dom node, List excludeProp } } - public Logger getLogger() - { - return logger; - } - public CacheConfig getConfig() { return config; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java index d00750a6b410..91f0c5caa755 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java @@ -29,7 +29,6 @@ import org.apache.maven.caching.xml.build.ProjectsInputInfo; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecution; -import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; import java.io.IOException; @@ -40,6 +39,7 @@ import java.util.Date; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import static org.apache.maven.caching.ProjectUtils.isLaterPhase; import static org.apache.maven.caching.ProjectUtils.mojoExecutionKey; @@ -107,18 +107,11 @@ public static List createAttachedArtifacts( List mojos, Logger logger ) + public List getMissingExecutions( List mojos ) { - for ( MojoExecution mojo : mojos ) - { - // TODO for strict check we might want exact match - if ( !hasCompletedExecution( mojoExecutionKey( mojo ) ) ) - { - logger.error( "Build mojo is not cached: " + mojo ); - return false; - } - } - return true; + return mojos.stream() + .filter( mojo -> !hasCompletedExecution( mojoExecutionKey( mojo ) ) ) + .collect( Collectors.toList() ); } private boolean hasCompletedExecution( String mojoExecutionKey ) @@ -128,7 +121,7 @@ private boolean hasCompletedExecution( String mojoExecutionKey ) { for ( CompletedExecution completedExecution : completedExecutions ) { - if ( StringUtils.equals( completedExecution.getExecutionKey(), mojoExecutionKey ) ) + if ( Objects.equals( completedExecution.getExecutionKey(), mojoExecutionKey ) ) { return true; } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java index 980bb610033e..bf82077d882d 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java @@ -25,7 +25,6 @@ import org.apache.maven.caching.SessionUtils; import org.apache.maven.execution.MavenSession; -import org.codehaus.plexus.logging.Logger; @Singleton @Named @@ -34,19 +33,17 @@ public class CacheConfigFactory private static final Object KEY = CacheConfigFactory.class.getName(); - private final Logger logger; private final XmlService xmlService; @Inject - public CacheConfigFactory( Logger logger, XmlService xmlService ) + public CacheConfigFactory( XmlService xmlService ) { - this.logger = logger; this.xmlService = xmlService; } public CacheConfig getCacheConfig( MavenSession session ) { - return SessionUtils.getOrCreate( session, KEY, () -> new CacheConfigImpl( logger, xmlService, session ) ); + return SessionUtils.getOrCreate( session, KEY, () -> new CacheConfigImpl( xmlService, session ) ); } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 877e9c014eec..3ea2cfd2c7b3 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -59,7 +59,8 @@ import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; import org.apache.maven.plugin.MojoExecution; -import org.codehaus.plexus.logging.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static java.lang.Boolean.TRUE; import static org.apache.maven.caching.ProjectUtils.getMultimoduleRoot; @@ -76,19 +77,21 @@ public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig public static final String FAIL_FAST_PROPERTY_NAME = "remote.cache.failFast"; public static final String BASELINE_BUILD_URL_PROPERTY_NAME = "remote.cache.baselineUrl"; + private static final Logger LOGGER = LoggerFactory.getLogger( CacheConfigImpl.class ); + private final MavenSession session; private final CacheState state; private final CacheConfig cacheConfig; private final HashFactory hashFactory; private final List excludePatterns; - public CacheConfigImpl( Logger logger, XmlService xmlService, MavenSession session ) + public CacheConfigImpl( XmlService xmlService, MavenSession session ) { this.session = session; if ( !Features.caching( session.getUserProperties() ).isActive() ) { - logger.info( "Cache disabled by command line flag, project will be built fully and not cached" ); + LOGGER.info( "Cache disabled by command line flag, project will be built fully and not cached" ); state = CacheState.DISABLED; cacheConfig = null; hashFactory = null; @@ -110,7 +113,7 @@ public CacheConfigImpl( Logger logger, XmlService xmlService, MavenSession sessi if ( !Files.exists( configPath ) ) { - logger.info( "Cache configuration is not available at configured path " + LOGGER.info( "Cache configuration is not available at configured path " + configPath + ", cache is disabled" ); state = CacheState.DISABLED; cacheConfig = null; @@ -121,7 +124,7 @@ public CacheConfigImpl( Logger logger, XmlService xmlService, MavenSession sessi { try { - logger.info( "Loading cache configuration from " + configPath ); + LOGGER.info( "Loading cache configuration from " + configPath ); cacheConfig = xmlService.loadCacheConfig( configPath.toFile() ); } catch ( Exception e ) @@ -143,7 +146,7 @@ public CacheConfigImpl( Logger logger, XmlService xmlService, MavenSession sessi { hashAlgorithm = getConfiguration().getHashAlgorithm(); hashFactory = HashFactory.of( hashAlgorithm ); - logger.info( "Using " + hashAlgorithm + " hash algorithm for cache" ); + LOGGER.info( "Using " + hashAlgorithm + " hash algorithm for cache" ); } catch ( Exception e ) { From 3a42b61b6a4001619aae3766655e431987489c38 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 16 Nov 2021 15:31:24 +0100 Subject: [PATCH 134/188] [MNG-7129] Use @SessionScoped annotation --- .../maven/caching/CacheControllerFactory.java | 82 ------------------- .../maven/caching/CacheControllerImpl.java | 6 ++ .../apache/maven/caching/CacheEventSpy.java | 23 ++---- .../maven/caching/CachingMojoExecutor.java | 20 ++--- .../caching/HttpCacheRepositoryImpl.java | 7 ++ .../caching/LocalCacheRepositoryFactory.java | 64 --------------- .../caching/LocalCacheRepositoryImpl.java | 7 ++ .../caching/RemoteCacheRepositoryFactory.java | 55 ------------- .../maven/caching/xml/CacheConfigImpl.java | 6 ++ 9 files changed, 43 insertions(+), 227 deletions(-) delete mode 100644 maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java delete mode 100644 maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java delete mode 100644 maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java deleted file mode 100644 index c600c5652b27..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerFactory.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; -import org.apache.maven.caching.xml.CacheConfigFactory; -import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.MavenPluginManager; -import org.apache.maven.project.MavenProjectHelper; -import org.apache.maven.repository.RepositorySystem; - -@Singleton -@Named -public class CacheControllerFactory -{ - - private static final Object KEY = CacheControllerFactory.class.getName(); - - private final XmlService xmlService; - private final MavenPluginManager mavenPluginManager; - private final MavenProjectHelper projectHelper; - private final ArtifactHandlerManager artifactHandlerManager; - private final RepositorySystem repoSystem; - private final CacheConfigFactory cacheConfigFactory; - private final LocalCacheRepositoryFactory localCacheRepositoryFactory; - private final RemoteCacheRepositoryFactory remoteCacheRepositoryFactory; - - @Inject - public CacheControllerFactory( XmlService xmlService, - MavenPluginManager mavenPluginManager, - MavenProjectHelper projectHelper, - ArtifactHandlerManager artifactHandlerManager, - RepositorySystem repoSystem, - CacheConfigFactory cacheConfigFactory, - LocalCacheRepositoryFactory localCacheRepositoryFactory, - RemoteCacheRepositoryFactory remoteCacheRepositoryFactory ) - { - this.xmlService = xmlService; - this.mavenPluginManager = mavenPluginManager; - this.projectHelper = projectHelper; - this.artifactHandlerManager = artifactHandlerManager; - this.repoSystem = repoSystem; - this.cacheConfigFactory = cacheConfigFactory; - this.localCacheRepositoryFactory = localCacheRepositoryFactory; - this.remoteCacheRepositoryFactory = remoteCacheRepositoryFactory; - } - - public CacheController getCacheContoller( MavenSession session ) - { - return SessionUtils.getOrCreate( session, KEY, - () -> new CacheControllerImpl( - mavenPluginManager, projectHelper, - repoSystem, artifactHandlerManager, - xmlService, - localCacheRepositoryFactory.getLocalCacheRepository( session ), - remoteCacheRepositoryFactory.getRemoteCacheRepository( session ), - cacheConfigFactory.getCacheConfig( session ) ) ); - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 87f499d21c6f..cf7c591103bd 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -44,11 +44,14 @@ import java.util.regex.Pattern; import javax.annotation.Nonnull; +import javax.inject.Inject; +import javax.inject.Named; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.mutable.MutableBoolean; +import org.apache.maven.SessionScoped; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.caching.checksum.KeyUtils; @@ -101,6 +104,8 @@ /** * CacheControllerImpl */ +@SessionScoped +@Named public class CacheControllerImpl implements CacheController { @@ -122,6 +127,7 @@ public class CacheControllerImpl implements CacheController private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); private volatile Scm scm; + @Inject public CacheControllerImpl( MavenPluginManager mavenPluginManager, MavenProjectHelper projectHelper, diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java index b0ffe050db04..5545b29c2e1c 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java @@ -19,15 +19,13 @@ * under the License. */ -import javax.inject.Inject; import javax.inject.Named; +import javax.inject.Provider; import javax.inject.Singleton; import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.CacheConfigFactory; import org.apache.maven.eventspy.AbstractEventSpy; import org.apache.maven.execution.ExecutionEvent; -import org.apache.maven.execution.MavenSession; /** * Triggers cache report generation on build completion @@ -36,14 +34,14 @@ @Named public class CacheEventSpy extends AbstractEventSpy { - private final CacheConfigFactory cacheConfigFactory; - private final CacheControllerFactory cacheControllerFactory; + // Use Providers to bridge the @SessionScope, as the EventSpy can't be scoped + private final Provider cacheConfig; + private final Provider cacheController; - @Inject - public CacheEventSpy( CacheConfigFactory cacheConfigFactory, CacheControllerFactory cacheControllerFactory ) + public CacheEventSpy( Provider cacheConfig, Provider cacheController ) { - this.cacheConfigFactory = cacheConfigFactory; - this.cacheControllerFactory = cacheControllerFactory; + this.cacheConfig = cacheConfig; + this.cacheController = cacheController; } @Override @@ -54,12 +52,9 @@ public void onEvent( Object event ) throws Exception ExecutionEvent executionEvent = (ExecutionEvent) event; if ( executionEvent.getType() == ExecutionEvent.Type.SessionEnded ) { - MavenSession session = executionEvent.getSession(); - CacheConfig cacheConfig = cacheConfigFactory.getCacheConfig( session ); - if ( cacheConfig.isEnabled() ) + if ( cacheConfig.get().isEnabled() ) { - CacheController cacheController = cacheControllerFactory.getCacheContoller( session ); - cacheController.saveCacheReport( executionEvent.getSession() ); + cacheController.get().saveCacheReport( executionEvent.getSession() ); } } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java index 8cfc2bd0ed67..36e8ff0b5650 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java @@ -31,14 +31,13 @@ import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Singleton; +import org.apache.maven.SessionScoped; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter; import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.CacheConfigFactory; import org.apache.maven.caching.xml.CacheState; import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.MavenSession; @@ -80,7 +79,7 @@ * Cache-enabled version of the MojoExecutor *

    */ -@Singleton +@SessionScoped @Named @Priority( 10 ) public class CachingMojoExecutor implements IMojoExecutor @@ -91,8 +90,8 @@ public class CachingMojoExecutor implements IMojoExecutor private final MavenPluginManager mavenPluginManager; private final LifecycleDependencyResolver lifeCycleDependencyResolver; private final ExecutionEventCatapult eventCatapult; - private final CacheControllerFactory cacheControllerFactory; - private final CacheConfigFactory cacheConfigFactory; + private final CacheController cacheController; + private final CacheConfig cacheConfig; private final MojoParametersListener mojoListener; @Inject @@ -101,16 +100,16 @@ public CachingMojoExecutor( MavenPluginManager mavenPluginManager, LifecycleDependencyResolver lifeCycleDependencyResolver, ExecutionEventCatapult eventCatapult, - CacheControllerFactory cacheControllerFactory, - CacheConfigFactory cacheConfigFactory, + CacheController cacheController, + CacheConfig cacheConfig, MojoParametersListener mojoListener ) { this.pluginManager = pluginManager; this.mavenPluginManager = mavenPluginManager; this.lifeCycleDependencyResolver = lifeCycleDependencyResolver; this.eventCatapult = eventCatapult; - this.cacheControllerFactory = cacheControllerFactory; - this.cacheConfigFactory = cacheConfigFactory; + this.cacheController = cacheController; + this.cacheConfig = cacheConfig; this.mojoListener = mojoListener; } @@ -172,7 +171,6 @@ else if ( Artifact.SCOPE_TEST.equals( classpath ) ) public void execute( MavenSession session, List mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { - CacheController cacheController = cacheControllerFactory.getCacheContoller( session ); DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); @@ -181,7 +179,6 @@ public void execute( MavenSession session, List mojoExecutions, P final Source source = getSource( mojoExecutions ); // execute clean bound goals before restoring to not interfere/slowdown clean - CacheConfig cacheConfig = cacheConfigFactory.getCacheConfig( session ); CacheState cacheState = DISABLED; CacheResult result = CacheResult.empty(); if ( source == Source.LIFECYCLE ) @@ -260,7 +257,6 @@ private boolean restoreProject( CacheResult cacheResult, final MavenProject project = cacheResult.getContext().getProject(); final MavenSession session = cacheResult.getContext().getSession(); final List cachedSegment = build.getCachedSegment( mojoExecutions ); - CacheController cacheController = cacheControllerFactory.getCacheContoller( session ); boolean restored = cacheController.restoreProjectArtifacts( cacheResult ); if ( !restored ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java index 5e0297175825..2d19c7899180 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java @@ -27,6 +27,9 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; +import javax.inject.Inject; +import javax.inject.Named; + import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -37,6 +40,7 @@ import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.maven.SessionScoped; import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; @@ -53,6 +57,8 @@ /** * HTTP remote cache repository implementation. */ +@SessionScoped +@Named public class HttpCacheRepositoryImpl implements RemoteCacheRepository { @@ -64,6 +70,7 @@ public class HttpCacheRepositoryImpl implements RemoteCacheRepository private final XmlService xmlService; private final CacheConfig cacheConfig; + @Inject public HttpCacheRepositoryImpl( XmlService xmlService, CacheConfig cacheConfig ) { this.xmlService = xmlService; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java deleted file mode 100644 index 618700750fa1..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.caching.xml.CacheConfigFactory; -import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.execution.MavenSession; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Singleton -@Named -public class LocalCacheRepositoryFactory -{ - - private static final Object KEY = LocalCacheRepository.class.getName(); - - private static final Logger LOGGER = LoggerFactory.getLogger( LocalCacheRepositoryFactory.class ); - - private final XmlService xmlService; - private final CacheConfigFactory cacheConfigFactory; - private final RemoteCacheRepositoryFactory remoteCacheRepositoryFactory; - - @Inject - public LocalCacheRepositoryFactory( XmlService xmlService, - CacheConfigFactory cacheConfigFactory, - RemoteCacheRepositoryFactory remoteCacheRepositoryFactory ) - { - this.xmlService = xmlService; - this.cacheConfigFactory = cacheConfigFactory; - this.remoteCacheRepositoryFactory = remoteCacheRepositoryFactory; - } - - public LocalCacheRepository getLocalCacheRepository( MavenSession session ) - { - return SessionUtils.getOrCreate( session, KEY, - () -> new LocalCacheRepositoryImpl( - remoteCacheRepositoryFactory.getRemoteCacheRepository( session ), - xmlService, - cacheConfigFactory.getCacheConfig( session ) ) ); - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java index 53a3857eecde..58a2e3f0340e 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java @@ -38,8 +38,12 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import javax.inject.Inject; +import javax.inject.Named; + import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.tuple.Pair; +import org.apache.maven.SessionScoped; import org.apache.maven.caching.Utils.MultiMap; import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; @@ -67,6 +71,8 @@ /** * Local cache repository implementation. */ +@SessionScoped +@Named public class LocalCacheRepositoryImpl implements LocalCacheRepository { @@ -84,6 +90,7 @@ public class LocalCacheRepositoryImpl implements LocalCacheRepository private final CacheConfig cacheConfig; private final Map, Optional> bestBuildCache = new ConcurrentHashMap<>(); + @Inject public LocalCacheRepositoryImpl( RemoteCacheRepository remoteRepository, XmlService xmlService, diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java deleted file mode 100644 index d2743d7334b7..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.caching.xml.CacheConfigFactory; -import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.execution.MavenSession; - -@Singleton -@Named -public class RemoteCacheRepositoryFactory -{ - - private static final Object KEY = RemoteCacheRepositoryFactory.class.getName(); - - private final XmlService xmlService; - private final CacheConfigFactory cacheConfigFactory; - - @Inject - public RemoteCacheRepositoryFactory( XmlService xmlService, CacheConfigFactory cacheConfigFactory ) - { - this.xmlService = xmlService; - this.cacheConfigFactory = cacheConfigFactory; - } - - public RemoteCacheRepository getRemoteCacheRepository( MavenSession session ) - { - return SessionUtils.getOrCreate( session, KEY, - () -> new HttpCacheRepositoryImpl( - xmlService, - cacheConfigFactory.getCacheConfig( session ) ) ); - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 3ea2cfd2c7b3..ca6edac4c815 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -28,8 +28,11 @@ import java.util.regex.Pattern; import javax.annotation.Nonnull; +import javax.inject.Inject; +import javax.inject.Named; import org.apache.commons.lang3.StringUtils; +import org.apache.maven.SessionScoped; import org.apache.maven.caching.DefaultPluginScanConfig; import org.apache.maven.caching.PluginScanConfig; import org.apache.maven.caching.PluginScanConfigImpl; @@ -68,6 +71,8 @@ /** * CacheConfigImpl */ +@SessionScoped +@Named public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig { @@ -85,6 +90,7 @@ public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig private final HashFactory hashFactory; private final List excludePatterns; + @Inject public CacheConfigImpl( XmlService xmlService, MavenSession session ) { this.session = session; From 8af92201467dad5c975bb53d7bf73571e6a2888b Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 16 Nov 2021 15:50:42 +0100 Subject: [PATCH 135/188] Fix wrong usage of `project.getAttachedArtifacts().clear()` --- .../maven/caching/CacheControllerImpl.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index cf7c591103bd..e81f498e2adb 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -20,6 +20,7 @@ */ import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -82,6 +83,7 @@ import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; +import org.apache.maven.project.artifact.AttachedArtifact; import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.util.ReflectionUtils; import org.slf4j.Logger; @@ -304,6 +306,8 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) try { + File file = null; + List artifacts = new ArrayList<>(); if ( isNotBlank( artifact.getFileName() ) ) { // TODO if remote is forced, probably need to refresh or reconcile all files @@ -314,8 +318,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) return false; } LOGGER.debug( "Setting project artifact {} from {}", artifact.getArtifactId(), artifactFile ); - project.getArtifact().setFile( artifactFile.toFile() ); - project.getArtifact().setResolved( true ); + file = artifactFile.toFile(); putChecksum( artifact, context.getInputInfo().getChecksum() ); } @@ -328,12 +331,8 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) attachedArtifact ); if ( !Files.exists( attachedArtifactFile ) ) { - LOGGER.info( "Missing file for cached build, cannot restore. File: {}", - attachedArtifactFile ); - project.getArtifact().setFile( null ); - project.getArtifact().setResolved( false ); - project.getAttachedArtifacts().clear(); - return false; + throw new FileNotFoundException( + "Missing file for cached build, cannot restore. File: " + attachedArtifactFile ); } LOGGER.debug( "Attaching artifact {} from {}", artifact.getArtifactId(), attachedArtifactFile ); @@ -344,23 +343,30 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) } else { - projectHelper.attachArtifact( project, attachedArtifact.getType(), - attachedArtifact.getClassifier(), attachedArtifactFile.toFile() ); + AttachedArtifact a = new AttachedArtifact( null, + attachedArtifact.getType(), attachedArtifact.getClassifier(), null ); + a.setFile( attachedArtifactFile.toFile() ); + artifacts.add( a ); } putChecksum( attachedArtifact, context.getInputInfo().getChecksum() ); } } + // Actually modify project at the end in case something went wrong during restoration, + // in which case, the project is unmodified and we continue with normal build. + if ( file != null ) + { + project.getArtifact().setFile( file ); + project.getArtifact().setResolved( true ); + } + artifacts.forEach( a -> projectHelper.attachArtifact( project, + a.getType(), a.getClassifier(), a.getFile() ) ); + return true; } catch ( Exception e ) { - project.getArtifact().setFile( null ); - project.getArtifact().setResolved( false ); - project.getAttachedArtifacts().clear(); LOGGER.error( "Cannot restore cache, continuing with normal build.", e ); return false; } - - return true; } private void putChecksum( Artifact artifact, String projectChecksum ) From 219b4aaaeb9e54f07d2328de517d337202d89a48 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 16 Nov 2021 16:30:27 +0100 Subject: [PATCH 136/188] [MNG-7337] Fix broken integration tests due to early logging --- .../maven/caching/CachingMojoExecutor.java | 2 +- .../apache/maven/caching/xml/CacheConfig.java | 2 +- .../maven/caching/xml/CacheConfigImpl.java | 105 +++++++++--------- 3 files changed, 53 insertions(+), 56 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java index 36e8ff0b5650..b1575fd603f3 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java @@ -188,7 +188,7 @@ public void execute( MavenSession session, List mojoExecutions, P { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } - cacheState = cacheConfig.getState(); + cacheState = cacheConfig.initialize(); if ( cacheState == INITIALIZED ) { result = cacheController.findCachedBuild( session, project, projectIndex, mojoExecutions ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java index 273b2283260c..63ed1430cabb 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java @@ -41,7 +41,7 @@ public interface CacheConfig { @Nonnull - CacheState getState(); + CacheState initialize(); @Nonnull List getTrackedProperties( MojoExecution mojoExecution ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index ca6edac4c815..50cf4a1cbfac 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -84,92 +84,89 @@ public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig private static final Logger LOGGER = LoggerFactory.getLogger( CacheConfigImpl.class ); + private final XmlService xmlService; private final MavenSession session; - private final CacheState state; - private final CacheConfig cacheConfig; - private final HashFactory hashFactory; - private final List excludePatterns; + + private CacheState state; + private CacheConfig cacheConfig; + private HashFactory hashFactory; + private List excludePatterns; @Inject public CacheConfigImpl( XmlService xmlService, MavenSession session ) { + this.xmlService = xmlService; this.session = session; + } - if ( !Features.caching( session.getUserProperties() ).isActive() ) - { - LOGGER.info( "Cache disabled by command line flag, project will be built fully and not cached" ); - state = CacheState.DISABLED; - cacheConfig = null; - hashFactory = null; - excludePatterns = null; - } - else + @Nonnull + @Override + public CacheState initialize() + { + if ( state == null ) { - Path configPath; - - String configPathText = getProperty( CONFIG_PATH_PROPERTY_NAME, null ); - if ( StringUtils.isNotBlank( configPathText ) ) - { - configPath = Paths.get( configPathText ); - } - else - { - configPath = getMultimoduleRoot( session ).resolve( ".mvn" ).resolve( "maven-cache-config.xml" ); - } - - if ( !Files.exists( configPath ) ) + if ( !Features.caching( session.getUserProperties() ).isActive() ) { - LOGGER.info( "Cache configuration is not available at configured path " - + configPath + ", cache is disabled" ); + LOGGER.info( "Cache disabled by command line flag, project will be built fully and not cached" ); state = CacheState.DISABLED; - cacheConfig = null; - hashFactory = null; - excludePatterns = null; } else { - try + Path configPath; + + String configPathText = getProperty( CONFIG_PATH_PROPERTY_NAME, null ); + if ( StringUtils.isNotBlank( configPathText ) ) { - LOGGER.info( "Loading cache configuration from " + configPath ); - cacheConfig = xmlService.loadCacheConfig( configPath.toFile() ); + configPath = Paths.get( configPathText ); } - catch ( Exception e ) + else { - throw new IllegalArgumentException( - "Cannot initialize cache because xml config is not valid or not available", e ); + configPath = getMultimoduleRoot( session ).resolve( ".mvn" ).resolve( "maven-cache-config.xml" ); } - if ( !cacheConfig.getConfiguration().isEnabled() ) + if ( !Files.exists( configPath ) ) { + LOGGER.info( "Cache configuration is not available at configured path {}, cache is disabled", + configPath ); state = CacheState.DISABLED; - hashFactory = null; - excludePatterns = null; } else { - String hashAlgorithm = null; try { - hashAlgorithm = getConfiguration().getHashAlgorithm(); - hashFactory = HashFactory.of( hashAlgorithm ); - LOGGER.info( "Using " + hashAlgorithm + " hash algorithm for cache" ); + LOGGER.info( "Loading cache configuration from {}", configPath ); + cacheConfig = xmlService.loadCacheConfig( configPath.toFile() ); } catch ( Exception e ) { - throw new IllegalArgumentException( "Unsupported hashing algorithm: " + hashAlgorithm, e ); + throw new IllegalArgumentException( + "Cannot initialize cache because xml config is not valid or not available", e ); } - excludePatterns = compileExcludePatterns(); - state = CacheState.INITIALIZED; + if ( !cacheConfig.getConfiguration().isEnabled() ) + { + state = CacheState.DISABLED; + } + else + { + String hashAlgorithm = null; + try + { + hashAlgorithm = getConfiguration().getHashAlgorithm(); + hashFactory = HashFactory.of( hashAlgorithm ); + LOGGER.info( "Using {} hash algorithm for cache", hashAlgorithm ); + } + catch ( Exception e ) + { + throw new IllegalArgumentException( "Unsupported hashing algorithm: " + hashAlgorithm, e ); + } + + excludePatterns = compileExcludePatterns(); + state = CacheState.INITIALIZED; + } } } } - } - - @Nonnull - @Override - public CacheState getState() - { return state; } @@ -527,7 +524,7 @@ public List getAttachedOutputs() { checkInitializedState(); final AttachedOutputs attachedOutputs = getConfiguration().getAttachedOutputs(); - return attachedOutputs == null ? Collections.emptyList() : attachedOutputs.getDirNames(); + return attachedOutputs == null ? Collections.emptyList() : attachedOutputs.getDirNames(); } @Nonnull From 5d80e2e988257d267e21e1951d097d15a52f7729 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Nov 2021 07:43:33 +0100 Subject: [PATCH 137/188] [MNG-7129] Rely on the DefaultLifecycles instead of hard-coded list of phases, make lifecycles ordering more explicit --- .../maven/caching/CacheControllerImpl.java | 21 +-- .../maven/caching/CachingMojoExecutor.java | 14 +- .../maven/caching/LifecyclePhasesHelper.java | 124 ++++++++++++++++++ .../apache/maven/caching/ProjectUtils.java | 34 +---- .../org/apache/maven/caching/xml/Build.java | 33 ----- .../maven/lifecycle/DefaultLifecycles.java | 3 + .../DefaultLifecyclePluginAnalyzer.java | 15 +-- 7 files changed, 150 insertions(+), 94 deletions(-) create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/LifecyclePhasesHelper.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index e81f498e2adb..411e626e466f 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -127,6 +127,7 @@ public class CacheControllerImpl implements CacheController private final RemoteCacheRepository remoteCache; private final ConcurrentMap artifactDigestByKey = new ConcurrentHashMap<>(); private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); + private final LifecyclePhasesHelper lifecyclePhasesHelper; private volatile Scm scm; @Inject @@ -138,7 +139,8 @@ public CacheControllerImpl( XmlService xmlService, LocalCacheRepository localCache, RemoteCacheRepository remoteCache, - CacheConfig cacheConfig ) + CacheConfig cacheConfig, + LifecyclePhasesHelper lifecyclePhasesHelper ) { this.mavenPluginManager = mavenPluginManager; this.projectHelper = projectHelper; @@ -148,6 +150,7 @@ public CacheControllerImpl( this.repoSystem = repoSystem; this.artifactHandlerManager = artifactHandlerManager; this.xmlService = xmlService; + this.lifecyclePhasesHelper = lifecyclePhasesHelper; } @Override @@ -158,7 +161,7 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, { final String highestRequestPhase = Utils.getLast( mojoExecutions ).get().getLifecyclePhase(); - if ( !ProjectUtils.isLaterPhase( highestRequestPhase, "post-clean" ) ) + if ( !lifecyclePhasesHelper.isLaterPhaseThanClean( highestRequestPhase ) ) { return empty(); } @@ -239,8 +242,8 @@ private CacheResult analyzeResult( CacheContext context, List moj info.getCacheImplementationVersion() ); } - final List cachedSegment = info.getCachedSegment( mojoExecutions ); - final List missingMojos = info.getMissingExecutions( cachedSegment ); + List cachedSegment = lifecyclePhasesHelper.getCachedSegment( mojoExecutions, info ); + List missingMojos = info.getMissingExecutions( cachedSegment ); if ( !missingMojos.isEmpty() ) { LOGGER.warn( "Cached build doesn't contains all requested plugin executions " @@ -255,12 +258,11 @@ private CacheResult analyzeResult( CacheContext context, List moj } final String highestRequestPhase = Utils.getLast( mojoExecutions ).get().getLifecyclePhase(); - final String highestCompletedGoal = info.getHighestCompletedGoal(); - if ( ProjectUtils.isLaterPhase( highestRequestPhase, highestCompletedGoal ) && !canIgnoreMissingSegment( - info, mojoExecutions ) ) + if ( lifecyclePhasesHelper.isLaterPhaseThanBuild( highestRequestPhase, info ) + && !canIgnoreMissingSegment( info, mojoExecutions ) ) { LOGGER.info( "Project restored partially. Highest cached goal: {}, requested: {}", - highestCompletedGoal, highestRequestPhase ); + info.getHighestCompletedGoal(), highestRequestPhase ); return partialSuccess( info, context ); } @@ -282,7 +284,8 @@ private CacheResult analyzeResult( CacheContext context, List moj private boolean canIgnoreMissingSegment( Build info, List mojoExecutions ) { - final List postCachedSegment = info.getPostCachedSegment( mojoExecutions ); + final List postCachedSegment = + lifecyclePhasesHelper.getPostCachedSegment( mojoExecutions, info ); for ( MojoExecution mojoExecution : postCachedSegment ) { if ( !cacheConfig.canIgnore( mojoExecution ) ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java index b1575fd603f3..d80cfb1ec843 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java @@ -68,7 +68,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.apache.maven.caching.ProjectUtils.isLaterPhase; import static org.apache.maven.caching.checksum.KeyUtils.getVersionlessProjectKey; import static org.apache.maven.caching.xml.CacheState.DISABLED; import static org.apache.maven.caching.xml.CacheState.INITIALIZED; @@ -93,6 +92,7 @@ public class CachingMojoExecutor implements IMojoExecutor private final CacheController cacheController; private final CacheConfig cacheConfig; private final MojoParametersListener mojoListener; + private final LifecyclePhasesHelper lifecyclePhasesHelper; @Inject public CachingMojoExecutor( @@ -102,7 +102,8 @@ public CachingMojoExecutor( ExecutionEventCatapult eventCatapult, CacheController cacheController, CacheConfig cacheConfig, - MojoParametersListener mojoListener ) + MojoParametersListener mojoListener, + LifecyclePhasesHelper lifecyclePhasesHelper ) { this.pluginManager = pluginManager; this.mavenPluginManager = mavenPluginManager; @@ -111,6 +112,7 @@ public CachingMojoExecutor( this.cacheController = cacheController; this.cacheConfig = cacheConfig; this.mojoListener = mojoListener; + this.lifecyclePhasesHelper = lifecyclePhasesHelper; } public DependencyContext newDependencyContext( MavenSession session, List mojoExecutions ) @@ -208,7 +210,7 @@ public void execute( MavenSession session, List mojoExecutions, P { if ( source == Source.CLI || mojoExecution.getLifecyclePhase() == null - || isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) + || lifecyclePhasesHelper.isLaterPhaseThanClean( mojoExecution.getLifecyclePhase() ) ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } @@ -256,7 +258,7 @@ private boolean restoreProject( CacheResult cacheResult, final Build build = cacheResult.getBuildInfo(); final MavenProject project = cacheResult.getContext().getProject(); final MavenSession session = cacheResult.getContext().getSession(); - final List cachedSegment = build.getCachedSegment( mojoExecutions ); + final List cachedSegment = lifecyclePhasesHelper.getCachedSegment( mojoExecutions, build ); boolean restored = cacheController.restoreProjectArtifacts( cacheResult ); if ( !restored ) @@ -299,7 +301,7 @@ private boolean restoreProject( CacheResult cacheResult, } } - for ( MojoExecution mojoExecution : build.getPostCachedSegment( mojoExecutions ) ) + for ( MojoExecution mojoExecution : lifecyclePhasesHelper.getPostCachedSegment( mojoExecutions, build ) ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } @@ -350,7 +352,7 @@ private List getCleanPhase( List mojoExecutions ) for ( MojoExecution mojoExecution : mojoExecutions ) { if ( mojoExecution.getLifecyclePhase() == null - || isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) + || lifecyclePhasesHelper.isLaterPhaseThanClean( mojoExecution.getLifecyclePhase() ) ) { break; } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LifecyclePhasesHelper.java b/maven-caching/src/main/java/org/apache/maven/caching/LifecyclePhasesHelper.java new file mode 100644 index 000000000000..fb2f7eaa4ae8 --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/LifecyclePhasesHelper.java @@ -0,0 +1,124 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.apache.maven.caching.xml.Build; +import org.apache.maven.lifecycle.DefaultLifecycles; +import org.apache.maven.lifecycle.Lifecycle; +import org.apache.maven.plugin.MojoExecution; + +@Singleton +@Named +public class LifecyclePhasesHelper +{ + + private final DefaultLifecycles defaultLifecycles; + private final List phases; + private final String lastCleanPhase; + + @Inject + public LifecyclePhasesHelper( DefaultLifecycles defaultLifecycles, + @Named( "clean" ) Lifecycle cleanLifecycle ) + { + this.defaultLifecycles = Objects.requireNonNull( defaultLifecycles ); + this.phases = defaultLifecycles.getLifeCycles().stream() + .flatMap( lf -> lf.getPhases().stream() ) + .collect( Collectors.toList() ); + this.lastCleanPhase = Utils.getLast( cleanLifecycle.getPhases() ).get(); + } + + /** + * Check if the given phase is later than the clean lifecycle. + */ + public boolean isLaterPhaseThanClean( String phase ) + { + return isLaterPhase( phase, lastCleanPhase ); + } + + public boolean isLaterPhaseThanBuild( String phase, Build build ) + { + return isLaterPhase( phase, build.getHighestCompletedGoal() ); + } + + /** + * Check if the given phase is later than the other in maven lifecycle. + * Example: isLaterPhase("install", "clean") returns true; + */ + public boolean isLaterPhase( String phase, String other ) + { + if ( !phases.contains( phase ) ) + { + throw new IllegalArgumentException( "Unsupported phase: " + phase ); + } + if ( !phases.contains( other ) ) + { + throw new IllegalArgumentException( "Unsupported phase: " + other ); + } + + return phases.indexOf( phase ) > phases.indexOf( other ); + } + + /** + * Computes the list of segments that are cached. + */ + public List getCachedSegment( List mojoExecutions, Build build ) + { + List list = new ArrayList<>(); + for ( MojoExecution mojoExecution : mojoExecutions ) + { + if ( !isLaterPhaseThanClean( mojoExecution.getLifecyclePhase() ) ) + { + continue; + } + if ( isLaterPhaseThanBuild( mojoExecution.getLifecyclePhase(), build ) ) + { + break; + } + list.add( mojoExecution ); + } + return list; + } + + /** + * Computes the list of segments that will have to be executed after cache restoration. + */ + public List getPostCachedSegment( List mojoExecutions, Build build ) + { + List list = new ArrayList<>(); + for ( MojoExecution mojoExecution : mojoExecutions ) + { + if ( isLaterPhaseThanBuild( mojoExecution.getLifecyclePhase(), build ) ) + { + list.add( mojoExecution ); + } + } + return list; + } + +} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java index c8b5eeba5ffd..d1d9590326c7 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java @@ -50,37 +50,6 @@ public class ProjectUtils { - private static final List PHASES = Arrays.asList( - //clean - "pre-clean", "clean", "post-clean", - // default - "validate", "initialize", "generate-sources", "process-sources", "generate-resources", "process-resources", - "compile", "process-classes", "generate-test-sources", "process-test-sources", "generate-test-resources", - "process-test-resources", "test-compile", "process-test-classes", "test", "prepare-package", "package", - "pre-integration-test", "integration-test", "post-integration-test", "verify", "install", "deploy", - //site - "pre-site", "site", "post-site", "site-deploy" ); - - /** - * @param phase - * @param other - * @return true if the given phase is later than the other in maven lifecycle. Example: isLaterPhase("install", - * "clean") returns true; - */ - public static boolean isLaterPhase( String phase, String other ) - { - if ( !PHASES.contains( phase ) ) - { - throw new IllegalArgumentException( "Unsupported phase: " + phase ); - } - if ( !PHASES.contains( other ) ) - { - throw new IllegalArgumentException( "Unsupported phase: " + other ); - } - - return PHASES.indexOf( phase ) > PHASES.indexOf( other ); - } - public static boolean isBuilding( Dependency dependency, ProjectIndex projectIndex ) { final MavenProject key = new MavenProject(); @@ -145,7 +114,8 @@ public static String normalizedName( Artifact artifact ) public static String mojoExecutionKey( MojoExecution mojo ) { - return StringUtils.join( Arrays.asList( StringUtils.defaultIfEmpty( mojo.getExecutionId(), "emptyExecId" ), + return StringUtils.join( Arrays.asList( + StringUtils.defaultIfEmpty( mojo.getExecutionId(), "emptyExecId" ), StringUtils.defaultIfEmpty( mojo.getGoal(), "emptyGoal" ), StringUtils.defaultIfEmpty( mojo.getLifecyclePhase(), "emptyLifecyclePhase" ), StringUtils.defaultIfEmpty( mojo.getArtifactId(), "emptyArtifactId" ), diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java index 91f0c5caa755..8c665ed9e354 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java @@ -41,7 +41,6 @@ import java.util.Objects; import java.util.stream.Collectors; -import static org.apache.maven.caching.ProjectUtils.isLaterPhase; import static org.apache.maven.caching.ProjectUtils.mojoExecutionKey; /** @@ -184,38 +183,6 @@ public String getHighestCompletedGoal() return Utils.getLast( dto.getGoals() ).get(); } - public List getCachedSegment( List mojoExecutions ) - { - List list = new ArrayList<>(); - for ( MojoExecution mojoExecution : mojoExecutions ) - { - if ( !isLaterPhase( mojoExecution.getLifecyclePhase(), "post-clean" ) ) - { - continue; - } - if ( isLaterPhase( mojoExecution.getLifecyclePhase(), getHighestCompletedGoal() ) ) - { - break; - } - list.add( mojoExecution ); - } - return list; - - } - - public List getPostCachedSegment( List mojoExecutions ) - { - List list = new ArrayList<>(); - for ( MojoExecution mojoExecution : mojoExecutions ) - { - if ( isLaterPhase( mojoExecution.getLifecyclePhase(), getHighestCompletedGoal() ) ) - { - list.add( mojoExecution ); - } - } - return list; - } - public DigestItem findArtifact( Dependency dependency ) { diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java index 1160e88a8d5b..b8f0c394e71b 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java @@ -117,6 +117,9 @@ public Map getPhaseToLifecycleMap() return phaseToLifecycleMap; } + /** + * Returns an ordered list of lifecycles + */ public List getLifeCycles() { List lifecycleIds = Arrays.asList( STANDARD_LIFECYCLES ); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java index 65843f853077..b0e3fa16c4ef 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java @@ -19,8 +19,6 @@ * under the License. */ -import java.util.ArrayList; -import java.util.Comparator; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -110,7 +108,7 @@ public Set getPluginsBoundByDefaultToAllLifecycles( String packaging ) Map plugins = new LinkedHashMap<>(); - for ( Lifecycle lifecycle : getOrderedLifecycles() ) + for ( Lifecycle lifecycle : defaultLifeCycles.getLifeCycles() ) { org.apache.maven.lifecycle.mapping.Lifecycle lifecycleConfiguration = lifecycleMappingForPackaging.getLifecycles().get( lifecycle.getId() ); @@ -163,17 +161,6 @@ private LifecycleMapping lookupLifecycleMapping( final String packaging ) } } - private List getOrderedLifecycles() - { - // NOTE: The lifecycle order can affect implied execution ids so we better be deterministic. - - List lifecycles = new ArrayList<>( defaultLifeCycles.getLifeCycles() ); - - lifecycles.sort( Comparator.comparing( Lifecycle::getId ) ); - - return lifecycles; - } - private void parseLifecyclePhaseDefinitions( Map plugins, String phase, LifecyclePhase goals ) { InputSource inputSource = new InputSource(); From c62e3fe9c9a922b9afd050da65ab1daacf18337a Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Nov 2021 10:26:47 +0100 Subject: [PATCH 138/188] [MNG-7129] Fix lifecycles --- .../java/org/apache/maven/lifecycle/DefaultLifecycles.java | 2 +- .../org/apache/maven/lifecycle/DefaultLifecyclesTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java index b8f0c394e71b..9849fffea3c5 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java @@ -45,7 +45,7 @@ @Singleton public class DefaultLifecycles { - public static final String[] STANDARD_LIFECYCLES = { "default", "clean", "site", "wrapper" }; + public static final String[] STANDARD_LIFECYCLES = { "clean", "default", "site", "wrapper" }; private final Logger logger = LoggerFactory.getLogger( getClass() ); diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java index 59229d442b1e..046227a60432 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/DefaultLifecyclesTest.java @@ -93,8 +93,8 @@ public void testCustomLifecycle() DefaultLifecycles dl = new DefaultLifecycles( myLifecycles.stream() .collect( Collectors.toMap( l -> l.getId(), l -> l ) ) ); - assertThat( dl.getLifeCycles().get( 0 ).getId(), is( "default" ) ); - assertThat( dl.getLifeCycles().get( 1 ).getId(), is( "clean" ) ); + assertThat( dl.getLifeCycles().get( 0 ).getId(), is( "clean" ) ); + assertThat( dl.getLifeCycles().get( 1 ).getId(), is( "default" ) ); assertThat( dl.getLifeCycles().get( 2 ).getId(), is( "site" ) ); assertThat( dl.getLifeCycles().get( 3 ).getId(), is( "wrapper" ) ); assertThat( dl.getLifeCycles().get( 4 ).getId(), is( "etl" ) ); From a074408d18cdbf158d0b93e97785795c9995b73a Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Nov 2021 10:24:38 +0100 Subject: [PATCH 139/188] Remove Utils and rename ProjectUtils to CacheUtils --- .../maven/caching/CacheControllerImpl.java | 8 +- .../{ProjectUtils.java => CacheUtils.java} | 16 +++- .../caching/HttpCacheRepositoryImpl.java | 2 +- .../maven/caching/LifecyclePhasesHelper.java | 2 +- .../caching/LocalCacheRepositoryImpl.java | 25 ++++-- .../maven/caching/MojoExecutionManager.java | 2 +- .../maven/caching/MojoParametersListener.java | 2 +- .../java/org/apache/maven/caching/Utils.java | 87 ------------------- .../caching/checksum/MavenProjectInput.java | 33 +++---- .../org/apache/maven/caching/xml/Build.java | 9 +- .../maven/caching/xml/CacheConfigImpl.java | 2 +- .../apache/maven/caching/xml/DtoUtils.java | 4 +- 12 files changed, 62 insertions(+), 130 deletions(-) rename maven-caching/src/main/java/org/apache/maven/caching/{ProjectUtils.java => CacheUtils.java} (94%) delete mode 100644 maven-caching/src/main/java/org/apache/maven/caching/Utils.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 411e626e466f..5c9bdbe7ad20 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -160,7 +160,7 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, List mojoExecutions ) { - final String highestRequestPhase = Utils.getLast( mojoExecutions ).get().getLifecyclePhase(); + final String highestRequestPhase = CacheUtils.getLast( mojoExecutions ).getLifecyclePhase(); if ( !lifecyclePhasesHelper.isLaterPhaseThanClean( highestRequestPhase ) ) { return empty(); @@ -257,7 +257,7 @@ private CacheResult analyzeResult( CacheContext context, List moj return failure( info, context ); } - final String highestRequestPhase = Utils.getLast( mojoExecutions ).get().getLifecyclePhase(); + final String highestRequestPhase = CacheUtils.getLast( mojoExecutions ).getLifecyclePhase(); if ( lifecyclePhasesHelper.isLaterPhaseThanBuild( highestRequestPhase, info ) && !canIgnoreMissingSegment( info, mojoExecutions ) ) { @@ -573,7 +573,7 @@ private List buildExecutionInfo( List mojoExe List list = new ArrayList<>(); for ( MojoExecution mojoExecution : mojoExecutions ) { - final String executionKey = ProjectUtils.mojoExecutionKey( mojoExecution ); + final String executionKey = CacheUtils.mojoExecutionKey( mojoExecution ); final MojoExecutionEvent executionEvent = executionEvents.get( executionKey ); CompletedExecution executionInfo = new CompletedExecution(); executionInfo.setExecutionKey( executionKey ); @@ -778,7 +778,7 @@ private void populateGitInfo( Build build, MavenSession session ) throws IOExcep { try { - scm = ProjectUtils.readGitInfo( session ); + scm = CacheUtils.readGitInfo( session ); } catch ( IOException e ) { diff --git a/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java similarity index 94% rename from maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java rename to maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java index d1d9590326c7..b067497bf5a2 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/ProjectUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java @@ -38,6 +38,7 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; +import java.util.NoSuchElementException; import static org.apache.commons.lang3.StringUtils.removeStart; import static org.apache.commons.lang3.StringUtils.trim; @@ -47,7 +48,7 @@ /** * ProjectUtils */ -public class ProjectUtils +public class CacheUtils { public static boolean isBuilding( Dependency dependency, ProjectIndex projectIndex ) @@ -162,9 +163,18 @@ public static Scm readGitInfo( MavenSession session ) throws IOException private static String readFirstLine( Path path, String defaultValue ) throws IOException { - final List lines = Files.readAllLines( path, StandardCharsets.UTF_8 ); - return Utils.getFirst( lines ).orElse( defaultValue ); + return Files.lines( path, StandardCharsets.UTF_8 ).findFirst().orElse( defaultValue ); } + public static T getLast( List list ) + { + int size = list.size(); + if ( size > 0 ) + { + return list.get( size - 1 ); + } + throw new NoSuchElementException(); + } + } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java index 2d19c7899180..45e47cec5635 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java @@ -141,7 +141,7 @@ public void saveArtifactFile( CacheResult cacheResult, org.apache.maven.artifact.Artifact artifact ) throws IOException { CacheContext context = cacheResult.getContext(); - final String resourceUrl = getResourceUrl( cacheResult.getContext(), ProjectUtils.normalizedName( artifact ) ); + final String resourceUrl = getResourceUrl( cacheResult.getContext(), CacheUtils.normalizedName( artifact ) ); try ( InputStream inputStream = Files.newInputStream( artifact.getFile().toPath() ) ) { putToRemoteCache( inputStream, resourceUrl, context.getProject().getArtifactId() ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LifecyclePhasesHelper.java b/maven-caching/src/main/java/org/apache/maven/caching/LifecyclePhasesHelper.java index fb2f7eaa4ae8..ad5737e9c52f 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LifecyclePhasesHelper.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LifecyclePhasesHelper.java @@ -50,7 +50,7 @@ public LifecyclePhasesHelper( DefaultLifecycles defaultLifecycles, this.phases = defaultLifecycles.getLifeCycles().stream() .flatMap( lf -> lf.getPhases().stream() ) .collect( Collectors.toList() ); - this.lastCleanPhase = Utils.getLast( cleanLifecycle.getPhases() ).get(); + this.lastCleanPhase = CacheUtils.getLast( cleanLifecycle.getPhases() ); } /** diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java index 58a2e3f0340e..dd5b49bfd4b4 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java @@ -32,11 +32,13 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; import javax.inject.Inject; import javax.inject.Named; @@ -44,7 +46,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.maven.SessionScoped; -import org.apache.maven.caching.Utils.MultiMap; import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheSource; @@ -65,7 +66,7 @@ import static java.util.concurrent.TimeUnit.HOURS; import static java.util.concurrent.TimeUnit.MINUTES; import static org.apache.commons.lang3.StringUtils.isNotBlank; -import static org.apache.maven.caching.ProjectUtils.getMultimoduleRoot; +import static org.apache.maven.caching.CacheUtils.getMultimoduleRoot; import static org.apache.maven.caching.checksum.MavenProjectInput.CACHE_IMPLEMENTATION_VERSION; /** @@ -261,7 +262,7 @@ private Optional findBestMatchingBuildImpl( final Path artifactCacheDir = artifactCacheDir( session, dependency.getGroupId(), dependency.getArtifactId() ); - final MultiMap, Pair> filesByVersion = new MultiMap<>(); + final Map, Collection>> filesByVersion = new HashMap<>(); Files.walkFileTree( artifactCacheDir, new SimpleFileVisitor() { @@ -278,14 +279,14 @@ public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttrib Pair.of( new Build( dto, CacheSource.LOCAL ), path ); final String cachedVersion = dto.getArtifact().getVersion(); final String cachedBranch = getScmRef( dto.getScm() ); - filesByVersion.add( Pair.of( cachedVersion, cachedBranch ), buildInfoAndFile ); + add( filesByVersion, Pair.of( cachedVersion, cachedBranch ), buildInfoAndFile ); if ( isNotBlank( cachedBranch ) ) { - filesByVersion.add( Pair.of( EMPTY, cachedBranch ), buildInfoAndFile ); + add( filesByVersion, Pair.of( EMPTY, cachedBranch ), buildInfoAndFile ); } if ( isNotBlank( cachedVersion ) ) { - filesByVersion.add( Pair.of( cachedVersion, EMPTY ), buildInfoAndFile ); + add( filesByVersion, Pair.of( cachedVersion, EMPTY ), buildInfoAndFile ); } } catch ( Exception e ) @@ -304,7 +305,7 @@ public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttrib return Optional.empty(); } - final String currentRef = getScmRef( ProjectUtils.readGitInfo( session ) ); + final String currentRef = getScmRef( CacheUtils.readGitInfo( session ) ); // first lets try by branch and version Collection> bestMatched = new LinkedList<>(); if ( isNotBlank( currentRef ) ) @@ -324,7 +325,8 @@ public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttrib if ( bestMatched.isEmpty() ) { // ok lets take all - bestMatched = filesByVersion.allValues(); + bestMatched = filesByVersion.values().stream() + .flatMap( Collection::stream ).collect( Collectors.toList() ); } return bestMatched.stream() @@ -410,7 +412,7 @@ public void saveArtifactFile( CacheResult cacheResult, org.apache.maven.artifact { // safe artifacts to cache File artifactFile = artifact.getFile(); - Path cachePath = localBuildPath( cacheResult.getContext(), ProjectUtils.normalizedName( artifact ), true ); + Path cachePath = localBuildPath( cacheResult.getContext(), CacheUtils.normalizedName( artifact ), true ); Files.copy( artifactFile.toPath(), cachePath, StandardCopyOption.REPLACE_EXISTING ); if ( cacheConfig.isRemoteCacheEnabled() && cacheConfig.isSaveToRemote() && !cacheResult.isFinal() ) { @@ -470,4 +472,9 @@ private static FileTime lastModifiedTime( Path p ) } } + private static void add( Map> map, K key, V value ) + { + map.computeIfAbsent( key, k -> new ArrayList<>() ).add( value ); + } + } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java index 3da8eaad5a50..95a9ef06569b 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java @@ -37,7 +37,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import static org.apache.maven.caching.ProjectUtils.mojoExecutionKey; +import static org.apache.maven.caching.CacheUtils.mojoExecutionKey; /** * MojoExecutionManager diff --git a/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java index cdea6cd48c88..36779755cf20 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java @@ -49,7 +49,7 @@ public class MojoParametersListener implements MojoExecutionListener @Override public void beforeMojoExecution( MojoExecutionEvent event ) { - final String executionKey = ProjectUtils.mojoExecutionKey( event.getExecution() ); + final String executionKey = CacheUtils.mojoExecutionKey( event.getExecution() ); LOGGER.debug( "Starting mojo execution: {}, class: {}", executionKey, event.getMojo().getClass() ); final MavenProject project = event.getProject(); Map projectEvents = projectExecutions.get( project ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/Utils.java b/maven-caching/src/main/java/org/apache/maven/caching/Utils.java deleted file mode 100644 index 57cbd8f18946..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/Utils.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -public class Utils -{ - - public static Optional getFirst( List list ) - { - int size = list.size(); - if ( size > 0 ) - { - return Optional.of( list.get( 0 ) ); - } - return Optional.empty(); - } - - public static Optional getLast( List list ) - { - int size = list.size(); - if ( size > 0 ) - { - return Optional.of( list.get( size - 1 ) ); - } - return Optional.empty(); - } - - public static T getOnlyElement( Collection col ) - { - Iterator iterator = col.iterator(); - T first = iterator.next(); - if ( iterator.hasNext() ) - { - StringBuilder sb = new StringBuilder().append( "expected one element but was: <" ).append( first ); - for ( int i = 0; i < 4 && iterator.hasNext(); i++ ) - { - sb.append( ", " ).append( iterator.next() ); - } - if ( iterator.hasNext() ) - { - sb.append( ", ..." ); - } - sb.append( '>' ); - throw new IllegalArgumentException( sb.toString() ); - } - return first; - } - - public static class MultiMap extends HashMap> - { - public void add( K key, V value ) - { - super.computeIfAbsent( key, k -> new ArrayList<>() ).add( value ); - } - - public Collection allValues() - { - return values().stream().flatMap( Collection::stream ).collect( Collectors.toList() ); - } - } - -} \ No newline at end of file diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 9f909f55f99c..b7fdfaac6948 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -55,10 +55,9 @@ import org.apache.maven.caching.Clock; import org.apache.maven.caching.LocalCacheRepository; import org.apache.maven.caching.PluginScanConfig; -import org.apache.maven.caching.ProjectUtils; +import org.apache.maven.caching.CacheUtils; import org.apache.maven.caching.RemoteCacheRepository; import org.apache.maven.caching.ScanConfigProperties; -import org.apache.maven.caching.Utils; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashChecksum; import org.apache.maven.caching.hash.HashFactory; @@ -93,8 +92,8 @@ import static org.apache.commons.lang3.StringUtils.replaceEachRepeatedly; import static org.apache.commons.lang3.StringUtils.startsWithAny; import static org.apache.commons.lang3.StringUtils.stripToEmpty; -import static org.apache.maven.caching.ProjectUtils.isBuilding; -import static org.apache.maven.caching.ProjectUtils.isSnapshot; +import static org.apache.maven.caching.CacheUtils.isBuilding; +import static org.apache.maven.caching.CacheUtils.isSnapshot; /** * MavenProjectInput @@ -723,7 +722,7 @@ private SortedMap getMutableDependencies() throws IOExceptio continue; } - if ( ProjectUtils.isPom( dependency ) ) + if ( CacheUtils.isPom( dependency ) ) { // POM dependency will be resolved by maven system to actual dependencies // and will contribute to effective pom. @@ -755,7 +754,7 @@ private SortedMap getMutableDependencies() throws IOExceptio resolved = bestMatched.findArtifact( dependency ); } } - if ( resolved == null && !ProjectUtils.isPom( dependency ) ) + if ( resolved == null && !CacheUtils.isPom( dependency ) ) { try { @@ -777,13 +776,17 @@ private DigestItem resolveArtifact( final Artifact dependencyArtifact, MultimoduleDiscoveryStrategy strategy ) throws IOException { - ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( - dependencyArtifact ).setResolveRoot( true ).setResolveTransitively( false ).setLocalRepository( - session.getLocalRepository() ).setRemoteRepositories( - project.getRemoteArtifactRepositories() ).setOffline( - session.isOffline() || !strategy.isLookupRemoteMavenRepo( dependencyArtifact ) ).setForceUpdate( - session.getRequest().isUpdateSnapshots() ).setServers( session.getRequest().getServers() ).setMirrors( - session.getRequest().getMirrors() ).setProxies( session.getRequest().getProxies() ); + ArtifactResolutionRequest request = new ArtifactResolutionRequest() + .setArtifact( dependencyArtifact ) + .setResolveRoot( true ) + .setResolveTransitively( false ) + .setLocalRepository( session.getLocalRepository() ) + .setRemoteRepositories( project.getRemoteArtifactRepositories() ) + .setOffline( session.isOffline() || !strategy.isLookupRemoteMavenRepo( dependencyArtifact ) ) + .setForceUpdate( session.getRequest().isUpdateSnapshots() ) + .setServers( session.getRequest().getServers() ) + .setMirrors( session.getRequest().getMirrors() ) + .setProxies( session.getRequest().getProxies() ); final ArtifactResolutionResult result = repoSystem.resolve( request ); @@ -798,14 +801,14 @@ private DigestItem resolveArtifact( final Artifact dependencyArtifact, "Cannot resolve artifact: " + dependencyArtifact + ", missing: " + result.getMissingArtifacts() ); } - if ( result.getArtifacts().size() > 1 ) + if ( result.getArtifacts().size() != 1 ) { throw new IllegalStateException( "Unexpected number of artifacts returned. Requested: " + dependencyArtifact + ", expected: 1, actual: " + result.getArtifacts() ); } - final Artifact resolved = Utils.getOnlyElement( result.getArtifacts() ); + final Artifact resolved = result.getArtifacts().iterator().next(); final HashAlgorithm algorithm = config.getHashFactory().createAlgorithm(); final String hash = algorithm.hash( resolved.getFile().toPath() ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java index 8c665ed9e354..b2098c1e1fba 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java @@ -19,8 +19,7 @@ * under the License. */ -import org.apache.maven.caching.ProjectUtils; -import org.apache.maven.caching.Utils; +import org.apache.maven.caching.CacheUtils; import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.xml.build.Artifact; @@ -41,7 +40,7 @@ import java.util.Objects; import java.util.stream.Collectors; -import static org.apache.maven.caching.ProjectUtils.mojoExecutionKey; +import static org.apache.maven.caching.CacheUtils.mojoExecutionKey; /** * BuildInfo @@ -180,13 +179,13 @@ public org.apache.maven.caching.xml.build.Build getDto() public String getHighestCompletedGoal() { - return Utils.getLast( dto.getGoals() ).get(); + return CacheUtils.getLast( dto.getGoals() ); } public DigestItem findArtifact( Dependency dependency ) { - if ( ProjectUtils.isPom( dependency ) ) + if ( CacheUtils.isPom( dependency ) ) { throw new IllegalArgumentException( "Pom dependencies should not be treated as artifacts: " + dependency ); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 50cf4a1cbfac..cc50d32dc5c7 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -66,7 +66,7 @@ import org.slf4j.LoggerFactory; import static java.lang.Boolean.TRUE; -import static org.apache.maven.caching.ProjectUtils.getMultimoduleRoot; +import static org.apache.maven.caching.CacheUtils.getMultimoduleRoot; /** * CacheConfigImpl diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java index 690b7c19fe01..16751e91d364 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java @@ -21,7 +21,7 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.ProjectUtils; +import org.apache.maven.caching.CacheUtils; import org.apache.maven.caching.xml.build.Artifact; import org.apache.maven.caching.xml.build.CompletedExecution; import org.apache.maven.caching.xml.build.DigestItem; @@ -67,7 +67,7 @@ public static Artifact createDto( org.apache.maven.artifact.Artifact artifact ) dto.setClassifier( artifact.getClassifier() ); dto.setType( artifact.getType() ); dto.setScope( artifact.getScope() ); - dto.setFileName( ProjectUtils.normalizedName( artifact ) ); + dto.setFileName( CacheUtils.normalizedName( artifact ) ); return dto; } From 8ac204b3f0e17f59fe7873885d29b848f15d88c7 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Nov 2021 10:34:32 +0100 Subject: [PATCH 140/188] Avoid using deprecated class and fix NPE --- .../maven/caching/CacheControllerImpl.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 5c9bdbe7ad20..dcd240a87e44 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -83,7 +83,6 @@ import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; -import org.apache.maven.project.artifact.AttachedArtifact; import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.util.ReflectionUtils; import org.slf4j.Logger; @@ -310,7 +309,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) try { File file = null; - List artifacts = new ArrayList<>(); + List artifacts = new ArrayList<>(); if ( isNotBlank( artifact.getFileName() ) ) { // TODO if remote is forced, probably need to refresh or reconcile all files @@ -346,10 +345,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) } else { - AttachedArtifact a = new AttachedArtifact( null, - attachedArtifact.getType(), attachedArtifact.getClassifier(), null ); - a.setFile( attachedArtifactFile.toFile() ); - artifacts.add( a ); + artifacts.add( new ArtifactToAttach( attachedArtifact, attachedArtifactFile ) ); } putChecksum( attachedArtifact, context.getInputInfo().getChecksum() ); } @@ -361,8 +357,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) project.getArtifact().setFile( file ); project.getArtifact().setResolved( true ); } - artifacts.forEach( a -> projectHelper.attachArtifact( project, - a.getType(), a.getClassifier(), a.getFile() ) ); + artifacts.forEach( a -> projectHelper.attachArtifact( project, a.type, a.classifier, a.file ) ); return true; } catch ( Exception e ) @@ -923,4 +918,24 @@ private boolean isOutputArtifact( String name ) return true; } + private static class ArtifactToAttach + { + + private final String type; + private final String classifier; + private final File file; + + ArtifactToAttach( String type, String classifier, File file ) + { + this.type = type; + this.classifier = classifier; + this.file = file; + } + + ArtifactToAttach( Artifact attachedArtifact, Path attachedArtifactFile ) + { + this( attachedArtifact.getType(), attachedArtifact.getClassifier(), attachedArtifactFile.toFile() ); + } + } + } From 178f14355ea3664cb509c898a054062c59992699 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Nov 2021 10:39:24 +0100 Subject: [PATCH 141/188] Fix DigestUtils log to stdout and use JDK8 lambda for thread local initialization --- .../maven/caching/checksum/DigestUtils.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java index f9fc0dd608bb..81e9c5bb703f 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java @@ -24,6 +24,8 @@ import org.apache.maven.caching.hash.HashChecksum; import org.apache.maven.caching.xml.build.DigestItem; import org.mozilla.universalchardet.UniversalDetector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.nio.ByteBuffer; @@ -44,14 +46,10 @@ public class DigestUtils { - private static final ThreadLocal ENCODING_DETECTOR = new ThreadLocal() - { - @Override - protected UniversalDetector initialValue() - { - return new UniversalDetector( null ); - } - }; + private static final Logger LOGGER = LoggerFactory.getLogger( DigestUtils.class ); + + private static final ThreadLocal ENCODING_DETECTOR = + ThreadLocal.withInitial( () -> new UniversalDetector( null ) ); public static DigestItem pom( HashChecksum checksum, String effectivePom ) @@ -62,14 +60,15 @@ public static DigestItem pom( HashChecksum checksum, String effectivePom ) public static DigestItem file( HashChecksum checksum, Path basedir, Path file ) throws IOException { byte[] content = Files.readAllBytes( file ); - DigestItem item = item( "file", normalize( basedir, file ), checksum.update( content ) ); + String normalized = normalize( basedir, file ); + DigestItem item = item( "file", normalized, checksum.update( content ) ); try { populateContentDetails( file, content, item ); } catch ( IOException ignore ) { - System.out.println( "hello" ); + LOGGER.debug( "Failed to compute digest for file {}", normalized, ignore ); } return item; } From ca53648153d9e046037bc2176f0a8d3f277d78bf Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Nov 2021 11:12:09 +0100 Subject: [PATCH 142/188] Merge SessionUtils and ZipUtils into CacheUtils --- .../maven/caching/CacheControllerImpl.java | 30 ++--- .../org/apache/maven/caching/CacheUtils.java | 71 +++++++++++ .../apache/maven/caching/SessionUtils.java | 48 -------- .../org/apache/maven/caching/ZipUtils.java | 116 ------------------ .../maven/caching/xml/CacheConfigFactory.java | 4 +- 5 files changed, 84 insertions(+), 185 deletions(-) delete mode 100644 maven-caching/src/main/java/org/apache/maven/caching/SessionUtils.java delete mode 100644 maven-caching/src/main/java/org/apache/maven/caching/ZipUtils.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index dcd240a87e44..2e987bb531df 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -22,14 +22,12 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; -import java.nio.file.StandardCopyOption; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Collections; @@ -788,13 +786,10 @@ private void populateGitInfo( Build build, MavenSession session ) throws IOExcep private void zipAndAttachArtifact( MavenProject project, Path dir, String classifier ) throws IOException { - try ( InputStream inputStream = ZipUtils.zipFolder( dir ) ) - { - File tempFile = File.createTempFile( "maven-incremental", project.getArtifactId() ); - tempFile.deleteOnExit(); - Files.copy( inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING ); - projectHelper.attachArtifact( project, "zip", classifier, tempFile ); - } + Path temp = Files.createTempFile( "maven-incremental", project.getArtifactId() ); + temp.toFile().deleteOnExit(); + CacheUtils.zip( dir, temp ); + projectHelper.attachArtifact( project, "zip", classifier, temp.toFile() ); } private String pathToClassifier( Path relative ) @@ -821,18 +816,15 @@ private void restoreGeneratedSources( Artifact artifact, Path artifactFilePath, { final Path targetDir = Paths.get( project.getBuild().getDirectory() ); final Path outputDir = classifierToPath( targetDir, artifact.getClassifier() ); - try ( InputStream is = Files.newInputStream( artifactFilePath ) ) + if ( Files.exists( outputDir ) ) { - if ( Files.exists( outputDir ) ) - { - FileUtils.cleanDirectory( outputDir.toFile() ); - } - else - { - Files.createDirectories( outputDir ); - } - ZipUtils.unzip( is, outputDir ); + FileUtils.cleanDirectory( outputDir.toFile() ); + } + else + { + Files.createDirectories( outputDir ); } + CacheUtils.unzip( artifactFilePath, outputDir ); } //TODO: move to config diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java index b067497bf5a2..8acef95bb573 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java @@ -30,15 +30,24 @@ import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; +import org.eclipse.aether.SessionData; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.FileTime; import java.util.Arrays; import java.util.List; import java.util.NoSuchElementException; +import java.util.function.Supplier; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; import static org.apache.commons.lang3.StringUtils.removeStart; import static org.apache.commons.lang3.StringUtils.trim; @@ -177,4 +186,66 @@ public static T getLast( List list ) throw new NoSuchElementException(); } + public static T getOrCreate( MavenSession session, Object key, Supplier supplier ) + { + SessionData data = session.getRepositorySession().getData(); + while ( true ) + { + T t = (T) data.get( key ); + if ( t == null ) + { + t = supplier.get(); + if ( data.set( key, null, t ) ) + { + continue; + } + } + return t; + } + } + + public static void zip( Path dir, Path zip ) throws IOException + { + try ( ZipOutputStream zipOutputStream = new ZipOutputStream( Files.newOutputStream( zip ) ) ) + { + Files.walkFileTree( dir, new SimpleFileVisitor() + { + @Override + public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttributes ) + throws IOException + { + final ZipEntry zipEntry = new ZipEntry( dir.relativize( path ).toString() ); + zipOutputStream.putNextEntry( zipEntry ); + Files.copy( path, zipOutputStream ); + zipOutputStream.closeEntry(); + return FileVisitResult.CONTINUE; + } + } ); + } + } + + public static void unzip( Path zip, Path out ) throws IOException + { + try ( ZipInputStream zis = new ZipInputStream( Files.newInputStream( zip ) ) ) + { + ZipEntry entry = zis.getNextEntry(); + while ( entry != null ) + { + Path file = out.resolve( entry.getName() ); + if ( entry.isDirectory() ) + { + Files.createDirectory( file ); + } + else + { + Path parent = file.getParent(); + Files.createDirectories( parent ); + Files.copy( zis, file ); + } + Files.setLastModifiedTime( file, FileTime.fromMillis( entry.getTime() ) ); + entry = zis.getNextEntry(); + } + } + } + } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/SessionUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/SessionUtils.java deleted file mode 100644 index a0ca30c0524f..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/SessionUtils.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.function.Supplier; - -import org.apache.maven.execution.MavenSession; -import org.eclipse.aether.SessionData; - -public final class SessionUtils -{ - - public static T getOrCreate( MavenSession session, Object key, Supplier supplier ) - { - SessionData data = session.getRepositorySession().getData(); - while ( true ) - { - T t = (T) data.get( key ); - if ( t == null ) - { - t = supplier.get(); - if ( data.set( key, null, t ) ) - { - continue; - } - } - return t; - } - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/ZipUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/ZipUtils.java deleted file mode 100644 index 9f15bb1d2460..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/ZipUtils.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.io.IOUtils; - -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; - -/** - * ZipUtils - */ -public class ZipUtils -{ - - private static final int BUFFER_SIZE = 4096; - - public static InputStream zipFolder( final Path dir ) throws IOException - { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try ( ZipOutputStream zipOutputStream = new ZipOutputStream( out ) ) - { - processFolder( dir, zipOutputStream ); - } - return new ByteArrayInputStream( out.toByteArray() ); - } - - private static void processFolder( final Path dir, final ZipOutputStream zipOutputStream ) throws IOException - { - Files.walkFileTree( dir, new SimpleFileVisitor() - { - @Override - public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttributes ) throws IOException - { - final ZipEntry zipEntry = new ZipEntry( dir.relativize( path ).toString() ); - zipOutputStream.putNextEntry( zipEntry ); - try ( InputStream inputStream = Files.newInputStream( path ) ) - { - IOUtils.copy( inputStream, zipOutputStream ); - } - zipOutputStream.closeEntry(); - return FileVisitResult.CONTINUE; - } - } ); - } - - public static void unzip( InputStream is, Path out ) throws IOException - { - try ( ZipInputStream zis = new ZipInputStream( is ) ) - { - - ZipEntry entry = zis.getNextEntry(); - - while ( entry != null ) - { - File file = new File( out.toFile(), entry.getName() ); - file.setLastModified( entry.getTime() ); - - if ( entry.isDirectory() ) - { - file.mkdirs(); - } - else - { - File parent = file.getParentFile(); - - if ( !parent.exists() ) - { - parent.mkdirs(); - } - - try ( BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream( file ) ) ) - { - byte[] buffer = new byte[BUFFER_SIZE]; - int location; - while ( ( location = zis.read( buffer ) ) != -1 ) - { - bos.write( buffer, 0, location ); - } - } - } - entry = zis.getNextEntry(); - } - } - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java index bf82077d882d..39782a76a1ac 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java @@ -23,7 +23,7 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.apache.maven.caching.SessionUtils; +import org.apache.maven.caching.CacheUtils; import org.apache.maven.execution.MavenSession; @Singleton @@ -43,7 +43,7 @@ public CacheConfigFactory( XmlService xmlService ) public CacheConfig getCacheConfig( MavenSession session ) { - return SessionUtils.getOrCreate( session, KEY, () -> new CacheConfigImpl( xmlService, session ) ); + return CacheUtils.getOrCreate( session, KEY, () -> new CacheConfigImpl( xmlService, session ) ); } } From e9b633e405a65e2d3edfa72ca64c4cbb5070b1be Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Nov 2021 11:48:55 +0100 Subject: [PATCH 143/188] Inline Clock utility class, remove unused CacheUtils methods --- .../org/apache/maven/caching/CacheUtils.java | 23 ---------- .../java/org/apache/maven/caching/Clock.java | 42 ------------------- .../caching/checksum/MavenProjectInput.java | 10 ++--- 3 files changed, 4 insertions(+), 71 deletions(-) delete mode 100644 maven-caching/src/main/java/org/apache/maven/caching/Clock.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java index 8acef95bb573..ec3d73ca10c9 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java @@ -19,7 +19,6 @@ * under the License. */ -import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; @@ -32,7 +31,6 @@ import org.apache.maven.project.MavenProject; import org.eclipse.aether.SessionData; -import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.FileVisitResult; @@ -69,16 +67,6 @@ public static boolean isBuilding( Dependency dependency, ProjectIndex projectInd return projectIndex.getProjects().containsKey( BuilderCommon.getKey( key ) ); } - public static boolean isPomPackaging( MavenProject project ) - { - return project.getPackaging().equals( "pom" ) && !new File( getSrcDir( project ) ).exists(); - } - - public static boolean isPom( Artifact artifact ) - { - return artifact.getType().equals( "pom" ); - } - public static boolean isPom( Dependency dependency ) { return dependency.getType().equals( "pom" ); @@ -89,19 +77,8 @@ public static boolean isSnapshot( String version ) return version.endsWith( SNAPSHOT_VERSION ) || version.endsWith( LATEST_VERSION ); } - public static String getTargetDir( MavenProject project ) - { - return FilenameUtils.concat( project.getBasedir().getAbsolutePath(), "target" ); - } - - public static String getSrcDir( MavenProject project ) - { - return FilenameUtils.concat( project.getBasedir().getAbsolutePath(), "src" ); - } - public static String normalizedName( Artifact artifact ) { - if ( artifact.getFile() == null ) { return null; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/Clock.java b/maven-caching/src/main/java/org/apache/maven/caching/Clock.java deleted file mode 100644 index ce0c487c669c..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/Clock.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import static java.util.concurrent.TimeUnit.NANOSECONDS; - -/** - * Clock - */ -public class Clock -{ - public static long time() - { - return System.nanoTime(); - } - - public static long elapsed( long time ) - { - return NANOSECONDS.toMillis( time() - time ); - } - - private Clock() - { - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index b7fdfaac6948..1084c429239a 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -52,7 +52,6 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.caching.Clock; import org.apache.maven.caching.LocalCacheRepository; import org.apache.maven.caching.PluginScanConfig; import org.apache.maven.caching.CacheUtils; @@ -198,14 +197,13 @@ public MavenProjectInput( MavenProject project, public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOException { - long time = Clock.time(); + final long t0 = System.currentTimeMillis(); final String effectivePom = getEffectivePom( project.getOriginalEffectiveModel() ); final SortedSet inputFiles = getInputFiles(); final SortedMap dependenciesChecksum = getMutableDependencies(); - final long inputTime = Clock.elapsed( time ); - time = Clock.time(); + final long t1 = System.currentTimeMillis(); // hash items: effective pom + input files + dependencies final int count = 1 + inputFiles.size() + dependenciesChecksum.size(); @@ -263,14 +261,14 @@ public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOE projectsInputInfoType.setChecksum( checksum.digest() ); projectsInputInfoType.getItems().addAll( items ); - final long checksumTime = Clock.elapsed( time ); + final long t2 = System.currentTimeMillis(); for ( DigestItem item : projectsInputInfoType.getItems() ) { LOGGER.debug( "Hash calculated, item: {}, hash: {}", item.getType(), item.getHash() ); } LOGGER.info( "Project inputs calculated in {} ms. {} checksum [{}] calculated in {} ms.", - inputTime, hashFactory.getAlgorithm(), projectsInputInfoType.getChecksum(), checksumTime ); + t1 - t0, hashFactory.getAlgorithm(), projectsInputInfoType.getChecksum(), t2 - t1 ); return projectsInputInfoType; } From cff378035fe69468768e4f71de00f4ae58ed92a4 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Nov 2021 11:49:36 +0100 Subject: [PATCH 144/188] Avoid possible NPE if no build is defined in the pom --- .../org/apache/maven/caching/checksum/MavenProjectInput.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 1084c429239a..6847c6e598a7 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -348,7 +348,8 @@ private String getEffectivePom( Model prototype ) throws IOException PluginManagement pluginManagement = prototype.getBuild().getPluginManagement(); pluginManagement.setPlugins( normalizePlugins( prototype.getBuild().getPluginManagement().getPlugins() ) ); - List plugins = normalizePlugins( prototype.getBuild().getPlugins() ); + List plugins = prototype.getBuild() != null + ? normalizePlugins( prototype.getBuild().getPlugins() ) : new ArrayList<>(); org.apache.maven.model.Build build = new org.apache.maven.model.Build(); build.setPluginManagement( pluginManagement ); From a928405c0af08ff15f78db967bddd56fe6f2b875 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Nov 2021 13:58:15 +0100 Subject: [PATCH 145/188] Use a LifecycleParticipant as they can be session scoped --- ...py.java => CacheLifecycleParticipant.java} | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) rename maven-caching/src/main/java/org/apache/maven/caching/{CacheEventSpy.java => CacheLifecycleParticipant.java} (50%) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheLifecycleParticipant.java similarity index 50% rename from maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java rename to maven-caching/src/main/java/org/apache/maven/caching/CacheLifecycleParticipant.java index 5545b29c2e1c..9554f3027c5f 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheEventSpy.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheLifecycleParticipant.java @@ -19,44 +19,36 @@ * under the License. */ +import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Provider; -import javax.inject.Singleton; +import org.apache.maven.AbstractMavenLifecycleParticipant; +import org.apache.maven.MavenExecutionException; +import org.apache.maven.SessionScoped; import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.eventspy.AbstractEventSpy; -import org.apache.maven.execution.ExecutionEvent; +import org.apache.maven.execution.MavenSession; -/** - * Triggers cache report generation on build completion - */ -@Singleton +@SessionScoped @Named -public class CacheEventSpy extends AbstractEventSpy +@SuppressWarnings( "unused" ) +public class CacheLifecycleParticipant extends AbstractMavenLifecycleParticipant { - // Use Providers to bridge the @SessionScope, as the EventSpy can't be scoped - private final Provider cacheConfig; - private final Provider cacheController; + private final CacheConfig cacheConfig; + private final CacheController cacheController; - public CacheEventSpy( Provider cacheConfig, Provider cacheController ) + @Inject + public CacheLifecycleParticipant( CacheConfig cacheConfig, CacheController cacheController ) { this.cacheConfig = cacheConfig; this.cacheController = cacheController; } @Override - public void onEvent( Object event ) throws Exception + public void afterSessionEnd( MavenSession session ) throws MavenExecutionException { - if ( event instanceof ExecutionEvent ) + if ( cacheConfig.isEnabled() ) { - ExecutionEvent executionEvent = (ExecutionEvent) event; - if ( executionEvent.getType() == ExecutionEvent.Type.SessionEnded ) - { - if ( cacheConfig.get().isEnabled() ) - { - cacheController.get().saveCacheReport( executionEvent.getSession() ); - } - } + cacheController.saveCacheReport( session ); } } -} \ No newline at end of file +} From c80847b1b134c24ba6975e6cf87852c92c874ada Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Nov 2021 14:09:28 +0100 Subject: [PATCH 146/188] Cleanup --- .../maven/caching/CacheControllerImpl.java | 26 +++++----- .../maven/caching/CachingMojoExecutor.java | 5 +- .../caching/HttpCacheRepositoryImpl.java | 13 ++--- .../caching/LocalCacheRepositoryImpl.java | 1 + .../maven/caching/checksum/KeyUtils.java | 33 ++++++++++--- .../caching/checksum/MavenProjectInput.java | 25 +++++----- .../maven/caching/xml/CacheConfigFactory.java | 49 ------------------- .../maven/caching/xml/CacheConfigImpl.java | 1 + 8 files changed, 61 insertions(+), 92 deletions(-) delete mode 100644 maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 2e987bb531df..418505f366ac 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -75,7 +75,6 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MojoExecutionEvent; import org.apache.maven.lifecycle.internal.ProjectIndex; -import org.apache.maven.plugin.MavenPluginManager; import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.descriptor.Parameter; @@ -105,6 +104,7 @@ */ @SessionScoped @Named +@SuppressWarnings( "unused" ) public class CacheControllerImpl implements CacheController { @@ -114,7 +114,6 @@ public class CacheControllerImpl implements CacheController private static final Logger LOGGER = LoggerFactory.getLogger( CacheControllerImpl.class ); - private final MavenPluginManager mavenPluginManager; private final MavenProjectHelper projectHelper; private final RepositorySystem repoSystem; private final ArtifactHandlerManager artifactHandlerManager; @@ -129,7 +128,6 @@ public class CacheControllerImpl implements CacheController @Inject public CacheControllerImpl( - MavenPluginManager mavenPluginManager, MavenProjectHelper projectHelper, RepositorySystem repoSystem, ArtifactHandlerManager artifactHandlerManager, @@ -139,7 +137,6 @@ public CacheControllerImpl( CacheConfig cacheConfig, LifecyclePhasesHelper lifecyclePhasesHelper ) { - this.mavenPluginManager = mavenPluginManager; this.projectHelper = projectHelper; this.localCache = localCache; this.remoteCache = remoteCache; @@ -367,19 +364,20 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) private void putChecksum( Artifact artifact, String projectChecksum ) { - final DigestItem projectArtifact = DtoUtils.createdDigestedByProjectChecksum( artifact, projectChecksum ); final String dependencyKey = KeyUtils.getArtifactKey( artifact ); artifactDigestByKey.put( dependencyKey, projectArtifact ); - if ( !"pom".equals( artifact.getType() ) ) + final ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() ); + String packaging = artifactHandler.getPackaging(); + if ( !Objects.equals( packaging, artifact.getType() ) ) + { + artifactDigestByKey.put( KeyUtils.getArtifactKey( artifact, packaging ), projectArtifact ); + } + String extension = artifactHandler.getExtension(); + if ( !Objects.equals( extension, artifact.getType() ) && !Objects.equals( extension, packaging ) ) { - final ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() ); - Artifact copy = DtoUtils.copy( artifact ); - copy.setType( artifactHandler.getPackaging() ); - artifactDigestByKey.put( KeyUtils.getArtifactKey( copy ), projectArtifact ); - copy.setType( artifactHandler.getExtension() ); - artifactDigestByKey.put( KeyUtils.getArtifactKey( copy ), projectArtifact ); + artifactDigestByKey.put( KeyUtils.getArtifactKey( artifact, extension ), projectArtifact ); } } @@ -389,7 +387,7 @@ private ProjectsInputInfo calculateInput( MavenProject project, MavenSession ses try { final MavenProjectInput inputs = new MavenProjectInput( project, session, cacheConfig, projectIndex, - artifactDigestByKey, repoSystem, artifactHandlerManager, localCache, remoteCache ); + artifactDigestByKey, repoSystem, localCache, remoteCache ); return inputs.calculateChecksum( cacheConfig.getHashFactory() ); } catch ( Exception e ) @@ -761,7 +759,7 @@ else if ( result.getSource() == CacheSource.BUILD && cacheConfig.isSaveToRemote( } } - private void populateGitInfo( Build build, MavenSession session ) throws IOException + private void populateGitInfo( Build build, MavenSession session ) { if ( scm == null ) { diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java index d80cfb1ec843..c5d4e4cceb39 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java @@ -81,6 +81,7 @@ @SessionScoped @Named @Priority( 10 ) +@SuppressWarnings( "unused" ) public class CachingMojoExecutor implements IMojoExecutor { private static final Logger LOGGER = LoggerFactory.getLogger( CachingMojoExecutor.class ); @@ -463,7 +464,7 @@ public void ensureDependenciesAreResolved( MojoDescriptor mojoDescriptor, Collection scopesToResolve = dependencyContext.getScopesToResolveForCurrentProject(); lifeCycleDependencyResolver.resolveProjectDependencies( project, scopesToCollect, scopesToResolve, session, - aggregating, Collections.emptySet() ); + aggregating, Collections.emptySet() ); dependencyContext.synchronizeWithProjectState(); } @@ -480,7 +481,7 @@ public void ensureDependenciesAreResolved( MojoDescriptor mojoDescriptor, if ( aggregatedProject != project ) { lifeCycleDependencyResolver.resolveProjectDependencies( aggregatedProject, scopesToCollect, - scopesToResolve, session, aggregating, Collections.emptySet() ); + scopesToResolve, session, aggregating, Collections.emptySet() ); } } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java index 45e47cec5635..56285b4588b5 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java @@ -116,10 +116,8 @@ public byte[] getArtifactContent( CacheContext context, Artifact artifact ) public void saveBuildInfo( CacheResult cacheResult, Build build ) throws IOException { - CacheContext context = cacheResult.getContext(); final String resourceUrl = getResourceUrl( cacheResult.getContext(), BUILDINFO_XML ); - putToRemoteCache( new ByteArrayInputStream( xmlService.toBytes( build.getDto() ) ), resourceUrl, - context.getProject().getArtifactId() ); + putToRemoteCache( new ByteArrayInputStream( xmlService.toBytes( build.getDto() ) ), resourceUrl ); } @@ -132,19 +130,17 @@ public void saveCacheReport( String buildId, MavenSession session, CacheReport c + "/" + rootProject.getArtifactId() + "/" + buildId + "/" + CACHE_REPORT_XML; - putToRemoteCache( new ByteArrayInputStream( xmlService.toBytes( cacheReport ) ), resourceUrl, - rootProject.getArtifactId() ); + putToRemoteCache( new ByteArrayInputStream( xmlService.toBytes( cacheReport ) ), resourceUrl ); } @Override public void saveArtifactFile( CacheResult cacheResult, org.apache.maven.artifact.Artifact artifact ) throws IOException { - CacheContext context = cacheResult.getContext(); final String resourceUrl = getResourceUrl( cacheResult.getContext(), CacheUtils.normalizedName( artifact ) ); try ( InputStream inputStream = Files.newInputStream( artifact.getFile().toPath() ) ) { - putToRemoteCache( inputStream, resourceUrl, context.getProject().getArtifactId() ); + putToRemoteCache( inputStream, resourceUrl ); } } @@ -219,10 +215,9 @@ private String getResourceUrl( String filename, String groupId, String artifactI } /** - * @param logReference * @param instream to be closed externally */ - private void putToRemoteCache( InputStream instream, String url, String logReference ) throws IOException + private void putToRemoteCache( InputStream instream, String url ) throws IOException { HttpPut httpPut = null; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java index dd5b49bfd4b4..e70d9e95622f 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java @@ -74,6 +74,7 @@ */ @SessionScoped @Named +@SuppressWarnings( "unused" ) public class LocalCacheRepositoryImpl implements LocalCacheRepository { diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java index 3fa9d5d8744d..f94ddd11fc85 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java @@ -49,15 +49,36 @@ public static String getVersionlessDependencyKey( Dependency dependency ) public static String getArtifactKey( Artifact artifact ) { - return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() - + ( artifact.getClassifier() != null ? ":" + artifact.getClassifier() : "" ) - + ":" + artifact.getVersion(); + return getArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), + artifact.getClassifier(), artifact.getVersion() ); + } + + /** + * Computes the key for the given artifact, using the given type instead of the one + * defined in the artifact. + */ + public static String getArtifactKey( Artifact artifact, String type ) + { + return getArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), type, + artifact.getClassifier(), artifact.getVersion() ); } public static String getArtifactKey( org.apache.maven.artifact.Artifact artifact ) { - return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() - + ( artifact.getClassifier() != null ? ":" + artifact.getClassifier() : "" ) - + ":" + artifact.getVersion(); + return getArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), + artifact.getClassifier(), artifact.getVersion() ); + } + + public static String getArtifactKey( String groupId, String artifactId, String type, + String classifier, String version ) + { + if ( classifier != null ) + { + return StringUtils.joinWith( SEPARATOR, groupId, artifactId, type, classifier, version ); + } + else + { + return StringUtils.joinWith( SEPARATOR, groupId, artifactId, type, version ); + } } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 6847c6e598a7..b90cc81e0b10 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -49,7 +49,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.caching.LocalCacheRepository; @@ -136,7 +135,6 @@ public class MavenProjectInput private final LocalCacheRepository localCache; private final RemoteCacheRepository remoteCache; private final RepositorySystem repoSystem; - private final ArtifactHandlerManager artifactHandlerManager; private final CacheConfig config; private final ConcurrentMap projectArtifactsByKey; private final PathIgnoringCaseComparator fileComparator; @@ -154,7 +152,6 @@ public MavenProjectInput( MavenProject project, ProjectIndex projectIndex, ConcurrentMap artifactsByKey, RepositorySystem repoSystem, - ArtifactHandlerManager artifactHandlerManager, LocalCacheRepository localCache, RemoteCacheRepository remoteCache ) { @@ -165,7 +162,6 @@ public MavenProjectInput( MavenProject project, this.projectArtifactsByKey = artifactsByKey; this.baseDirPath = project.getBasedir().toPath().toAbsolutePath(); this.repoSystem = repoSystem; - this.artifactHandlerManager = artifactHandlerManager; this.localCache = localCache; this.remoteCache = remoteCache; Properties properties = project.getProperties(); @@ -345,17 +341,22 @@ private String getEffectivePom( Model prototype ) throws IOException prototype.getDependencies().sort( dependencyComparator ); toHash.setDependencies( prototype.getDependencies() ); - PluginManagement pluginManagement = prototype.getBuild().getPluginManagement(); - pluginManagement.setPlugins( normalizePlugins( prototype.getBuild().getPluginManagement().getPlugins() ) ); + if ( prototype.getBuild() != null ) + { + org.apache.maven.model.Build build = new org.apache.maven.model.Build(); - List plugins = prototype.getBuild() != null - ? normalizePlugins( prototype.getBuild().getPlugins() ) : new ArrayList<>(); + PluginManagement pluginManagement = prototype.getBuild().getPluginManagement(); + if ( pluginManagement != null ) + { + pluginManagement.setPlugins( normalizePlugins( pluginManagement.getPlugins() ) ); + } + build.setPluginManagement( pluginManagement ); - org.apache.maven.model.Build build = new org.apache.maven.model.Build(); - build.setPluginManagement( pluginManagement ); - build.setPlugins( plugins ); + List plugins = normalizePlugins( prototype.getBuild().getPlugins() ); + build.setPlugins( plugins ); - toHash.setBuild( build ); + toHash.setBuild( build ); + } ByteArrayOutputStream output = new ByteArrayOutputStream(); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java deleted file mode 100644 index 39782a76a1ac..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigFactory.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.apache.maven.caching.xml; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.caching.CacheUtils; -import org.apache.maven.execution.MavenSession; - -@Singleton -@Named -public class CacheConfigFactory -{ - - private static final Object KEY = CacheConfigFactory.class.getName(); - - private final XmlService xmlService; - - @Inject - public CacheConfigFactory( XmlService xmlService ) - { - this.xmlService = xmlService; - } - - public CacheConfig getCacheConfig( MavenSession session ) - { - return CacheUtils.getOrCreate( session, KEY, () -> new CacheConfigImpl( xmlService, session ) ); - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index cc50d32dc5c7..c4d890882387 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -73,6 +73,7 @@ */ @SessionScoped @Named +@SuppressWarnings( "unused" ) public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig { From 03bc795ac195a9b86c4964ec65d4bf29298168c7 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Nov 2021 14:11:36 +0100 Subject: [PATCH 147/188] Remove empty lines after block start --- .../org/apache/maven/caching/CacheControllerImpl.java | 9 --------- .../main/java/org/apache/maven/caching/CacheDiff.java | 3 --- .../org/apache/maven/caching/CachingMojoExecutor.java | 3 --- .../apache/maven/caching/HttpCacheRepositoryImpl.java | 1 - .../apache/maven/caching/LocalCacheRepositoryImpl.java | 1 - .../org/apache/maven/caching/PluginScanConfigImpl.java | 2 -- .../apache/maven/caching/checksum/MavenProjectInput.java | 7 ------- .../java/org/apache/maven/caching/checksum/WalkKey.java | 1 - .../main/java/org/apache/maven/caching/xml/Build.java | 2 -- .../org/apache/maven/caching/xml/CacheConfigImpl.java | 3 --- .../main/java/org/apache/maven/caching/xml/DtoUtils.java | 1 - 11 files changed, 33 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 418505f366ac..d32477b1e531 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -153,7 +153,6 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, ProjectIndex projectIndex, List mojoExecutions ) { - final String highestRequestPhase = CacheUtils.getLast( mojoExecutions ).getLifecyclePhase(); if ( !lifecyclePhasesHelper.isLaterPhaseThanClean( highestRequestPhase ) ) { @@ -170,7 +169,6 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, if ( !result.isSuccess() && result.getContext() != null ) { - LOGGER.debug( "Remote cache is incomplete or missing, trying local build" ); CacheResult localBuild = findLocalBuild( mojoExecutions, context ); @@ -221,7 +219,6 @@ private CacheResult analyzeResult( CacheContext context, List moj { if ( info != null ) { - final ProjectsInputInfo inputInfo = context.getInputInfo(); LOGGER.info( "Found cached build, restoring from cache {}", inputInfo.getChecksum() ); @@ -293,7 +290,6 @@ private boolean canIgnoreMissingSegment( Build info, List mojoExe @Override public boolean restoreProjectArtifacts( CacheResult cacheResult ) { - final Build build = cacheResult.getBuildInfo(); final CacheContext context = cacheResult.getContext(); final MavenProject project = context.getProject(); @@ -400,7 +396,6 @@ private ProjectsInputInfo calculateInput( MavenProject project, MavenSession ses public void save( CacheResult cacheResult, List mojoExecutions, Map executionEvents ) { - CacheContext context = cacheResult.getContext(); if ( context == null || context.getInputInfo() == null ) @@ -413,7 +408,6 @@ public void save( CacheResult cacheResult, List mojoExecutions, final MavenSession session = context.getSession(); try { - attachGeneratedSources( project ); attachOutputs( project ); @@ -627,7 +621,6 @@ private void recordMojoProperties( CompletedExecution execution, MojoExecutionEv private boolean isExcluded( String propertyName, boolean logAll, List excludedProperties, List forceLogProperties ) { - if ( !forceLogProperties.isEmpty() ) { for ( PropertyName logProperty : forceLogProperties ) @@ -672,7 +665,6 @@ private boolean isCachedSegmentPropertiesPresent( MavenProject project, Build bu { for ( MojoExecution mojoExecution : mojoExecutions ) { - // completion of all mojos checked above, so we expect tp have execution info here final List trackedProperties = cacheConfig.getTrackedProperties( mojoExecution ); final CompletedExecution cachedExecution = build.findMojoExecutionInfo( mojoExecution ); @@ -910,7 +902,6 @@ private boolean isOutputArtifact( String name ) private static class ArtifactToAttach { - private final String type; private final String classifier; private final File file; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java index 550b546f5759..535cf79e2d5b 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java @@ -60,7 +60,6 @@ public CacheDiff( Build current, Build baseline, CacheConfig config ) public Diff compare() { - if ( !StringUtils.equals( current.getHashFunction(), baseline.getHashFunction() ) ) { addNewMismatch( @@ -115,7 +114,6 @@ public static Optional findPom( ProjectsInputInfo projectInputs ) private void compareFiles( ProjectsInputInfo current, ProjectsInputInfo baseline ) { - final Map currentFiles = current.getItems().stream() .filter( item -> "file".equals( item.getType() ) ) .collect( Collectors.toMap( DigestItem::getValue, item -> item ) ); @@ -147,7 +145,6 @@ private void compareFiles( ProjectsInputInfo current, ProjectsInputInfo baseline final DigestItem baselineFile = baselineFiles.get( filePath ); if ( !StringUtils.equals( currentFile.getHash(), baselineFile.getHash() ) ) { - String reason = "File content is different."; if ( currentFile.getEol() != null && baselineFile.getEol() != null && !StringUtils.equals( baselineFile.getEol(), currentFile.getEol() ) ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java index c5d4e4cceb39..abf4d7d46e5e 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojoExecutor.java @@ -255,7 +255,6 @@ private boolean restoreProject( CacheResult cacheResult, PhaseRecorder phaseRecorder, CacheConfig cacheConfig ) throws LifecycleExecutionException { - final Build build = cacheResult.getBuildInfo(); final MavenProject project = cacheResult.getContext().getProject(); final MavenSession session = cacheResult.getContext().getSession(); @@ -270,7 +269,6 @@ private boolean restoreProject( CacheResult cacheResult, for ( MojoExecution cacheCandidate : cachedSegment ) { - if ( cacheController.isForcedExecution( project, cacheCandidate ) ) { LOGGER.info( "Mojo execution is forced by project property: {}", @@ -318,7 +316,6 @@ private boolean verifyCacheConsistency( MojoExecution cacheCandidate, PhaseRecorder phaseRecorder, CacheConfig cacheConfig ) throws LifecycleExecutionException { - AtomicBoolean consistent = new AtomicBoolean( true ); final MojoExecutionManager mojoChecker = new MojoExecutionManager( project, cachedBuild, consistent, cacheConfig ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java index 56285b4588b5..6c5ef598c10c 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java @@ -219,7 +219,6 @@ private String getResourceUrl( String filename, String groupId, String artifactI */ private void putToRemoteCache( InputStream instream, String url ) throws IOException { - HttpPut httpPut = null; try { diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java index e70d9e95622f..b24c7c748143 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java @@ -128,7 +128,6 @@ public Build findLocalBuild( CacheContext context ) throws IOException @Override public Build findBuild( CacheContext context ) throws IOException { - Path buildInfoPath = remoteBuildPath( context, BUILDINFO_XML ); LOGGER.debug( "Checking if build is already downloaded: {}", buildInfoPath ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java index 34f71802e1f7..76dee362be65 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java @@ -77,7 +77,6 @@ private boolean contains( List excludes, String tagName ) @Override public PluginScanConfig mergeWith( final PluginScanConfig overrideConfig ) { - if ( dto == null ) { return overrideConfig; @@ -138,7 +137,6 @@ private ScanConfigProperties findTagScanProperties( String tagName ) private ScanConfigProperties findConfigByName( String tagName, List configs ) { - if ( configs == null ) { return null; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index b90cc81e0b10..97e37c5da7ff 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -457,7 +457,6 @@ private void startWalk( Path candidate, List collectedFiles, Set visitedDirs ) { - Path normalized = candidate.isAbsolute() ? candidate : baseDirPath.resolve( candidate ); normalized = normalized.toAbsolutePath().normalize(); WalkKey key = new WalkKey( normalized, glob, recursive ); @@ -499,11 +498,9 @@ private Path normalizedPath( String directory ) private void collectFromPlugins( List files, HashSet visitedDirs ) { - List plugins = project.getBuild().getPlugins(); for ( Plugin plugin : plugins ) { - PluginScanConfig scanConfig = config.getPluginDirScanConfig( plugin ); if ( scanConfig.isSkip() ) @@ -521,7 +518,6 @@ private void collectFromPlugins( List files, HashSet visitedDirs for ( PluginExecution exec : plugin.getExecutions() ) { - final PluginScanConfig executionScanConfig = config.getExecutionDirScanConfig( plugin, exec ); PluginScanConfig mergedConfig = scanConfig.mergeWith( executionScanConfig ); @@ -589,7 +585,6 @@ private void addInputsFromPluginConfigs( Xpp3Dom[] configurationChildren, PluginScanConfig scanConfig, List files, HashSet visitedDirs ) { - if ( configurationChildren == null ) { return; @@ -597,7 +592,6 @@ private void addInputsFromPluginConfigs( Xpp3Dom[] configurationChildren, for ( Xpp3Dom configChild : configurationChildren ) { - String tagName = configChild.getName(); String tagValue = configChild.getValue(); @@ -775,7 +769,6 @@ private SortedMap getMutableDependencies() throws IOExceptio private DigestItem resolveArtifact( final Artifact dependencyArtifact, MultimoduleDiscoveryStrategy strategy ) throws IOException { - ArtifactResolutionRequest request = new ArtifactResolutionRequest() .setArtifact( dependencyArtifact ) .setResolveRoot( true ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/WalkKey.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/WalkKey.java index 0d6f274df5b6..31a23ded054d 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/WalkKey.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/WalkKey.java @@ -32,7 +32,6 @@ public class WalkKey public WalkKey( Path normalized, String glob, boolean recursive ) { - this.normalized = normalized; this.glob = glob; this.recursive = recursive; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java index b2098c1e1fba..303874b1669e 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java @@ -136,7 +136,6 @@ public String toString() public CompletedExecution findMojoExecutionInfo( MojoExecution mojoExecution ) { - if ( dto.getExecutions() == null ) { return null; @@ -184,7 +183,6 @@ public String getHighestCompletedGoal() public DigestItem findArtifact( Dependency dependency ) { - if ( CacheUtils.isPom( dependency ) ) { throw new IllegalArgumentException( "Pom dependencies should not be treated as artifacts: " + dependency ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index c4d890882387..2a013b8ea8b7 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -201,7 +201,6 @@ public boolean isLogAllProperties( MojoExecution mojoExecution ) private GoalReconciliation findReconciliationConfig( MojoExecution mojoExecution ) { - if ( cacheConfig.getExecutionControl() == null ) { return null; @@ -217,7 +216,6 @@ private GoalReconciliation findReconciliationConfig( MojoExecution mojoExecution for ( GoalReconciliation goalReconciliationConfig : reconciliation ) { - final String goal = mojoExecution.getGoal(); if ( isPluginMatch( mojoExecution.getPlugin(), goalReconciliationConfig ) && StringUtils.equals( goal, @@ -278,7 +276,6 @@ public List getEffectivePomExcludeProperties( Plugin plugin ) private PluginConfigurationScan findPluginScanConfig( Plugin plugin ) { - if ( cacheConfig.getInput() == null ) { return null; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java index 16751e91d364..88f5b1179cf0 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java @@ -136,7 +136,6 @@ public static void addProperty( CompletedExecution execution, public static boolean containsAllProperties( @Nonnull CompletedExecution cachedExecution, List trackedProperties ) { - if ( trackedProperties == null || trackedProperties.isEmpty() ) { return true; From c095e550d3aaf2c6a670950d492a940c80ef6f3f Mon Sep 17 00:00:00 2001 From: Andrey Petrenko Date: Wed, 17 Nov 2021 21:54:13 +0300 Subject: [PATCH 148/188] MNG-7129: caching extension --- .../maven/caching/CacheControllerImpl.java | 35 ++-- .../org/apache/maven/caching/CacheUtils.java | 6 + .../CachingMojosExecutionStrategy.java | 112 ++++++++++-- .../maven/caching/MojoExecutionManager.java | 153 ----------------- .../caching/checksum/MavenProjectInput.java | 161 +++++++++++------- .../org/apache/maven/caching/xml/Build.java | 59 +++---- maven-caching/src/main/mdo/cache-config.mdo | 2 - .../org/apache/maven/plugin/MojoCheker.java | 38 ----- .../apache/maven/plugin/MojoExecution.java | 23 +-- .../maven/project/DefaultProjectBuilder.java | 129 +++++++------- .../apache/maven/project/MavenProject.java | 18 +- 11 files changed, 324 insertions(+), 412 deletions(-) delete mode 100644 maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java delete mode 100644 maven-core/src/main/java/org/apache/maven/plugin/MojoCheker.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 424a30dad107..04cabd639054 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -31,6 +31,7 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -74,6 +75,7 @@ import org.apache.maven.caching.xml.report.ProjectReport; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MojoExecutionEvent; +import org.apache.maven.lifecycle.internal.builder.BuilderCommon; import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.descriptor.Parameter; @@ -123,8 +125,8 @@ public class CacheControllerImpl implements CacheController private final ConcurrentMap artifactDigestByKey = new ConcurrentHashMap<>(); private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); private final LifecyclePhasesHelper lifecyclePhasesHelper; - private final MavenSession mavenSession; private volatile Scm scm; + private volatile Map projectIndex; @Inject public CacheControllerImpl( @@ -133,10 +135,9 @@ public CacheControllerImpl( ArtifactHandlerManager artifactHandlerManager, XmlService xmlService, LocalCacheRepository localCache, - RemoteCacheRepository remoteCache, + RemoteCacheRepository remoteCache, CacheConfig cacheConfig, - LifecyclePhasesHelper lifecyclePhasesHelper, - MavenSession mavenSession ) + LifecyclePhasesHelper lifecyclePhasesHelper ) { this.projectHelper = projectHelper; this.localCache = localCache; @@ -146,7 +147,6 @@ public CacheControllerImpl( this.artifactHandlerManager = artifactHandlerManager; this.xmlService = xmlService; this.lifecyclePhasesHelper = lifecyclePhasesHelper; - this.mavenSession = mavenSession; } @Override @@ -229,9 +229,9 @@ private CacheResult analyzeResult( CacheContext context, List moj if ( !CACHE_IMPLEMENTATION_VERSION.equals( cacheImplementationVersion ) ) { LOGGER.warn( - "Maven and cached build implementations mismatch, caching might not work correctly. " + "Maven and cached build implementations mismatch, caching might not work correctly. " + "Implementation version: " + CACHE_IMPLEMENTATION_VERSION + ", cached build: {}", - info.getCacheImplementationVersion() ); + info.getCacheImplementationVersion() ); } List cachedSegment = lifecyclePhasesHelper.getCachedSegment( mojoExecutions, info ); @@ -308,7 +308,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) final Path artifactFile = localCache.getArtifactFile( context, cacheResult.getSource(), artifact ); if ( !Files.exists( artifactFile ) ) { - LOGGER.info( "Missing file for cached build, cannot restore. File: {}", artifactFile ); + LOGGER.info( "Missing file for cached build, cannot restore. File: {}", artifactFile ); return false; } LOGGER.debug( "Setting project artifact {} from {}", artifact.getArtifactId(), artifactFile ); @@ -329,7 +329,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) "Missing file for cached build, cannot restore. File: " + attachedArtifactFile ); } LOGGER.debug( "Attaching artifact {} from {}", - artifact.getArtifactId(), attachedArtifactFile ); + artifact.getArtifactId(), attachedArtifactFile ); if ( StringUtils.startsWith( attachedArtifact.getClassifier(), GENERATEDSOURCES_PREFIX ) ) { // generated sources artifact @@ -382,7 +382,18 @@ private ProjectsInputInfo calculateInput( MavenProject project, MavenSession ses { try { - final MavenProjectInput inputs = new MavenProjectInput( project, session, cacheConfig, + if ( this.projectIndex == null ) + { + Map projectMap = new HashMap<>( + session.getProjects().size() * 2 + ); + for ( MavenProject p : session.getProjects() ) + { + projectMap.put( BuilderCommon.getKey( p ), p ); + } + this.projectIndex = projectMap; + } + final MavenProjectInput inputs = new MavenProjectInput( project, projectIndex, session, cacheConfig, artifactDigestByKey, repoSystem, localCache, remoteCache ); return inputs.calculateChecksum( cacheConfig.getHashFactory() ); } @@ -672,14 +683,14 @@ private boolean isCachedSegmentPropertiesPresent( MavenProject project, Build bu if ( cachedExecution == null ) { LOGGER.info( "Execution is not cached. Plugin: {}, goal {}", - mojoExecution.getExecutionId(), mojoExecution.getGoal() ); + mojoExecution.getExecutionId(), mojoExecution.getGoal() ); return false; } if ( !DtoUtils.containsAllProperties( cachedExecution, trackedProperties ) ) { LOGGER.info( "Build info doesn't match rules. Plugin: {}", - mojoExecution.getExecutionId() ); + mojoExecution.getExecutionId() ); return false; } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java index 9a7857b908e9..feac5df68e9a 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java @@ -26,6 +26,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.project.MavenProject; import org.eclipse.aether.SessionData; import java.io.IOException; @@ -55,6 +56,11 @@ public class CacheUtils { + public static boolean isPom( MavenProject project ) + { + return project.getPackaging().equals( "pom" ); + } + public static boolean isPom( Dependency dependency ) { return dependency.getType().equals( "pom" ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojosExecutionStrategy.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojosExecutionStrategy.java index 8c290cabd09f..11d6d9857347 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojosExecutionStrategy.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojosExecutionStrategy.java @@ -21,27 +21,36 @@ import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; import javax.inject.Inject; import javax.inject.Named; +import org.apache.commons.lang3.StringUtils; import org.apache.maven.SessionScoped; import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.CacheState; +import org.apache.maven.caching.xml.DtoUtils; +import org.apache.maven.caching.xml.build.CompletedExecution; +import org.apache.maven.caching.xml.config.TrackedProperty; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MojoExecutionEvent; import org.apache.maven.lifecycle.LifecycleExecutionException; +import org.apache.maven.plugin.MavenPluginManager; +import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecution.Source; import org.apache.maven.plugin.MojoExecutionRunner; import org.apache.maven.plugin.MojosExecutionStrategy; +import org.apache.maven.plugin.PluginConfigurationException; +import org.apache.maven.plugin.PluginContainerException; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.ReflectionUtils; import org.eclipse.sisu.Priority; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.maven.caching.CacheUtils.mojoExecutionKey; import static org.apache.maven.caching.checksum.KeyUtils.getVersionlessProjectKey; import static org.apache.maven.caching.xml.CacheState.DISABLED; import static org.apache.maven.caching.xml.CacheState.INITIALIZED; @@ -64,18 +73,21 @@ public class CachingMojosExecutionStrategy implements MojosExecutionStrategy private final CacheConfig cacheConfig; private final MojoParametersListener mojoListener; private final LifecyclePhasesHelper lifecyclePhasesHelper; + private final MavenPluginManager mavenPluginManager; @Inject public CachingMojosExecutionStrategy( CacheController cacheController, CacheConfig cacheConfig, MojoParametersListener mojoListener, - LifecyclePhasesHelper lifecyclePhasesHelper ) + LifecyclePhasesHelper lifecyclePhasesHelper, + MavenPluginManager mavenPluginManager ) { this.cacheController = cacheController; this.cacheConfig = cacheConfig; this.mojoListener = mojoListener; this.lifecyclePhasesHelper = lifecyclePhasesHelper; + this.mavenPluginManager = mavenPluginManager; } public void execute( List mojoExecutions, @@ -174,7 +186,7 @@ private boolean restoreProject( CacheResult cacheResult, if ( cacheController.isForcedExecution( project, cacheCandidate ) ) { LOGGER.info( "Mojo execution is forced by project property: {}", - cacheCandidate.getMojoDescriptor().getFullGoalName() ); + cacheCandidate.getMojoDescriptor().getFullGoalName() ); mojoExecutionRunner.run( cacheCandidate ); } else @@ -216,31 +228,103 @@ private boolean verifyCacheConsistency( MojoExecution cacheCandidate, MojoExecutionRunner mojoExecutionRunner, CacheConfig cacheConfig ) throws LifecycleExecutionException { - AtomicBoolean consistent = new AtomicBoolean( true ); - final MojoExecutionManager mojoChecker = new MojoExecutionManager( project, cachedBuild, - consistent, cacheConfig ); + long createdTimestamp = System.currentTimeMillis(); + boolean consistent = true; - if ( mojoChecker.needCheck( cacheCandidate, session ) ) + if ( !cacheConfig.getTrackedProperties( cacheCandidate ).isEmpty() ) { + Mojo mojo = null; try { - // actual execution will not happen (if not forced). decision delayed to execution time - // then all properties are resolved. - cacheCandidate.setMojoExecutionManager( mojoChecker ); - mojoExecutionRunner.run( cacheCandidate ); + mojo = mavenPluginManager.getConfiguredMojo( Mojo.class, session, cacheCandidate ); + final CompletedExecution completedExecution = cachedBuild.findMojoExecutionInfo( cacheCandidate ); + final String fullGoalName = cacheCandidate.getMojoDescriptor().getFullGoalName(); + + if ( completedExecution != null + && !isParamsMatched( cacheCandidate, mojo, completedExecution ) ) + { + LOGGER.info( "Mojo cached parameters mismatch with actual, forcing full project build. Mojo: {}", + fullGoalName ); + consistent = false; + } + + if ( consistent ) + { + long elapsed = System.currentTimeMillis() - createdTimestamp; + LOGGER.info( "Skipping plugin execution (reconciled in {} millis): {}", elapsed, fullGoalName ); + } + + if ( LOGGER.isDebugEnabled() ) + { + LOGGER.debug( "Checked {}, resolved mojo: {}, cached params: {}", + fullGoalName, mojo, completedExecution ); + } + } + catch ( PluginContainerException | PluginConfigurationException e ) + { + throw new LifecycleExecutionException( "Cannot get configured mojo", e ); } finally { - cacheCandidate.setMojoExecutionManager( null ); + if ( mojo != null ) + { + mavenPluginManager.releaseMojo( mojo, cacheCandidate ); + } } } else { LOGGER.info( "Skipping plugin execution (cached): {}", - cacheCandidate.getMojoDescriptor().getFullGoalName() ); + cacheCandidate.getMojoDescriptor().getFullGoalName() ); } - return consistent.get(); + return consistent; + } + + private boolean isParamsMatched( MojoExecution mojoExecution, + Mojo mojo, + CompletedExecution completedExecution ) + { + List tracked = cacheConfig.getTrackedProperties( mojoExecution ); + + for ( TrackedProperty trackedProperty : tracked ) + { + final String propertyName = trackedProperty.getPropertyName(); + + String expectedValue = DtoUtils.findPropertyValue( propertyName, completedExecution ); + if ( expectedValue == null && trackedProperty.getDefaultValue() != null ) + { + expectedValue = trackedProperty.getDefaultValue(); + } + + final String currentValue; + try + { + currentValue = String.valueOf( ReflectionUtils.getValueIncludingSuperclasses( propertyName, mojo ) ); + } + catch ( IllegalAccessException e ) + { + LOGGER.error( "Cannot extract plugin property {} from mojo {}", propertyName, mojo, e ); + return false; + } + + if ( !StringUtils.equals( currentValue, expectedValue ) ) + { + if ( !StringUtils.equals( currentValue, trackedProperty.getSkipValue() ) ) + { + LOGGER.info( "Plugin parameter mismatch found. Parameter: {}, expected: {}, actual: {}", + propertyName, expectedValue, currentValue ); + return false; + } + else + { + LOGGER.warn( "Cache contains plugin execution with skip flag and might be incomplete. " + + "Property: {}, execution {}", + propertyName, mojoExecutionKey( mojoExecution ) ); + } + } + } + return true; } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java deleted file mode 100644 index 95a9ef06569b..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/MojoExecutionManager.java +++ /dev/null @@ -1,153 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.DtoUtils; -import org.apache.maven.caching.xml.Build; -import org.apache.maven.caching.xml.config.TrackedProperty; -import org.apache.maven.caching.xml.build.CompletedExecution; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.Mojo; -import org.apache.maven.plugin.MojoCheker; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.ReflectionUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.apache.maven.caching.CacheUtils.mojoExecutionKey; - -/** - * MojoExecutionManager - */ -public class MojoExecutionManager implements MojoCheker -{ - - private static final Logger LOGGER = LoggerFactory.getLogger( MojoExecutionManager.class ); - - private final long createdTimestamp; - private final MavenProject project; - private final Build build; - private final AtomicBoolean consistent; - private final CacheConfig cacheConfig; - - public MojoExecutionManager( MavenProject project, - Build build, - AtomicBoolean consistent, - CacheConfig cacheConfig ) - { - this.createdTimestamp = System.currentTimeMillis(); - this.project = project; - this.build = build; - this.consistent = consistent; - this.cacheConfig = cacheConfig; - } - - /** - * runtime check is rather expensive for cached build and better to be avoided when possible - */ - @Override - public boolean needCheck( MojoExecution mojoExecution, MavenSession session ) - { - return !cacheConfig.getTrackedProperties( mojoExecution ).isEmpty(); - } - - /** - * this implementation has side effect of consistency check to force local save if local run is different than - * cached - * - * @return false always returns false to prevent mojo execution - */ - @Override - public boolean check( MojoExecution execution, Mojo mojo, MavenSession session ) - { - final CompletedExecution completedExecution = build.findMojoExecutionInfo( execution ); - final String fullGoalName = execution.getMojoDescriptor().getFullGoalName(); - - if ( completedExecution != null && !isParamsMatched( execution, mojo, completedExecution ) ) - { - LOGGER.info( "Mojo cached parameters mismatch with actual, forcing full project build. Mojo: {}", - fullGoalName ); - consistent.set( false ); - } - - if ( consistent.get() ) - { - long elapsed = System.currentTimeMillis() - createdTimestamp; - LOGGER.info( "Skipping plugin execution (reconciled in {} millis): {}", elapsed, fullGoalName ); - } - - LOGGER.debug( "Checked {}, resolved mojo: {}, cached params: {}", - fullGoalName, mojo, completedExecution ); - return false; - } - - private boolean isParamsMatched( MojoExecution mojoExecution, - Mojo mojo, - CompletedExecution completedExecution ) - { - List tracked = cacheConfig.getTrackedProperties( mojoExecution ); - - for ( TrackedProperty trackedProperty : tracked ) - { - final String propertyName = trackedProperty.getPropertyName(); - - String expectedValue = DtoUtils.findPropertyValue( propertyName, completedExecution ); - if ( expectedValue == null && trackedProperty.getDefaultValue() != null ) - { - expectedValue = trackedProperty.getDefaultValue(); - } - - final String currentValue; - try - { - currentValue = String.valueOf( ReflectionUtils.getValueIncludingSuperclasses( propertyName, mojo ) ); - } - catch ( IllegalAccessException e ) - { - LOGGER.error( "Cannot extract plugin property {} from mojo {}", propertyName, mojo, e ); - return false; - } - - if ( !StringUtils.equals( currentValue, expectedValue ) ) - { - if ( !StringUtils.equals( currentValue, trackedProperty.getSkipValue() ) ) - { - LOGGER.info( "Plugin parameter mismatch found. Parameter: {}, expected: {}, actual: {}", - propertyName, expectedValue, currentValue ); - return false; - } - else - { - LOGGER.warn( "Cache contains plugin execution with skip flag and might be incomplete. " - + "Property: {}, execution {}", - propertyName, mojoExecutionKey( mojoExecution ) ); - } - } - } - return true; - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index cff2e0c23697..eb6e729c502d 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -32,11 +32,11 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.Properties; import java.util.Set; @@ -45,6 +45,7 @@ import java.util.TreeMap; import java.util.TreeSet; import java.util.concurrent.ConcurrentMap; +import java.util.stream.Collectors; import javax.annotation.Nonnull; @@ -68,6 +69,7 @@ import org.apache.maven.caching.xml.config.Exclude; import org.apache.maven.caching.xml.config.Include; import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.internal.builder.BuilderCommon; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; @@ -90,6 +92,7 @@ import static org.apache.commons.lang3.StringUtils.replaceEachRepeatedly; import static org.apache.commons.lang3.StringUtils.startsWithAny; import static org.apache.commons.lang3.StringUtils.stripToEmpty; +import static org.apache.maven.caching.CacheUtils.isPom; import static org.apache.maven.caching.CacheUtils.isSnapshot; /** @@ -142,9 +145,11 @@ public class MavenProjectInput private final Path baseDirPath; private final String dirGlob; private final boolean processPlugins; + private final Map projectIndex; @SuppressWarnings( "checkstyle:parameternumber" ) public MavenProjectInput( MavenProject project, + Map projectIndex, MavenSession session, CacheConfig config, ConcurrentMap artifactsByKey, @@ -155,6 +160,7 @@ public MavenProjectInput( MavenProject project, this.project = project; this.session = session; this.config = config; + this.projectIndex = projectIndex; this.projectArtifactsByKey = artifactsByKey; this.baseDirPath = project.getBasedir().toPath().toAbsolutePath(); this.repoSystem = repoSystem; @@ -191,8 +197,8 @@ public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOE { final long t0 = System.currentTimeMillis(); - final String effectivePom = getEffectivePom( project.getOriginalEffectiveModel() ); - final SortedSet inputFiles = getInputFiles(); + final String effectivePom = getEffectivePom( project.getModel() ); + final SortedSet inputFiles = isPom( project ) ? Collections.emptySortedSet() : getInputFiles(); final SortedMap dependenciesChecksum = getMutableDependencies(); final long t1 = System.currentTimeMillis(); @@ -283,7 +289,7 @@ private void checkEffectivePomMatch( ProjectsInputInfo baselineBuild, DigestItem if ( !matches ) { LOGGER.info( "Mismatch in effective poms. Current: {}, remote: {}", - effectivePomChecksum.getHash(), pomItem.getHash() ); + effectivePomChecksum.getHash(), pomItem.getHash() ); } LOGGER.info( "Effective pom: {}", matches ? "MATCHED" : "OUT OF DATE" ); } @@ -321,10 +327,8 @@ private boolean checkItemMatchesBaseline( ProjectsInputInfo baselineBuild, Diges return matched; } - /** - * @param prototype effective model fully resolved by maven build. Do not pass here just parsed Model. - */ - private String getEffectivePom( Model prototype ) throws IOException + //prototype must not be affected + private Model normalizeModel( Model prototype ) { // TODO validate status of the model - it should be in resolved state Model toHash = new Model(); @@ -334,33 +338,49 @@ private String getEffectivePom( Model prototype ) throws IOException toHash.setVersion( prototype.getVersion() ); toHash.setModules( prototype.getModules() ); - prototype.getDependencies().sort( dependencyComparator ); - toHash.setDependencies( prototype.getDependencies() ); + toHash.setDependencies( + prototype.getDependencies().stream() + .sorted( dependencyComparator ) + .collect( Collectors.toList() ) + ); - if ( prototype.getBuild() != null ) + org.apache.maven.model.Build protoBuild = prototype.getBuild(); + if ( protoBuild == null ) { - org.apache.maven.model.Build build = new org.apache.maven.model.Build(); + return toHash; + } - PluginManagement pluginManagement = prototype.getBuild().getPluginManagement(); - if ( pluginManagement != null ) - { - pluginManagement.setPlugins( normalizePlugins( pluginManagement.getPlugins() ) ); - } - build.setPluginManagement( pluginManagement ); + org.apache.maven.model.Build buildToHash = new org.apache.maven.model.Build(); - List plugins = normalizePlugins( prototype.getBuild().getPlugins() ); - build.setPlugins( plugins ); + List plugins = normalizePlugins( prototype.getBuild().getPlugins() ); + buildToHash.setPlugins( plugins ); - toHash.setBuild( build ); + PluginManagement pluginManagement = buildToHash.getPluginManagement(); + //if it is not a pom packaging no need to track plugin management section in effective pom + //as it contributes into plugins section + if ( pluginManagement != null && isPom( this.project ) ) + { + PluginManagement pluginManagementToHash = pluginManagement.clone(); + pluginManagementToHash.setPlugins( normalizePlugins( pluginManagement.getPlugins() ) ); + buildToHash.setPluginManagement( pluginManagementToHash ); } + toHash.setBuild( buildToHash ); + return toHash; + } + + /** + * @param prototype effective model fully resolved by maven build. Do not pass here just parsed Model. + */ + private String getEffectivePom( Model prototype ) throws IOException + { ByteArrayOutputStream output = new ByteArrayOutputStream(); Writer writer = null; try { writer = WriterFactory.newXmlWriter( output ); - new MavenXpp3Writer().write( writer, toHash ); + new MavenXpp3Writer().write( writer, normalizeModel( prototype ) ); //normalize env specifics final String[] searchList = {baseDirPath.toString(), "\\", "windows", "linux"}; @@ -417,8 +437,8 @@ private SortedSet getInputFiles() long walkKnownPathsFinished = System.currentTimeMillis() - start; LOGGER.info( "Scanning plugins configurations to find input files. Probing is {}", processPlugins - ? "enabled, values will be checked for presence in file system" - : "disabled, only tags with attribute " + CACHE_INPUT_NAME + "=\"true\" will be added" ); + ? "enabled, values will be checked for presence in file system" + : "disabled, only tags with attribute " + CACHE_INPUT_NAME + "=\"true\" will be added" ); if ( processPlugins ) { @@ -438,7 +458,7 @@ private SortedSet getInputFiles() } LOGGER.info( "Found {} input files. Project dir processing: {}, plugins: {} millis", - sorted.size(), walkKnownPathsFinished, pluginsFinished ); + sorted.size(), walkKnownPathsFinished, pluginsFinished ); LOGGER.debug( "Src input: {}", sorted ); return sorted; @@ -520,7 +540,7 @@ private void collectFromPlugins( List files, HashSet visitedDirs if ( mergedConfig.isSkip() ) { LOGGER.debug( "Skipping plugin execution config scan (skip by config): {}, execId: {}", - plugin.getArtifactId(), exec.getId() ); + plugin.getArtifactId(), exec.getId() ); continue; } @@ -607,7 +627,7 @@ private void addInputsFromPluginConfigs( Xpp3Dom[] configurationChildren, if ( "true".equals( configChild.getAttribute( CACHE_INPUT_NAME ) ) ) { LOGGER.info( "Found tag marked with {} attribute. Tag: {}, value: {}", - CACHE_INPUT_NAME, tagName, tagValue ); + CACHE_INPUT_NAME, tagName, tagValue ); startWalk( Paths.get( tagValue ), glob, propertyConfig.isRecursive(), files, visitedDirs ); } else @@ -651,7 +671,7 @@ private Path getPathOrNull( String text ) return null; } - static void walkDirectoryFiles( Path dir, List collectedFiles, String glob ) + void walkDirectoryFiles( Path dir, List collectedFiles, String glob ) { if ( !Files.isDirectory( dir ) ) { @@ -664,6 +684,11 @@ static void walkDirectoryFiles( Path dir, List collectedFiles, String glob { for ( Path entry : stream ) { + if ( filteredOutPaths.stream() + .anyMatch( path -> path.getFileName().equals( entry.getFileName() ) ) ) + { + continue; + } File file = entry.toFile(); if ( file.isFile() && !isHidden( entry ) ) { @@ -703,14 +728,6 @@ private SortedMap getMutableDependencies() throws IOExceptio for ( Dependency dependency : project.getDependencies() ) { - // saved to index by the end of dependency build - final boolean currentlyBuilding = isBuilding( dependency ); - final boolean partOfMultiModule = strategy.isPartOfMultiModule( dependency ); - if ( !currentlyBuilding && !partOfMultiModule && !isSnapshot( dependency.getVersion() ) ) - { - // external immutable dependency, should skip - continue; - } if ( CacheUtils.isPom( dependency ) ) { @@ -721,6 +738,15 @@ private SortedMap getMutableDependencies() throws IOExceptio continue; } + // saved to index by the end of dependency build + final boolean currentlyBuilding = isBuilding( dependency ); + final boolean partOfMultiModule = strategy.isPartOfMultiModule( dependency ); + if ( !currentlyBuilding && !partOfMultiModule && !isSnapshot( dependency.getVersion() ) ) + { + // external immutable dependency, should skip + continue; + } + final Artifact dependencyArtifact = repoSystem.createDependencyArtifact( dependency ); final String artifactKey = KeyUtils.getArtifactKey( dependencyArtifact ); DigestItem resolved = null; @@ -744,16 +770,17 @@ private SortedMap getMutableDependencies() throws IOExceptio resolved = bestMatched.findArtifact( dependency ); } } - if ( resolved == null && !CacheUtils.isPom( dependency ) ) + if ( resolved != null ) { - try - { - resolved = resolveArtifact( dependencyArtifact, strategy ); - } - catch ( Exception e ) - { - throw new RuntimeException( "Cannot resolve dependency " + dependency, e ); - } + continue; + } + try + { + resolved = resolveArtifact( dependencyArtifact, strategy ); + } + catch ( Exception e ) + { + throw new RuntimeException( "Cannot resolve dependency " + dependency, e ); } } result.put( artifactKey, resolved ); @@ -763,15 +790,16 @@ private SortedMap getMutableDependencies() throws IOExceptio private boolean isBuilding( Dependency dependency ) { - return session.getProjects().stream() - .anyMatch( p -> Objects.equals( p.getGroupId(), dependency.getGroupId() ) - && Objects.equals( p.getArtifactId(), dependency.getArtifactId() ) - && Objects.equals( p.getVersion(), dependency.getVersion() ) ); + final MavenProject key = new MavenProject(); + key.setGroupId( dependency.getGroupId() ); + key.setArtifactId( dependency.getArtifactId() ); + key.setVersion( dependency.getVersion() ); + return projectIndex.containsKey( BuilderCommon.getKey( key ) ); } @Nonnull private DigestItem resolveArtifact( final Artifact dependencyArtifact, - MultimoduleDiscoveryStrategy strategy ) throws IOException + MultimoduleDiscoveryStrategy strategy ) throws IOException { ArtifactResolutionRequest request = new ArtifactResolutionRequest() .setArtifact( dependencyArtifact ) @@ -841,22 +869,31 @@ public int compare( Dependency d1, Dependency d2 ) { return d1.getArtifactId().compareTo( d2.getArtifactId() ); } + } private List normalizePlugins( List plugins ) { - for ( Plugin plugin : plugins ) - { - List excludeProperties = config.getEffectivePomExcludeProperties( plugin ); - removeBlacklistedAttributes( (Xpp3Dom) plugin.getConfiguration(), excludeProperties ); - for ( PluginExecution execution : plugin.getExecutions() ) - { - Xpp3Dom config = (Xpp3Dom) execution.getConfiguration(); - removeBlacklistedAttributes( config, excludeProperties ); - } - plugin.getDependencies().sort( dependencyComparator ); - } - return plugins; + return plugins.stream() + .map( it -> { + //do not touch original plugin, work with copy to calculate checksum + Plugin plugin = it.clone(); + List excludeProperties = config.getEffectivePomExcludeProperties( plugin ); + removeBlacklistedAttributes( (Xpp3Dom) plugin.getConfiguration(), excludeProperties ); + for ( PluginExecution execution : plugin.getExecutions() ) + { + Xpp3Dom config = (Xpp3Dom) execution.getConfiguration(); + removeBlacklistedAttributes( config, excludeProperties ); + } + //list could be immutable here hence we must not modify it but set new one + plugin.setDependencies( + it.getDependencies().stream() + .sorted( dependencyComparator ) + .collect( Collectors.toList() ) + ); + return plugin; + } ) + .collect( Collectors.toList() ); } private void removeBlacklistedAttributes( Xpp3Dom node, List excludeProperties ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java index 303874b1669e..95e30425592e 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java @@ -28,7 +28,6 @@ import org.apache.maven.caching.xml.build.ProjectsInputInfo; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecution; -import org.codehaus.plexus.util.StringUtils; import java.io.IOException; import java.net.InetAddress; @@ -37,19 +36,21 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; import static org.apache.maven.caching.CacheUtils.mojoExecutionKey; /** - * BuildInfo + * Build */ public class Build { final org.apache.maven.caching.xml.build.Build dto; CacheSource source; + volatile Map execMap; public Build( List goals, Artifact artifact, @@ -114,42 +115,18 @@ public List getMissingExecutions( List mojos ) private boolean hasCompletedExecution( String mojoExecutionKey ) { - final List completedExecutions = dto.getExecutions(); - if ( dto.getExecutions() != null ) - { - for ( CompletedExecution completedExecution : completedExecutions ) - { - if ( Objects.equals( completedExecution.getExecutionKey(), mojoExecutionKey ) ) - { - return true; - } - } - } - return false; + return getExecutionMap().containsKey( mojoExecutionKey ); } @Override public String toString() { - return "BuildInfo{" + "dto=" + dto + '}'; + return "Build{" + "dto=" + dto + '}'; } public CompletedExecution findMojoExecutionInfo( MojoExecution mojoExecution ) { - if ( dto.getExecutions() == null ) - { - return null; - } - - final List executions = dto.getExecutions(); - for ( CompletedExecution execution : executions ) - { - if ( StringUtils.equals( execution.getExecutionKey(), mojoExecutionKey( mojoExecution ) ) ) - { - return execution; - } - } - return null; + return getExecutionMap().get( mojoExecutionKey( mojoExecution ) ); } public String getCacheImplementationVersion() @@ -201,8 +178,26 @@ public DigestItem findArtifact( Dependency dependency ) private boolean isEquals( Dependency dependency, Artifact artifact ) { - return Objects.equals( dependency.getGroupId(), artifact.getArtifactId() ) && Objects.equals( - dependency.getArtifactId(), artifact.getArtifactId() ) && Objects.equals( dependency.getType(), - artifact.getType() ) && Objects.equals( dependency.getClassifier(), artifact.getClassifier() ); + return Objects.equals( dependency.getGroupId(), artifact.getGroupId() ) && + Objects.equals( dependency.getArtifactId(), artifact.getArtifactId() ) && + Objects.equals( dependency.getType(), artifact.getType() ) && + Objects.equals( dependency.getClassifier(), artifact.getClassifier() ); + } + + private Map getExecutionMap() + { + if ( execMap != null ) + { + return execMap; + } + List executionsList = dto.getExecutions(); + if ( executionsList == null || executionsList.isEmpty() ) + { + execMap = Collections.emptyMap(); + return execMap; + } + execMap = executionsList.stream() + .collect( Collectors.toMap( CompletedExecution::getExecutionKey, v -> v ) ); + return execMap; } } diff --git a/maven-caching/src/main/mdo/cache-config.mdo b/maven-caching/src/main/mdo/cache-config.mdo index 2276bd77a419..07bef41bfe2b 100644 --- a/maven-caching/src/main/mdo/cache-config.mdo +++ b/maven-caching/src/main/mdo/cache-config.mdo @@ -568,7 +568,6 @@ under the License. glob String - * @@ -744,7 +743,6 @@ under the License. glob String - * includes diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MojoCheker.java b/maven-core/src/main/java/org/apache/maven/plugin/MojoCheker.java deleted file mode 100644 index c82064b78bbf..000000000000 --- a/maven-core/src/main/java/org/apache/maven/plugin/MojoCheker.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apache.maven.plugin; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.execution.MavenSession; - -/** - * MojoCheker - */ -public interface MojoCheker -{ - /** - * @return true if this execution needs to be checked - */ - boolean needCheck( MojoExecution mojoExecution, MavenSession session ); - - /** - * @return true if check passed and mojo could be run - */ - boolean check( MojoExecution mojoExecution, Mojo mojo, MavenSession session ); -} diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java index 0cac2a7fba9e..0cae8ee2f96e 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java @@ -19,7 +19,6 @@ * under the License. */ -import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.codehaus.plexus.util.xml.Xpp3Dom; @@ -38,18 +37,12 @@ public class MojoExecution private String goal; - private String executionId; + private final String executionId; private MojoDescriptor mojoDescriptor; - private MojoCheker mojoCheker; - private Xpp3Dom configuration; - public boolean canRun( Mojo mojo, MavenSession session ) - { - return mojoCheker == null || mojoCheker.check( this, mojo, session ); - } /** * Describes the source of an execution. @@ -80,7 +73,7 @@ public enum Source * The executions to fork before this execution, indexed by the groupId:artifactId:version of the project on which * the forked execution are to be run and in reactor build order. */ - private Map> forkedExecutions = new LinkedHashMap<>(); + private final Map> forkedExecutions = new LinkedHashMap<>(); public MojoExecution( Plugin plugin, String goal, String executionId ) { @@ -160,12 +153,7 @@ public void setConfiguration( Xpp3Dom configuration ) public String identify() { - StringBuilder sb = new StringBuilder( 256 ); - - sb.append( executionId ); - sb.append( configuration.toString() ); - - return sb.toString(); + return executionId + configuration.toString(); } public String getLifecyclePhase() @@ -244,9 +232,4 @@ public void setForkedExecutions( String projectKey, List forkedEx { this.forkedExecutions.put( projectKey, forkedExecutions ); } - - public void setMojoExecutionManager( MojoCheker mojoCheker ) - { - this.mojoCheker = mojoCheker; - } } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 9601367aa469..70b85757f869 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -92,7 +92,7 @@ @Named @Singleton public class DefaultProjectBuilder - implements ProjectBuilder + implements ProjectBuilder { private final Logger logger = LoggerFactory.getLogger( getClass() ); private final ModelBuilder modelBuilder; @@ -121,13 +121,13 @@ public DefaultProjectBuilder( this.repositoryManager = repositoryManager; this.dependencyResolver = dependencyResolver; } -// ---------------------------------------------------------------------- + // ---------------------------------------------------------------------- // MavenProjectBuilder Implementation // ---------------------------------------------------------------------- @Override public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest request ) - throws ProjectBuildingException + throws ProjectBuildingException { return build( pomFile, new FileModelSource( pomFile ), new InternalConfig( request, null, null ) ); @@ -135,14 +135,14 @@ public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest request @Override public ProjectBuildingResult build( ModelSource modelSource, ProjectBuildingRequest request ) - throws ProjectBuildingException + throws ProjectBuildingException { return build( null, modelSource, - new InternalConfig( request, null, null ) ); + new InternalConfig( request, null, null ) ); } private ProjectBuildingResult build( File pomFile, ModelSource modelSource, InternalConfig config ) - throws ProjectBuildingException + throws ProjectBuildingException { ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -163,7 +163,7 @@ private ProjectBuildingResult build( File pomFile, ModelSource modelSource, Inte project.setFile( pomFile ); DefaultModelBuildingListener listener = - new DefaultModelBuildingListener( project, projectBuildingHelper, projectBuildingRequest ); + new DefaultModelBuildingListener( project, projectBuildingHelper, projectBuildingRequest ); request.setModelBuildingListener( listener ); request.setPomFile( pomFile ); @@ -189,7 +189,7 @@ private ProjectBuildingResult build( File pomFile, ModelSource modelSource, Inte modelProblems = result.getProblems(); initProject( project, Collections.emptyMap(), true, - result, new HashMap<>(), projectBuildingRequest ); + result, new HashMap<>(), projectBuildingRequest ); } else if ( projectBuildingRequest.isResolveDependencies() ) { @@ -238,7 +238,7 @@ private DependencyResolutionResult resolveDependencies( MavenProject project, Re if ( resolutionResult.getDependencyGraph() != null ) { RepositoryUtils.toArtifacts( artifacts, resolutionResult.getDependencyGraph().getChildren(), - Collections.singletonList( project.getArtifact().getId() ), null ); + Collections.singletonList( project.getArtifact().getId() ), null ); // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not LocalRepositoryManager lrm = session.getLocalRepositoryManager(); @@ -271,8 +271,8 @@ private ModelBuildingRequest getModelBuildingRequest( InternalConfig config ) RequestTrace trace = RequestTrace.newChild( null, configuration ).newChild( request ); ModelResolver resolver = - new ProjectModelResolver( config.session, trace, repoSystem, repositoryManager, config.repositories, - configuration.getRepositoryMerging(), config.modelPool ); + new ProjectModelResolver( config.session, trace, repoSystem, repositoryManager, config.repositories, + configuration.getRepositoryMerging(), config.modelPool ); request.setValidationLevel( configuration.getValidationLevel() ); request.setProcessPlugins( configuration.isProcessPlugins() ); @@ -295,20 +295,20 @@ private ModelBuildingRequest getModelBuildingRequest( InternalConfig config ) @Override public ProjectBuildingResult build( Artifact artifact, ProjectBuildingRequest request ) - throws ProjectBuildingException + throws ProjectBuildingException { return build( artifact, false, request ); } @Override public ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, ProjectBuildingRequest request ) - throws ProjectBuildingException + throws ProjectBuildingException { org.eclipse.aether.artifact.Artifact pomArtifact = RepositoryUtils.toArtifact( artifact ); pomArtifact = ArtifactDescriptorUtils.toPomArtifact( pomArtifact ); InternalConfig config = - new InternalConfig( request, null, null ); + new InternalConfig( request, null, null ); boolean localProject; @@ -329,7 +329,7 @@ public ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, P return build( null, createStubModelSource( artifact ), config ); } throw new ProjectBuildingException( artifact.getId(), - "Error resolving project artifact: " + e.getMessage(), e ); + "Error resolving project artifact: " + e.getMessage(), e ); } File pomFile = pomArtifact.getFile(); @@ -348,8 +348,8 @@ public ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, P else { return build( null, new ArtifactModelSource( pomFile, artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion() ), - config ); + artifact.getVersion() ), + config ); } } @@ -371,7 +371,7 @@ private ModelSource createStubModelSource( Artifact artifact ) @Override public List build( List pomFiles, boolean recursive, ProjectBuildingRequest request ) - throws ProjectBuildingException + throws ProjectBuildingException { List results = new ArrayList<>(); @@ -381,14 +381,14 @@ public List build( List pomFiles, boolean recursive final ReactorModelPool modelPool = poolBuilder.build(); InternalConfig config = - new InternalConfig( request, modelPool, modelBuilder.newTransformerContextBuilder() ); + new InternalConfig( request, modelPool, modelBuilder.newTransformerContextBuilder() ); Map projectIndex = new HashMap<>( 256 ); // phase 1: get file Models from the reactor. boolean noErrors = - build( results, interimResults, projectIndex, pomFiles, new LinkedHashSet<>(), true, recursive, - config, poolBuilder ); + build( results, interimResults, projectIndex, pomFiles, new LinkedHashSet<>(), true, recursive, + config, poolBuilder ); ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -396,8 +396,8 @@ public List build( List pomFiles, boolean recursive { // Phase 2: get effective models from the reactor noErrors = - build( results, new ArrayList<>(), projectIndex, interimResults, request, - new HashMap<>(), config.session ) && noErrors; + build( results, new ArrayList<>(), projectIndex, interimResults, request, + new HashMap<>(), config.session ) && noErrors; } finally { @@ -407,7 +407,7 @@ public List build( List pomFiles, boolean recursive if ( Features.buildConsumer( request.getUserProperties() ).isActive() ) { request.getRepositorySession().getData().set( TransformerContext.KEY, - config.transformerContextBuilder.build() ); + config.transformerContextBuilder.build() ); } if ( !noErrors ) @@ -431,7 +431,7 @@ private boolean build( List results, List aggregatorFiles.add( pomFile ); if ( !build( results, interimResults, projectIndex, pomFile, aggregatorFiles, root, recursive, config, - poolBuilder ) ) + poolBuilder ) ) { noErrors = false; } @@ -454,12 +454,12 @@ private boolean build( List results, List project.setFile( pomFile ); ModelBuildingRequest request = getModelBuildingRequest( config ) - .setPomFile( pomFile ) - .setTwoPhaseBuilding( true ) - .setLocationTracking( true ); + .setPomFile( pomFile ) + .setTwoPhaseBuilding( true ) + .setLocationTracking( true ); DefaultModelBuildingListener listener = - new DefaultModelBuildingListener( project, projectBuildingHelper, config.request ); + new DefaultModelBuildingListener( project, projectBuildingHelper, config.request ); request.setModelBuildingListener( listener ); ModelBuildingResult result; @@ -472,9 +472,9 @@ private boolean build( List results, List result = e.getResult(); if ( result == null || result.getFileModel() == null ) { - results.add( new DefaultProjectBuildingResult( e.getModelId(), pomFile, e.getProblems() ) ); + results.add( new DefaultProjectBuildingResult( e.getModelId(), pomFile, e.getProblems() ) ); - return false; + return false; } // validation error, continue project building and delay failing to help IDEs // result.getProblems().addAll(e.getProblems()) ? @@ -483,7 +483,7 @@ private boolean build( List results, List Model model = result.getFileModel().clone(); - poolBuilder.put( model.getPomFile().toPath(), model ); + poolBuilder.put( model.getPomFile().toPath(), model ); InterimResult interimResult = new InterimResult( pomFile, request, result, listener, isRoot ); interimResults.add( interimResult ); @@ -511,9 +511,10 @@ private boolean build( List results, List if ( !moduleFile.isFile() ) { ModelProblem problem = - new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile - + " does not exist", ModelProblem.Severity.ERROR, ModelProblem.Version.BASE, model, -1, - -1, null ); + new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile + + " does not exist", ModelProblem.Severity.ERROR, ModelProblem.Version.BASE, model, + -1, + -1, null ); result.getProblems().add( problem ); noErrors = false; @@ -548,9 +549,9 @@ private boolean build( List results, List buffer.append( moduleFile ); ModelProblem problem = - new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile - + " forms aggregation cycle " + buffer, ModelProblem.Severity.ERROR, - ModelProblem.Version.BASE, model, -1, -1, null ); + new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile + + " forms aggregation cycle " + buffer, ModelProblem.Severity.ERROR, + ModelProblem.Version.BASE, model, -1, -1, null ); result.getProblems().add( problem ); noErrors = false; @@ -564,7 +565,7 @@ private boolean build( List results, List interimResult.modules = new ArrayList<>(); if ( !build( results, interimResult.modules, projectIndex, moduleFiles, aggregatorFiles, false, - recursive, config, poolBuilder ) ) + recursive, config, poolBuilder ) ) { noErrors = false; } @@ -629,8 +630,8 @@ private boolean build( List results, List p List modules = new ArrayList<>(); noErrors = - build( results, modules, projectIndex, interimResult.modules, request, profilesXmls, session ) - && noErrors; + build( results, modules, projectIndex, interimResult.modules, request, profilesXmls, session ) + && noErrors; projects.addAll( modules ); projects.add( project ); @@ -676,13 +677,13 @@ private void initProject( MavenProject project, Map projects project.setModel( model ); project.setOriginalModel( result.getFileModel() ); - project.setOriginalEffectiveModel( model.clone() ); initParent( project, projects, buildParentIfNotExisting, result, projectBuildingRequest ); Artifact projectArtifact = - repositorySystem.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), null, - project.getPackaging() ); + repositorySystem.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), + null, + project.getPackaging() ); project.setArtifact( projectArtifact ); if ( project.getFile() != null && buildParentIfNotExisting ) // only set those on 2nd phase, ignore on 1st pass @@ -759,7 +760,7 @@ private void initProject( MavenProject project, Map projects } Artifact artifact = - repositorySystem.createArtifact( ext.getGroupId(), ext.getArtifactId(), version, null, "jar" ); + repositorySystem.createArtifact( ext.getGroupId(), ext.getArtifactId(), version, null, "jar" ); if ( artifact != null ) { @@ -775,7 +776,7 @@ private void initProject( MavenProject project, Map projects { final DependencyManagement dependencyManagement = project.getDependencyManagement(); if ( ( dependencyManagement != null ) && ( ( dependencyManagement.getDependencies() ) != null ) - && ( dependencyManagement.getDependencies().size() > 0 ) ) + && ( dependencyManagement.getDependencies().size() > 0 ) ) { map = new AbstractMap() { @@ -846,7 +847,7 @@ HashMap compute() // release artifact repository if ( project.getDistributionManagement() != null - && project.getDistributionManagement().getRepository() != null ) + && project.getDistributionManagement().getRepository() != null ) { try { @@ -855,22 +856,22 @@ HashMap compute() { ArtifactRepository repo = MavenRepositorySystem.buildArtifactRepository( r ); repositorySystem.injectProxy( projectBuildingRequest.getRepositorySession(), - Arrays.asList( repo ) ); + Arrays.asList( repo ) ); repositorySystem.injectAuthentication( projectBuildingRequest.getRepositorySession(), - Arrays.asList( repo ) ); + Arrays.asList( repo ) ); project.setReleaseArtifactRepository( repo ); } } catch ( InvalidRepositoryException e ) { throw new IllegalStateException( "Failed to create release distribution repository for " - + project.getId(), e ); + + project.getId(), e ); } } // snapshot artifact repository if ( project.getDistributionManagement() != null - && project.getDistributionManagement().getSnapshotRepository() != null ) + && project.getDistributionManagement().getSnapshotRepository() != null ) { try { @@ -879,16 +880,16 @@ HashMap compute() { ArtifactRepository repo = MavenRepositorySystem.buildArtifactRepository( r ); repositorySystem.injectProxy( projectBuildingRequest.getRepositorySession(), - Arrays.asList( repo ) ); + Arrays.asList( repo ) ); repositorySystem.injectAuthentication( projectBuildingRequest.getRepositorySession(), - Arrays.asList( repo ) ); + Arrays.asList( repo ) ); project.setSnapshotArtifactRepository( repo ); } } catch ( InvalidRepositoryException e ) { throw new IllegalStateException( "Failed to create snapshot distribution repository for " - + project.getId(), e ); + + project.getId(), e ); } } } @@ -897,8 +898,8 @@ private void initParent( MavenProject project, Map projects, ModelBuildingResult result, ProjectBuildingRequest projectBuildingRequest ) { Model parentModel = result.getModelIds().size() > 1 && !result.getModelIds().get( 1 ).isEmpty() - ? result.getRawModel( result.getModelIds().get( 1 ) ) - : null; + ? result.getRawModel( result.getModelIds().get( 1 ) ) + : null; if ( parentModel != null ) { @@ -906,8 +907,8 @@ private void initParent( MavenProject project, Map projects, final String parentVersion = inheritedVersion( result, 1 ); project.setParentArtifact( repositorySystem.createProjectArtifact( parentGroupId, - parentModel.getArtifactId(), - parentVersion ) ); + parentModel.getArtifactId(), + parentVersion ) ); // org.apache.maven.its.mng4834:parent:0.1 String parentModelId = result.getModelIds().get( 1 ); @@ -983,8 +984,8 @@ private static String inheritedGroupId( final ModelBuildingResult result, final { final Model model = result.getRawModel( modelId ); groupId = model.getGroupId() != null - ? model.getGroupId() - : inheritedGroupId( result, modelIndex + 1 ); + ? model.getGroupId() + : inheritedGroupId( result, modelIndex + 1 ); } @@ -1000,8 +1001,8 @@ private static String inheritedVersion( final ModelBuildingResult result, final { final Model model = result.getRawModel( modelId ); version = model.getVersion() != null - ? model.getVersion() - : inheritedVersion( result, modelIndex + 1 ); + ? model.getVersion() + : inheritedVersion( result, modelIndex + 1 ); } @@ -1032,8 +1033,8 @@ class InternalConfig this.transformerContextBuilder = transformerContextBuilder; session = - LegacyLocalRepositoryManager.overlay( request.getLocalRepository(), request.getRepositorySession(), - repoSystem ); + LegacyLocalRepositoryManager.overlay( request.getLocalRepository(), request.getRepositorySession(), + repoSystem ); repositories = RepositoryUtils.toRepos( request.getRemoteRepositories() ); } diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index 2b90be6696d0..f53fe5e2b8e6 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -145,7 +145,7 @@ public class MavenProject private List activeProfiles = new ArrayList<>(); - private Map> injectedProfileIds = new LinkedHashMap<>(); + private final Map> injectedProfileIds = new LinkedHashMap<>(); private Set dependencyArtifacts; @@ -156,8 +156,6 @@ public class MavenProject private Model originalModel; - private Model originalEffectiveModel; - private Map pluginArtifactMap; private Set reportArtifacts; @@ -170,7 +168,7 @@ public class MavenProject private Map managedVersionMap; - private Map projectReferences = new HashMap<>(); + private final Map projectReferences = new HashMap<>(); private boolean executionRoot; @@ -1050,16 +1048,6 @@ public Model getOriginalModel() return originalModel; } - public Model getOriginalEffectiveModel() - { - return originalEffectiveModel; - } - - public void setOriginalEffectiveModel( Model originalEffectiveModel ) - { - this.originalEffectiveModel = originalEffectiveModel; - } - public void setManagedVersionMap( Map map ) { managedVersionMap = map; @@ -1439,7 +1427,7 @@ public DependencyFilter getExtensionDependencyFilter() */ public void setResolvedArtifacts( Set artifacts ) { - this.resolvedArtifacts = ( artifacts != null ) ? artifacts : Collections.emptySet(); + this.resolvedArtifacts = ( artifacts != null ) ? artifacts : Collections.emptySet(); this.artifacts = null; this.artifactMap = null; } From 008fd604294c350538f38bf4427dddd497abd167 Mon Sep 17 00:00:00 2001 From: Andrey Petrenko Date: Wed, 17 Nov 2021 21:56:14 +0300 Subject: [PATCH 149/188] MNG-7129: caching extension --- .../org/apache/maven/caching/CacheControllerImpl.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 04cabd639054..2b16477b23bb 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -384,9 +384,7 @@ private ProjectsInputInfo calculateInput( MavenProject project, MavenSession ses { if ( this.projectIndex == null ) { - Map projectMap = new HashMap<>( - session.getProjects().size() * 2 - ); + Map projectMap = new HashMap<>( session.getProjects().size() * 2 ); for ( MavenProject p : session.getProjects() ) { projectMap.put( BuilderCommon.getKey( p ), p ); @@ -852,9 +850,10 @@ public void attachGeneratedSources( MavenProject project ) throws IOException for ( String sourceRoot : sourceRoots ) { final Path sourceRootPath = Paths.get( sourceRoot ); - if ( Files.isDirectory( sourceRootPath ) && sourceRootPath.startsWith( - targetDir ) && !( sourceRootPath.startsWith( generatedSourcesDir ) || sourceRootPath.startsWith( - generatedTestSourcesDir ) ) ) + if ( Files.isDirectory( sourceRootPath ) && + sourceRootPath.startsWith( targetDir ) && + !( sourceRootPath.startsWith( generatedSourcesDir ) || + sourceRootPath.startsWith( generatedTestSourcesDir ) ) ) { // dir within target attachDirIfNotEmpty( sourceRootPath, targetDir, project ); } From 5065d8a34d9947b14d8d15fabfface3c5b5cd1a5 Mon Sep 17 00:00:00 2001 From: Andrey Petrenko Date: Wed, 17 Nov 2021 22:05:34 +0300 Subject: [PATCH 150/188] MNG-7129: caching extension --- .../maven/caching/CacheControllerImpl.java | 8 +-- .../caching/checksum/MavenProjectInput.java | 16 +++-- .../org/apache/maven/caching/xml/Build.java | 8 +-- .../checksum/MavenProjectInputTest.java | 64 +++++++++++-------- .../plugin/DefaultBuildPluginManager.java | 5 +- 5 files changed, 59 insertions(+), 42 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 2b16477b23bb..b6fd240c1e0c 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -850,10 +850,10 @@ public void attachGeneratedSources( MavenProject project ) throws IOException for ( String sourceRoot : sourceRoots ) { final Path sourceRootPath = Paths.get( sourceRoot ); - if ( Files.isDirectory( sourceRootPath ) && - sourceRootPath.startsWith( targetDir ) && - !( sourceRootPath.startsWith( generatedSourcesDir ) || - sourceRootPath.startsWith( generatedTestSourcesDir ) ) ) + if ( Files.isDirectory( sourceRootPath ) + && sourceRootPath.startsWith( targetDir ) + && !( sourceRootPath.startsWith( generatedSourcesDir ) + || sourceRootPath.startsWith( generatedTestSourcesDir ) ) ) { // dir within target attachDirIfNotEmpty( sourceRootPath, targetDir, project ); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index eb6e729c502d..5b3714328105 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -45,6 +45,7 @@ import java.util.TreeMap; import java.util.TreeSet; import java.util.concurrent.ConcurrentMap; +import java.util.function.Predicate; import java.util.stream.Collectors; import javax.annotation.Nonnull; @@ -583,7 +584,12 @@ else if ( visitedDirs.contains( currentDirKey ) ) return FileVisitResult.SKIP_SUBTREE; } - walkDirectoryFiles( path, collectedFiles, key.getGlob() ); + walkDirectoryFiles( + path, + collectedFiles, + key.getGlob(), + entry -> filteredOutPaths.stream() + .anyMatch( it -> it.getFileName().equals( entry.getFileName() ) ) ); if ( !key.isRecursive() ) { @@ -671,7 +677,7 @@ private Path getPathOrNull( String text ) return null; } - void walkDirectoryFiles( Path dir, List collectedFiles, String glob ) + static void walkDirectoryFiles( Path dir, List collectedFiles, String glob, Predicate mustBeSkipped ) { if ( !Files.isDirectory( dir ) ) { @@ -684,8 +690,7 @@ void walkDirectoryFiles( Path dir, List collectedFiles, String glob ) { for ( Path entry : stream ) { - if ( filteredOutPaths.stream() - .anyMatch( path -> path.getFileName().equals( entry.getFileName() ) ) ) + if ( mustBeSkipped.test( entry ) ) { continue; } @@ -875,7 +880,8 @@ public int compare( Dependency d1, Dependency d2 ) private List normalizePlugins( List plugins ) { return plugins.stream() - .map( it -> { + .map( it -> + { //do not touch original plugin, work with copy to calculate checksum Plugin plugin = it.clone(); List excludeProperties = config.getEffectivePomExcludeProperties( plugin ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java index 95e30425592e..6339c547c390 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java @@ -178,10 +178,10 @@ public DigestItem findArtifact( Dependency dependency ) private boolean isEquals( Dependency dependency, Artifact artifact ) { - return Objects.equals( dependency.getGroupId(), artifact.getGroupId() ) && - Objects.equals( dependency.getArtifactId(), artifact.getArtifactId() ) && - Objects.equals( dependency.getType(), artifact.getType() ) && - Objects.equals( dependency.getClassifier(), artifact.getClassifier() ); + return Objects.equals( dependency.getGroupId(), artifact.getGroupId() ) + && Objects.equals( dependency.getArtifactId(), artifact.getArtifactId() ) + && Objects.equals( dependency.getType(), artifact.getType() ) + && Objects.equals( dependency.getClassifier(), artifact.getClassifier() ); } private Map getExecutionMap() diff --git a/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java b/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java index 91c4f9005455..3ec7f226601a 100644 --- a/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java @@ -29,48 +29,62 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class MavenProjectInputTest { +public class MavenProjectInputTest +{ private static final String GLOB = "{*-pom.xml}"; @Test - public void testAddInputsRelativePath() { -// MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), Paths.get("src\\test\\resources\\org"), GLOB); -// ArrayList files = new ArrayList<>(); -// inputs.listDirOrFile("../../resources", inputs.dirGlob, files, new HashSet()); -// assertEquals(4, files.size()); + public void testAddInputsRelativePath() + { + // MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), Paths.get("src\\test\\resources\\org"), GLOB); + // ArrayList files = new ArrayList<>(); + // inputs.listDirOrFile("../../resources", inputs.dirGlob, files, new HashSet()); + // assertEquals(4, files.size()); } @Test - public void testAddInputsAbsolutePath() { -// Path baseDirPath = Paths.get("src\\test\\resources\\org"); -// MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), baseDirPath, GLOB); -// ArrayList files = new ArrayList<>(); -// Path candidatePath = baseDirPath.resolve("../../resources").normalize().toAbsolutePath(); -// inputs.listDirOrFile(candidatePath.toString(), inputs.dirGlob, files, new HashSet()); -// assertEquals(4, files.size()); // pom is filtered out by hardcoded if + public void testAddInputsAbsolutePath() + { + // Path baseDirPath = Paths.get("src\\test\\resources\\org"); + // MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), baseDirPath, GLOB); + // ArrayList files = new ArrayList<>(); + // Path candidatePath = baseDirPath.resolve("../../resources").normalize().toAbsolutePath(); + // inputs.listDirOrFile(candidatePath.toString(), inputs.dirGlob, files, new HashSet()); + // assertEquals(4, files.size()); // pom is filtered out by hardcoded if } @Test - public void testGlobInput() { -// Path baseDirPath = Paths.get("src\\test\\resources"); -// MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), baseDirPath, GLOB); -// ArrayList files = new ArrayList<>(); -// inputs.tryAddInputs("*.java", files, new HashSet()); -// assertEquals(0, files.size()); // pom is filtered out by hardcoded if + public void testGlobInput() + { + // Path baseDirPath = Paths.get("src\\test\\resources"); + // MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), baseDirPath, GLOB); + // ArrayList files = new ArrayList<>(); + // inputs.tryAddInputs("*.java", files, new HashSet()); + // assertEquals(0, files.size()); // pom is filtered out by hardcoded if } @Test - public void testGetDirectoryFiles() { + public void testGetDirectoryFiles() + { List directoryFiles = new ArrayList<>(); - MavenProjectInput.walkDirectoryFiles(Paths.get("src/test/resources/test-folder"), directoryFiles, MavenProjectInput.DEFAULT_GLOB); - assertEquals(0, directoryFiles.size()); // pom is filtered out by hardcoded if + MavenProjectInput.walkDirectoryFiles( + Paths.get( "src/test/resources/test-folder" ), + directoryFiles, + MavenProjectInput.DEFAULT_GLOB, + it -> true ); + assertEquals( 0, directoryFiles.size() ); // pom is filtered out by hardcoded if } @Test - public void testGetDirectoryFiles2() { + public void testGetDirectoryFiles2() + { List directoryFiles = new ArrayList<>(); - MavenProjectInput.walkDirectoryFiles(Paths.get("src/test/resources/test-folder"), directoryFiles, GLOB); - assertEquals(1, directoryFiles.size()); // pom is filtered out by hardcoded if + MavenProjectInput.walkDirectoryFiles( + Paths.get( "src/test/resources/test-folder" ), + directoryFiles, + GLOB, + it -> true ); + assertEquals( 1, directoryFiles.size() ); // pom is filtered out by hardcoded if } } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java index 702598079979..1958fc7f64ce 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java @@ -134,10 +134,7 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) mojoExecutionListener.beforeMojoExecution( mojoExecutionEvent ); - if ( mojoExecution.canRun( mojo, session ) ) - { - mojo.execute(); - } + mojo.execute(); mojoExecutionListener.afterMojoExecutionSuccess( mojoExecutionEvent ); } From 82c445e989fee7e5854a2b65257d54df15ac1872 Mon Sep 17 00:00:00 2001 From: Alexander Ashitkin Date: Wed, 17 Nov 2021 15:42:45 -0500 Subject: [PATCH 151/188] [MNG-7129] Cache extension test fix --- .../apache/maven/caching/checksum/MavenProjectInputTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java b/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java index 3ec7f226601a..a7da1aecf68f 100644 --- a/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java +++ b/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java @@ -72,7 +72,7 @@ public void testGetDirectoryFiles() Paths.get( "src/test/resources/test-folder" ), directoryFiles, MavenProjectInput.DEFAULT_GLOB, - it -> true ); + it -> false ); assertEquals( 0, directoryFiles.size() ); // pom is filtered out by hardcoded if } @@ -84,7 +84,7 @@ public void testGetDirectoryFiles2() Paths.get( "src/test/resources/test-folder" ), directoryFiles, GLOB, - it -> true ); + it -> false ); assertEquals( 1, directoryFiles.size() ); // pom is filtered out by hardcoded if } } From c581c0d5a1c567986f33510b174f64dcd4fdd6e6 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 18 Nov 2021 08:21:47 +0100 Subject: [PATCH 152/188] MNG-7129: no need for a lazy initialization, prefer a final field --- .../maven/caching/CacheControllerImpl.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index b6fd240c1e0c..ecfd389c2e43 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -31,7 +31,6 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -41,7 +40,9 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.function.Function; import java.util.regex.Pattern; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.inject.Inject; @@ -125,8 +126,8 @@ public class CacheControllerImpl implements CacheController private final ConcurrentMap artifactDigestByKey = new ConcurrentHashMap<>(); private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); private final LifecyclePhasesHelper lifecyclePhasesHelper; + private final Map projectIndex; private volatile Scm scm; - private volatile Map projectIndex; @Inject public CacheControllerImpl( @@ -137,7 +138,8 @@ public CacheControllerImpl( LocalCacheRepository localCache, RemoteCacheRepository remoteCache, CacheConfig cacheConfig, - LifecyclePhasesHelper lifecyclePhasesHelper ) + LifecyclePhasesHelper lifecyclePhasesHelper, + MavenSession session ) { this.projectHelper = projectHelper; this.localCache = localCache; @@ -147,6 +149,8 @@ public CacheControllerImpl( this.artifactHandlerManager = artifactHandlerManager; this.xmlService = xmlService; this.lifecyclePhasesHelper = lifecyclePhasesHelper; + this.projectIndex = session.getProjects().stream() + .collect( Collectors.toMap( BuilderCommon::getKey, Function.identity() ) ); } @Override @@ -382,15 +386,6 @@ private ProjectsInputInfo calculateInput( MavenProject project, MavenSession ses { try { - if ( this.projectIndex == null ) - { - Map projectMap = new HashMap<>( session.getProjects().size() * 2 ); - for ( MavenProject p : session.getProjects() ) - { - projectMap.put( BuilderCommon.getKey( p ), p ); - } - this.projectIndex = projectMap; - } final MavenProjectInput inputs = new MavenProjectInput( project, projectIndex, session, cacheConfig, artifactDigestByKey, repoSystem, localCache, remoteCache ); return inputs.calculateChecksum( cacheConfig.getHashFactory() ); From a0b14a82c5f944eace8d61b3847ed6d35fdfd81c Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 18 Nov 2021 08:36:19 +0100 Subject: [PATCH 153/188] MNG-7129: retrieve the hashFactory directly from the cache config --- .../java/org/apache/maven/caching/CacheControllerImpl.java | 2 +- .../apache/maven/caching/checksum/MavenProjectInput.java | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index ecfd389c2e43..b19554aff703 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -388,7 +388,7 @@ private ProjectsInputInfo calculateInput( MavenProject project, MavenSession ses { final MavenProjectInput inputs = new MavenProjectInput( project, projectIndex, session, cacheConfig, artifactDigestByKey, repoSystem, localCache, remoteCache ); - return inputs.calculateChecksum( cacheConfig.getHashFactory() ); + return inputs.calculateChecksum(); } catch ( Exception e ) { diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 5b3714328105..96ec30f075c0 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -61,7 +61,6 @@ import org.apache.maven.caching.ScanConfigProperties; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashChecksum; -import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; @@ -194,7 +193,7 @@ public MavenProjectInput( MavenProject project, this.dependencyComparator = new DependencyComparator(); } - public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOException + public ProjectsInputInfo calculateChecksum() throws IOException { final long t0 = System.currentTimeMillis(); @@ -207,7 +206,7 @@ public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOE // hash items: effective pom + input files + dependencies final int count = 1 + inputFiles.size() + dependenciesChecksum.size(); final List items = new ArrayList<>( count ); - final HashChecksum checksum = hashFactory.createChecksum( count ); + final HashChecksum checksum = config.getHashFactory().createChecksum( count ); Optional baselineHolder = Optional.empty(); if ( config.isBaselineDiffEnabled() ) @@ -267,7 +266,7 @@ public ProjectsInputInfo calculateChecksum( HashFactory hashFactory ) throws IOE LOGGER.debug( "Hash calculated, item: {}, hash: {}", item.getType(), item.getHash() ); } LOGGER.info( "Project inputs calculated in {} ms. {} checksum [{}] calculated in {} ms.", - t1 - t0, hashFactory.getAlgorithm(), projectsInputInfoType.getChecksum(), t2 - t1 ); + t1 - t0, config.getHashFactory().getAlgorithm(), projectsInputInfoType.getChecksum(), t2 - t1 ); return projectsInputInfoType; } From 240ca7bbca947c82b2354fe4ace312f77ede3cbc Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 18 Nov 2021 08:55:59 +0100 Subject: [PATCH 154/188] Revert c581c0d5a1c567986f33510b174f64dcd4fdd6e6 as the projects are not yet discovered --- .../org/apache/maven/caching/CacheControllerImpl.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index b19554aff703..a3ea83794711 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -126,7 +126,7 @@ public class CacheControllerImpl implements CacheController private final ConcurrentMap artifactDigestByKey = new ConcurrentHashMap<>(); private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); private final LifecyclePhasesHelper lifecyclePhasesHelper; - private final Map projectIndex; + private volatile Map projectIndex; private volatile Scm scm; @Inject @@ -149,8 +149,6 @@ public CacheControllerImpl( this.artifactHandlerManager = artifactHandlerManager; this.xmlService = xmlService; this.lifecyclePhasesHelper = lifecyclePhasesHelper; - this.projectIndex = session.getProjects().stream() - .collect( Collectors.toMap( BuilderCommon::getKey, Function.identity() ) ); } @Override @@ -386,6 +384,11 @@ private ProjectsInputInfo calculateInput( MavenProject project, MavenSession ses { try { + if ( projectIndex == null ) + { + projectIndex = session.getProjects().stream() + .collect( Collectors.toMap( BuilderCommon::getKey, Function.identity() ) ); + } final MavenProjectInput inputs = new MavenProjectInput( project, projectIndex, session, cacheConfig, artifactDigestByKey, repoSystem, localCache, remoteCache ); return inputs.calculateChecksum(); From 0d693e502981713bbe5812040ea4fd7e23f58a42 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 18 Nov 2021 09:26:42 +0100 Subject: [PATCH 155/188] Minimize changes in maven-core --- .../lifecycle/internal/DependencyContext.java | 4 +- .../lifecycle/internal/MojoExecutor.java | 5 +- .../plugin/DefaultBuildPluginManager.java | 32 ++--- .../apache/maven/plugin/MojoExecution.java | 25 ++-- .../maven/project/DefaultProjectBuilder.java | 128 +++++++++--------- .../apache/maven/project/MavenProject.java | 6 +- .../LifecycleExecutorSubModulesTest.java | 2 +- .../internal/stub/MojoExecutorStub.java | 1 + 8 files changed, 103 insertions(+), 100 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DependencyContext.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DependencyContext.java index 675ffc5558d2..5572f52f745a 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DependencyContext.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DependencyContext.java @@ -93,8 +93,8 @@ public Collection getScopesToResolveForAggregatedProjects() public boolean isResolutionRequiredForCurrentProject() { - return lastDependencyArtifacts != project.getDependencyArtifacts() - || ( lastDependencyArtifacts != null && lastDependencyArtifactCount != lastDependencyArtifacts.size() ); + return lastDependencyArtifacts != project.getDependencyArtifacts() || ( lastDependencyArtifacts != null + && lastDependencyArtifactCount != lastDependencyArtifacts.size() ); } public boolean isResolutionRequiredForAggregatedProjects( Collection scopesToCollect, diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java index 7e41d103dede..c7709b493d59 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java @@ -145,9 +145,8 @@ else if ( Artifact.SCOPE_TEST.equals( classpath ) ) return Collections.unmodifiableCollection( scopes ); } - public void execute( final MavenSession session, - List mojoExecutions, - final ProjectIndex projectIndex ) throws LifecycleExecutionException + public void execute( MavenSession session, List mojoExecutions, ProjectIndex projectIndex ) + throws LifecycleExecutionException { DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java index 1958fc7f64ce..272371ade084 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java @@ -74,8 +74,8 @@ public DefaultBuildPluginManager( * @param repositories * @param session * @return PluginDescriptor The component descriptor for the Maven plugin. - * @throws PluginNotFoundException The plugin could not be found in any repositories. - * @throws PluginResolutionException The plugin could be found but could not be resolved. + * @throws PluginNotFoundException The plugin could not be found in any repositories. + * @throws PluginResolutionException The plugin could be found but could not be resolved. * @throws InvalidPluginDescriptorException */ public PluginDescriptor loadPlugin( Plugin plugin, List repositories, @@ -150,20 +150,20 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) } catch ( PluginContainerException e ) { - mojoExecutionListener.afterExecutionFailure( - new MojoExecutionEvent( session, project, mojoExecution, mojo, e ) ); + mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo, + e ) ); throw new PluginExecutionException( mojoExecution, project, e ); } catch ( NoClassDefFoundError e ) { - mojoExecutionListener.afterExecutionFailure( - new MojoExecutionEvent( session, project, mojoExecution, mojo, e ) ); + mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo, + e ) ); ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); PrintStream ps = new PrintStream( os ); - ps.println( - "A required class was missing while executing " + mojoDescriptor.getId() + ": " + e.getMessage() ); + ps.println( "A required class was missing while executing " + mojoDescriptor.getId() + ": " + + e.getMessage() ); pluginRealm.display( ps ); Exception wrapper = new PluginContainerException( mojoDescriptor, pluginRealm, os.toString(), e ); @@ -172,8 +172,8 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) } catch ( LinkageError e ) { - mojoExecutionListener.afterExecutionFailure( - new MojoExecutionEvent( session, project, mojoExecution, mojo, e ) ); + mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo, + e ) ); ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); PrintStream ps = new PrintStream( os ); @@ -187,8 +187,8 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) } catch ( ClassCastException e ) { - mojoExecutionListener.afterExecutionFailure( - new MojoExecutionEvent( session, project, mojoExecution, mojo, e ) ); + mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo, + e ) ); ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); PrintStream ps = new PrintStream( os ); @@ -200,8 +200,8 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) } catch ( RuntimeException e ) { - mojoExecutionListener.afterExecutionFailure( - new MojoExecutionEvent( session, project, mojoExecution, mojo, e ) ); + mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo, + e ) ); throw e; } @@ -218,8 +218,8 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution ) } /** - * TODO pluginDescriptor classRealm and artifacts are set as a side effect of this call, which is not nice. - * + * TODO pluginDescriptor classRealm and artifacts are set as a side effect of this + * call, which is not nice. * @throws PluginResolutionException */ public ClassRealm getPluginRealm( MavenSession session, PluginDescriptor pluginDescriptor ) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java index 0cae8ee2f96e..fa72c1866e4c 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java @@ -19,14 +19,14 @@ * under the License. */ -import org.apache.maven.model.Plugin; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.codehaus.plexus.util.xml.Xpp3Dom; - import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.codehaus.plexus.util.xml.Xpp3Dom; + /** * MojoExecution */ @@ -37,13 +37,12 @@ public class MojoExecution private String goal; - private final String executionId; + private String executionId; private MojoDescriptor mojoDescriptor; private Xpp3Dom configuration; - /** * Describes the source of an execution. */ @@ -64,8 +63,8 @@ public enum Source private Source source = Source.LIFECYCLE; /** - * The phase may or may not have been bound to a phase but once the plan has been calculated we know what phase this - * mojo execution is going to run in. + * The phase may or may not have been bound to a phase but once the plan has been calculated we know what phase + * this mojo execution is going to run in. */ private String lifecyclePhase; @@ -73,7 +72,7 @@ public enum Source * The executions to fork before this execution, indexed by the groupId:artifactId:version of the project on which * the forked execution are to be run and in reactor build order. */ - private final Map> forkedExecutions = new LinkedHashMap<>(); + private Map> forkedExecutions = new LinkedHashMap<>(); public MojoExecution( Plugin plugin, String goal, String executionId ) { @@ -153,7 +152,12 @@ public void setConfiguration( Xpp3Dom configuration ) public String identify() { - return executionId + configuration.toString(); + StringBuilder sb = new StringBuilder( 256 ); + + sb.append( executionId ); + sb.append( configuration.toString() ); + + return sb.toString(); } public String getLifecyclePhase() @@ -232,4 +236,5 @@ public void setForkedExecutions( String projectKey, List forkedEx { this.forkedExecutions.put( projectKey, forkedExecutions ); } + } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 70b85757f869..629b53a2351a 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -92,7 +92,7 @@ @Named @Singleton public class DefaultProjectBuilder - implements ProjectBuilder + implements ProjectBuilder { private final Logger logger = LoggerFactory.getLogger( getClass() ); private final ModelBuilder modelBuilder; @@ -121,13 +121,13 @@ public DefaultProjectBuilder( this.repositoryManager = repositoryManager; this.dependencyResolver = dependencyResolver; } - // ---------------------------------------------------------------------- +// ---------------------------------------------------------------------- // MavenProjectBuilder Implementation // ---------------------------------------------------------------------- @Override public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest request ) - throws ProjectBuildingException + throws ProjectBuildingException { return build( pomFile, new FileModelSource( pomFile ), new InternalConfig( request, null, null ) ); @@ -135,14 +135,14 @@ public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest request @Override public ProjectBuildingResult build( ModelSource modelSource, ProjectBuildingRequest request ) - throws ProjectBuildingException + throws ProjectBuildingException { return build( null, modelSource, - new InternalConfig( request, null, null ) ); + new InternalConfig( request, null, null ) ); } private ProjectBuildingResult build( File pomFile, ModelSource modelSource, InternalConfig config ) - throws ProjectBuildingException + throws ProjectBuildingException { ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -163,7 +163,7 @@ private ProjectBuildingResult build( File pomFile, ModelSource modelSource, Inte project.setFile( pomFile ); DefaultModelBuildingListener listener = - new DefaultModelBuildingListener( project, projectBuildingHelper, projectBuildingRequest ); + new DefaultModelBuildingListener( project, projectBuildingHelper, projectBuildingRequest ); request.setModelBuildingListener( listener ); request.setPomFile( pomFile ); @@ -189,7 +189,7 @@ private ProjectBuildingResult build( File pomFile, ModelSource modelSource, Inte modelProblems = result.getProblems(); initProject( project, Collections.emptyMap(), true, - result, new HashMap<>(), projectBuildingRequest ); + result, new HashMap<>(), projectBuildingRequest ); } else if ( projectBuildingRequest.isResolveDependencies() ) { @@ -238,7 +238,7 @@ private DependencyResolutionResult resolveDependencies( MavenProject project, Re if ( resolutionResult.getDependencyGraph() != null ) { RepositoryUtils.toArtifacts( artifacts, resolutionResult.getDependencyGraph().getChildren(), - Collections.singletonList( project.getArtifact().getId() ), null ); + Collections.singletonList( project.getArtifact().getId() ), null ); // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not LocalRepositoryManager lrm = session.getLocalRepositoryManager(); @@ -271,8 +271,8 @@ private ModelBuildingRequest getModelBuildingRequest( InternalConfig config ) RequestTrace trace = RequestTrace.newChild( null, configuration ).newChild( request ); ModelResolver resolver = - new ProjectModelResolver( config.session, trace, repoSystem, repositoryManager, config.repositories, - configuration.getRepositoryMerging(), config.modelPool ); + new ProjectModelResolver( config.session, trace, repoSystem, repositoryManager, config.repositories, + configuration.getRepositoryMerging(), config.modelPool ); request.setValidationLevel( configuration.getValidationLevel() ); request.setProcessPlugins( configuration.isProcessPlugins() ); @@ -295,20 +295,20 @@ private ModelBuildingRequest getModelBuildingRequest( InternalConfig config ) @Override public ProjectBuildingResult build( Artifact artifact, ProjectBuildingRequest request ) - throws ProjectBuildingException + throws ProjectBuildingException { return build( artifact, false, request ); } @Override public ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, ProjectBuildingRequest request ) - throws ProjectBuildingException + throws ProjectBuildingException { org.eclipse.aether.artifact.Artifact pomArtifact = RepositoryUtils.toArtifact( artifact ); pomArtifact = ArtifactDescriptorUtils.toPomArtifact( pomArtifact ); InternalConfig config = - new InternalConfig( request, null, null ); + new InternalConfig( request, null, null ); boolean localProject; @@ -329,7 +329,7 @@ public ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, P return build( null, createStubModelSource( artifact ), config ); } throw new ProjectBuildingException( artifact.getId(), - "Error resolving project artifact: " + e.getMessage(), e ); + "Error resolving project artifact: " + e.getMessage(), e ); } File pomFile = pomArtifact.getFile(); @@ -348,8 +348,8 @@ public ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, P else { return build( null, new ArtifactModelSource( pomFile, artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion() ), - config ); + artifact.getVersion() ), + config ); } } @@ -371,7 +371,7 @@ private ModelSource createStubModelSource( Artifact artifact ) @Override public List build( List pomFiles, boolean recursive, ProjectBuildingRequest request ) - throws ProjectBuildingException + throws ProjectBuildingException { List results = new ArrayList<>(); @@ -381,14 +381,14 @@ public List build( List pomFiles, boolean recursive final ReactorModelPool modelPool = poolBuilder.build(); InternalConfig config = - new InternalConfig( request, modelPool, modelBuilder.newTransformerContextBuilder() ); + new InternalConfig( request, modelPool, modelBuilder.newTransformerContextBuilder() ); Map projectIndex = new HashMap<>( 256 ); // phase 1: get file Models from the reactor. boolean noErrors = - build( results, interimResults, projectIndex, pomFiles, new LinkedHashSet<>(), true, recursive, - config, poolBuilder ); + build( results, interimResults, projectIndex, pomFiles, new LinkedHashSet<>(), true, recursive, + config, poolBuilder ); ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -396,8 +396,8 @@ public List build( List pomFiles, boolean recursive { // Phase 2: get effective models from the reactor noErrors = - build( results, new ArrayList<>(), projectIndex, interimResults, request, - new HashMap<>(), config.session ) && noErrors; + build( results, new ArrayList<>(), projectIndex, interimResults, request, + new HashMap<>(), config.session ) && noErrors; } finally { @@ -407,7 +407,7 @@ public List build( List pomFiles, boolean recursive if ( Features.buildConsumer( request.getUserProperties() ).isActive() ) { request.getRepositorySession().getData().set( TransformerContext.KEY, - config.transformerContextBuilder.build() ); + config.transformerContextBuilder.build() ); } if ( !noErrors ) @@ -431,7 +431,7 @@ private boolean build( List results, List aggregatorFiles.add( pomFile ); if ( !build( results, interimResults, projectIndex, pomFile, aggregatorFiles, root, recursive, config, - poolBuilder ) ) + poolBuilder ) ) { noErrors = false; } @@ -454,12 +454,12 @@ private boolean build( List results, List project.setFile( pomFile ); ModelBuildingRequest request = getModelBuildingRequest( config ) - .setPomFile( pomFile ) - .setTwoPhaseBuilding( true ) - .setLocationTracking( true ); + .setPomFile( pomFile ) + .setTwoPhaseBuilding( true ) + .setLocationTracking( true ); DefaultModelBuildingListener listener = - new DefaultModelBuildingListener( project, projectBuildingHelper, config.request ); + new DefaultModelBuildingListener( project, projectBuildingHelper, config.request ); request.setModelBuildingListener( listener ); ModelBuildingResult result; @@ -472,9 +472,9 @@ private boolean build( List results, List result = e.getResult(); if ( result == null || result.getFileModel() == null ) { - results.add( new DefaultProjectBuildingResult( e.getModelId(), pomFile, e.getProblems() ) ); + results.add( new DefaultProjectBuildingResult( e.getModelId(), pomFile, e.getProblems() ) ); - return false; + return false; } // validation error, continue project building and delay failing to help IDEs // result.getProblems().addAll(e.getProblems()) ? @@ -483,7 +483,7 @@ private boolean build( List results, List Model model = result.getFileModel().clone(); - poolBuilder.put( model.getPomFile().toPath(), model ); + poolBuilder.put( model.getPomFile().toPath(), model ); InterimResult interimResult = new InterimResult( pomFile, request, result, listener, isRoot ); interimResults.add( interimResult ); @@ -511,10 +511,9 @@ private boolean build( List results, List if ( !moduleFile.isFile() ) { ModelProblem problem = - new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile - + " does not exist", ModelProblem.Severity.ERROR, ModelProblem.Version.BASE, model, - -1, - -1, null ); + new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile + + " does not exist", ModelProblem.Severity.ERROR, ModelProblem.Version.BASE, model, -1, + -1, null ); result.getProblems().add( problem ); noErrors = false; @@ -549,9 +548,9 @@ private boolean build( List results, List buffer.append( moduleFile ); ModelProblem problem = - new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile - + " forms aggregation cycle " + buffer, ModelProblem.Severity.ERROR, - ModelProblem.Version.BASE, model, -1, -1, null ); + new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile + + " forms aggregation cycle " + buffer, ModelProblem.Severity.ERROR, + ModelProblem.Version.BASE, model, -1, -1, null ); result.getProblems().add( problem ); noErrors = false; @@ -565,7 +564,7 @@ private boolean build( List results, List interimResult.modules = new ArrayList<>(); if ( !build( results, interimResult.modules, projectIndex, moduleFiles, aggregatorFiles, false, - recursive, config, poolBuilder ) ) + recursive, config, poolBuilder ) ) { noErrors = false; } @@ -630,8 +629,8 @@ private boolean build( List results, List p List modules = new ArrayList<>(); noErrors = - build( results, modules, projectIndex, interimResult.modules, request, profilesXmls, session ) - && noErrors; + build( results, modules, projectIndex, interimResult.modules, request, profilesXmls, session ) + && noErrors; projects.addAll( modules ); projects.add( project ); @@ -681,9 +680,8 @@ private void initProject( MavenProject project, Map projects initParent( project, projects, buildParentIfNotExisting, result, projectBuildingRequest ); Artifact projectArtifact = - repositorySystem.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), - null, - project.getPackaging() ); + repositorySystem.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), null, + project.getPackaging() ); project.setArtifact( projectArtifact ); if ( project.getFile() != null && buildParentIfNotExisting ) // only set those on 2nd phase, ignore on 1st pass @@ -760,7 +758,7 @@ private void initProject( MavenProject project, Map projects } Artifact artifact = - repositorySystem.createArtifact( ext.getGroupId(), ext.getArtifactId(), version, null, "jar" ); + repositorySystem.createArtifact( ext.getGroupId(), ext.getArtifactId(), version, null, "jar" ); if ( artifact != null ) { @@ -776,7 +774,7 @@ private void initProject( MavenProject project, Map projects { final DependencyManagement dependencyManagement = project.getDependencyManagement(); if ( ( dependencyManagement != null ) && ( ( dependencyManagement.getDependencies() ) != null ) - && ( dependencyManagement.getDependencies().size() > 0 ) ) + && ( dependencyManagement.getDependencies().size() > 0 ) ) { map = new AbstractMap() { @@ -847,7 +845,7 @@ HashMap compute() // release artifact repository if ( project.getDistributionManagement() != null - && project.getDistributionManagement().getRepository() != null ) + && project.getDistributionManagement().getRepository() != null ) { try { @@ -856,22 +854,22 @@ HashMap compute() { ArtifactRepository repo = MavenRepositorySystem.buildArtifactRepository( r ); repositorySystem.injectProxy( projectBuildingRequest.getRepositorySession(), - Arrays.asList( repo ) ); + Arrays.asList( repo ) ); repositorySystem.injectAuthentication( projectBuildingRequest.getRepositorySession(), - Arrays.asList( repo ) ); + Arrays.asList( repo ) ); project.setReleaseArtifactRepository( repo ); } } catch ( InvalidRepositoryException e ) { throw new IllegalStateException( "Failed to create release distribution repository for " - + project.getId(), e ); + + project.getId(), e ); } } // snapshot artifact repository if ( project.getDistributionManagement() != null - && project.getDistributionManagement().getSnapshotRepository() != null ) + && project.getDistributionManagement().getSnapshotRepository() != null ) { try { @@ -880,16 +878,16 @@ HashMap compute() { ArtifactRepository repo = MavenRepositorySystem.buildArtifactRepository( r ); repositorySystem.injectProxy( projectBuildingRequest.getRepositorySession(), - Arrays.asList( repo ) ); + Arrays.asList( repo ) ); repositorySystem.injectAuthentication( projectBuildingRequest.getRepositorySession(), - Arrays.asList( repo ) ); + Arrays.asList( repo ) ); project.setSnapshotArtifactRepository( repo ); } } catch ( InvalidRepositoryException e ) { throw new IllegalStateException( "Failed to create snapshot distribution repository for " - + project.getId(), e ); + + project.getId(), e ); } } } @@ -898,8 +896,8 @@ private void initParent( MavenProject project, Map projects, ModelBuildingResult result, ProjectBuildingRequest projectBuildingRequest ) { Model parentModel = result.getModelIds().size() > 1 && !result.getModelIds().get( 1 ).isEmpty() - ? result.getRawModel( result.getModelIds().get( 1 ) ) - : null; + ? result.getRawModel( result.getModelIds().get( 1 ) ) + : null; if ( parentModel != null ) { @@ -907,8 +905,8 @@ private void initParent( MavenProject project, Map projects, final String parentVersion = inheritedVersion( result, 1 ); project.setParentArtifact( repositorySystem.createProjectArtifact( parentGroupId, - parentModel.getArtifactId(), - parentVersion ) ); + parentModel.getArtifactId(), + parentVersion ) ); // org.apache.maven.its.mng4834:parent:0.1 String parentModelId = result.getModelIds().get( 1 ); @@ -984,8 +982,8 @@ private static String inheritedGroupId( final ModelBuildingResult result, final { final Model model = result.getRawModel( modelId ); groupId = model.getGroupId() != null - ? model.getGroupId() - : inheritedGroupId( result, modelIndex + 1 ); + ? model.getGroupId() + : inheritedGroupId( result, modelIndex + 1 ); } @@ -1001,8 +999,8 @@ private static String inheritedVersion( final ModelBuildingResult result, final { final Model model = result.getRawModel( modelId ); version = model.getVersion() != null - ? model.getVersion() - : inheritedVersion( result, modelIndex + 1 ); + ? model.getVersion() + : inheritedVersion( result, modelIndex + 1 ); } @@ -1033,8 +1031,8 @@ class InternalConfig this.transformerContextBuilder = transformerContextBuilder; session = - LegacyLocalRepositoryManager.overlay( request.getLocalRepository(), request.getRepositorySession(), - repoSystem ); + LegacyLocalRepositoryManager.overlay( request.getLocalRepository(), request.getRepositorySession(), + repoSystem ); repositories = RepositoryUtils.toRepos( request.getRemoteRepositories() ); } diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index f53fe5e2b8e6..57069a5e6a9a 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -145,7 +145,7 @@ public class MavenProject private List activeProfiles = new ArrayList<>(); - private final Map> injectedProfileIds = new LinkedHashMap<>(); + private Map> injectedProfileIds = new LinkedHashMap<>(); private Set dependencyArtifacts; @@ -168,7 +168,7 @@ public class MavenProject private Map managedVersionMap; - private final Map projectReferences = new HashMap<>(); + private Map projectReferences = new HashMap<>(); private boolean executionRoot; @@ -1427,7 +1427,7 @@ public DependencyFilter getExtensionDependencyFilter() */ public void setResolvedArtifacts( Set artifacts ) { - this.resolvedArtifacts = ( artifacts != null ) ? artifacts : Collections.emptySet(); + this.resolvedArtifacts = ( artifacts != null ) ? artifacts : Collections.emptySet(); this.artifacts = null; this.artifactMap = null; } diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java index a6424f670f15..cc2961f91bcd 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorSubModulesTest.java @@ -22,10 +22,10 @@ import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator; import org.apache.maven.lifecycle.internal.LifecycleModuleBuilder; import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator; +import org.apache.maven.lifecycle.internal.MojoExecutor; import javax.inject.Inject; -import org.apache.maven.lifecycle.internal.MojoExecutor; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertNotNull; diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java index f32707f7ab79..fc2a3ec00990 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java @@ -65,6 +65,7 @@ public List executeForkedExecutions( MojoExecution mojoExecution, return null; } + public static MojoDescriptor createMojoDescriptor( String mojoDescription ) { final PluginDescriptor descriptor = new PluginDescriptor(); From 0dc3db7d7fcecca3ab28d731b5680ae96c3aa3bb Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 18 Nov 2021 10:05:41 +0100 Subject: [PATCH 156/188] Use a lambda expression --- .../org/apache/maven/lifecycle/internal/MojoExecutor.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java index c7709b493d59..26e3f5441e4b 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java @@ -154,9 +154,7 @@ public void execute( MavenSession session, List mojoExecutions, P PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); mojosExecutionStrategy.execute( mojoExecutions, session, mojoExecution -> - { - execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); - } ); + execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ) ); } private void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, From f306fcaae1daeb23ff23132588bc112168d159db Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 19 Nov 2021 16:18:47 +0100 Subject: [PATCH 157/188] Do not include maven-caching in the distribution --- apache-maven/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index 82364f87ec18..57f2718f1c71 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -47,10 +47,6 @@ under the License. org.apache.maven maven-core
    - - org.apache.maven - maven-caching - org.apache.maven maven-compat From f0179653d3e7e1c46e4b49500cfd8a3cc52b640f Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 22 Nov 2021 09:10:21 +0100 Subject: [PATCH 158/188] Fix problems when restoring projects that do not have any packaged artifacts Problems happens with pure testing modules for example --- .../maven/caching/CacheControllerImpl.java | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index a3ea83794711..e699f77e2755 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -111,8 +111,7 @@ public class CacheControllerImpl implements CacheController { public static final String FILE_SEPARATOR_SUBST = "_"; - private static final String GENERATEDSOURCES = "generatedsources"; - private static final String GENERATEDSOURCES_PREFIX = GENERATEDSOURCES + FILE_SEPARATOR_SUBST; + private static final String BUILD_PREFIX = "build" + FILE_SEPARATOR_SUBST; private static final Logger LOGGER = LoggerFactory.getLogger( CacheControllerImpl.class ); @@ -332,7 +331,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) } LOGGER.debug( "Attaching artifact {} from {}", artifact.getArtifactId(), attachedArtifactFile ); - if ( StringUtils.startsWith( attachedArtifact.getClassifier(), GENERATEDSOURCES_PREFIX ) ) + if ( StringUtils.startsWith( attachedArtifact.getClassifier(), BUILD_PREFIX ) ) { // generated sources artifact restoreGeneratedSources( attachedArtifact, attachedArtifactFile, project ); @@ -415,17 +414,27 @@ public void save( CacheResult cacheResult, List mojoExecutions, final MavenSession session = context.getSession(); try { - attachGeneratedSources( project ); - attachOutputs( project ); - - final org.apache.maven.artifact.Artifact projectArtifact = project.getArtifact(); final HashFactory hashFactory = cacheConfig.getHashFactory(); - final HashAlgorithm algorithm = hashFactory.createAlgorithm(); - final Artifact projectArtifactDto = artifactDto( project.getArtifact(), algorithm ); - - final List attachedArtifacts = - project.getAttachedArtifacts() != null ? project.getAttachedArtifacts() : Collections.emptyList(); - List attachedArtifactDtos = artifactDtos( attachedArtifacts, algorithm ); + final org.apache.maven.artifact.Artifact projectArtifact = project.getArtifact(); + final List attachedArtifacts; + final List attachedArtifactDtos; + final Artifact projectArtifactDto; + if ( project.hasLifecyclePhase( "package" ) ) + { + final HashAlgorithm algorithm = hashFactory.createAlgorithm(); + attachGeneratedSources( project ); + attachOutputs( project ); + attachedArtifacts = project.getAttachedArtifacts() != null + ? project.getAttachedArtifacts() : Collections.emptyList(); + attachedArtifactDtos = artifactDtos( attachedArtifacts, algorithm ); + projectArtifactDto = artifactDto( project.getArtifact(), algorithm ); + } + else + { + attachedArtifacts = Collections.emptyList(); + attachedArtifactDtos = new ArrayList<>(); + projectArtifactDto = null; + } List completedExecution = buildExecutionInfo( mojoExecutions, executionEvents ); @@ -566,7 +575,8 @@ private List buildExecutionInfo( List mojoExe for ( MojoExecution mojoExecution : mojoExecutions ) { final String executionKey = CacheUtils.mojoExecutionKey( mojoExecution ); - final MojoExecutionEvent executionEvent = executionEvents.get( executionKey ); + final MojoExecutionEvent executionEvent = + executionEvents != null ? executionEvents.get( executionKey ) : null; CompletedExecution executionInfo = new CompletedExecution(); executionInfo.setExecutionKey( executionKey ); executionInfo.setMojoClassName( mojoExecution.getMojoDescriptor().getImplementation() ); @@ -798,12 +808,12 @@ private String pathToClassifier( Path relative ) segments.add( relative.getName( i ).toFile().getName() ); } // todo handle _ in file names - return GENERATEDSOURCES_PREFIX + StringUtils.join( segments.iterator(), FILE_SEPARATOR_SUBST ); + return BUILD_PREFIX + StringUtils.join( segments.iterator(), FILE_SEPARATOR_SUBST ); } private Path classifierToPath( Path outputDir, String classifier ) { - classifier = StringUtils.removeStart( classifier, GENERATEDSOURCES_PREFIX ); + classifier = StringUtils.removeStart( classifier, BUILD_PREFIX ); final String relPath = replace( classifier, FILE_SEPARATOR_SUBST, File.separator ); return outputDir.resolve( relPath ); } From 806eb33bd40bb5eefcaa602a5465a66db6ecdc6b Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 22 Nov 2021 15:46:48 +0100 Subject: [PATCH 159/188] Add missing commons-lang3 dependency --- maven-caching/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/maven-caching/pom.xml b/maven-caching/pom.xml index 34a3397c7baa..87e904365189 100644 --- a/maven-caching/pom.xml +++ b/maven-caching/pom.xml @@ -55,6 +55,10 @@ under the License. juniversalchardet 2.4.0 + + org.apache.commons + commons-lang3 + com.google.code.findbugs jsr305 From 2157ad23c8ca061fe0a3cc8dd61f6b13b5d86d69 Mon Sep 17 00:00:00 2001 From: Alexander Ashitkin Date: Fri, 19 Nov 2021 23:11:04 -0500 Subject: [PATCH 160/188] [MNG-7129] Remove redundant remote calls --- .../caching/HttpCacheRepositoryImpl.java | 50 ++++++------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java index 6c5ef598c10c..23229e9fefc5 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java @@ -32,10 +32,10 @@ import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpHead; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.CloseableHttpClient; @@ -97,9 +97,9 @@ private static CloseableHttpClient newHttpClient() public Build findBuild( CacheContext context ) { final String resourceUrl = getResourceUrl( context, BUILDINFO_XML ); - if ( exists( resourceUrl ) ) + final byte[] bytes = getResourceContent( resourceUrl ); + if ( bytes != null ) { - final byte[] bytes = getResourceContent( resourceUrl ); final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( bytes ); return new Build( dto, CacheSource.REMOTE ); } @@ -144,44 +144,24 @@ public void saveArtifactFile( CacheResult cacheResult, } } - @SuppressWarnings( "checkstyle:magicnumber" ) - private boolean exists( String url ) - { - HttpHead head = null; - try - { - head = new HttpHead( url ); - HttpResponse response = httpClient.get().execute( head ); - int statusCode = response.getStatusLine().getStatusCode(); - LOGGER.info( "Checking {}. Status: {}", url, statusCode ); - return statusCode == 200; - } - catch ( IOException e ) - { - throw new RuntimeException( "Cannot check " + url, e ); - } - finally - { - if ( head != null ) - { - head.releaseConnection(); - } - } - } - - @SuppressWarnings( "checkstyle:magicnumber" ) + /** + * Downloads content of the resource + * + * @return null or content + */ public byte[] getResourceContent( String url ) { HttpGet get = null; try { get = new HttpGet( url ); + LOGGER.info( "Downloading {}", url ); HttpResponse response = httpClient.get().execute( get ); int statusCode = response.getStatusLine().getStatusCode(); - LOGGER.info( "Downloading {}. Status: {}", url, statusCode ); - if ( statusCode != 200 ) + if ( statusCode != HttpStatus.SC_OK ) { - throw new RuntimeException( "Cannot download " + url + ", unexpected status code: " + statusCode ); + LOGGER.info( "Cannot download {}, status code: {}", url, statusCode ); + return null; } try ( InputStream content = response.getEntity().getContent() ) { @@ -215,7 +195,7 @@ private String getResourceUrl( String filename, String groupId, String artifactI } /** - * @param instream to be closed externally + * @param instream to be closed externally */ private void putToRemoteCache( InputStream instream, String url ) throws IOException { @@ -278,9 +258,9 @@ public Optional findBaselineBuild( MavenProject project ) try { - if ( exists( url ) ) + byte[] content = getResourceContent( url ); + if ( content != null ) { - byte[] content = getResourceContent( url ); final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( content ); return Optional.of( new Build( dto, CacheSource.REMOTE ) ); } From 1b7fee5f944628a17453ffab32c9601d74b75e73 Mon Sep 17 00:00:00 2001 From: Alexander Ashitkin Date: Tue, 23 Nov 2021 10:58:03 -0500 Subject: [PATCH 161/188] [MNG-7129] Restore artifacts from cache lazily (#614) Co-authored-by: Alexander Ashitkin --- .../maven/caching/CacheControllerImpl.java | 159 +++++++++++------- .../caching/artifact/RestoredArtifact.java | 115 +++++++++++++ .../apache/maven/caching/xml/CacheConfig.java | 15 ++ .../maven/caching/xml/CacheConfigImpl.java | 19 ++- 4 files changed, 250 insertions(+), 58 deletions(-) create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/artifact/RestoredArtifact.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index e699f77e2755..068e8be09dfd 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -40,6 +40,8 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; import java.util.function.Function; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -55,6 +57,7 @@ import org.apache.maven.SessionScoped; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.caching.artifact.RestoredArtifact; import org.apache.maven.caching.checksum.KeyUtils; import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.hash.HashAlgorithm; @@ -111,6 +114,9 @@ public class CacheControllerImpl implements CacheController { public static final String FILE_SEPARATOR_SUBST = "_"; + /** + * Prefix for generated sources stored as a separate artifact in cache + */ private static final String BUILD_PREFIX = "build" + FILE_SEPARATOR_SUBST; private static final Logger LOGGER = LoggerFactory.getLogger( CacheControllerImpl.class ); @@ -296,61 +302,62 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) final CacheContext context = cacheResult.getContext(); final MavenProject project = context.getProject(); - final Artifact artifact = build.getArtifact(); - artifact.setVersion( project.getVersion() ); - try { - File file = null; - List artifacts = new ArrayList<>(); - if ( isNotBlank( artifact.getFileName() ) ) + RestoredArtifact restoredProjectArtifact = null; + List restoredAttachedArtifacts = new ArrayList<>(); + + if ( build.getArtifact() != null && isNotBlank( build.getArtifact().getFileName() ) ) { + final Artifact artifactInfo = build.getArtifact(); + artifactInfo.setVersion( project.getVersion() ); // TODO if remote is forced, probably need to refresh or reconcile all files - final Path artifactFile = localCache.getArtifactFile( context, cacheResult.getSource(), artifact ); - if ( !Files.exists( artifactFile ) ) - { - LOGGER.info( "Missing file for cached build, cannot restore. File: {}", artifactFile ); - return false; - } - LOGGER.debug( "Setting project artifact {} from {}", artifact.getArtifactId(), artifactFile ); - file = artifactFile.toFile(); - putChecksum( artifact, context.getInputInfo().getChecksum() ); + final Future downloadTask = createDownloadTask( cacheResult, context, project, artifactInfo ); + restoredProjectArtifact = + restoredArtifact( project.getArtifact(), artifactInfo.getType(), artifactInfo.getClassifier(), + downloadTask ); + putChecksum( artifactInfo, context.getInputInfo().getChecksum() ); } - for ( Artifact attachedArtifact : build.getAttachedArtifacts() ) + for ( Artifact attachedArtifactInfo : build.getAttachedArtifacts() ) { - attachedArtifact.setVersion( project.getVersion() ); - if ( isNotBlank( attachedArtifact.getFileName() ) ) + attachedArtifactInfo.setVersion( project.getVersion() ); + if ( isNotBlank( attachedArtifactInfo.getFileName() ) ) { - final Path attachedArtifactFile = localCache.getArtifactFile( context, cacheResult.getSource(), - attachedArtifact ); - if ( !Files.exists( attachedArtifactFile ) ) + if ( StringUtils.startsWith( attachedArtifactInfo.getClassifier(), BUILD_PREFIX ) ) { - throw new FileNotFoundException( - "Missing file for cached build, cannot restore. File: " + attachedArtifactFile ); - } - LOGGER.debug( "Attaching artifact {} from {}", - artifact.getArtifactId(), attachedArtifactFile ); - if ( StringUtils.startsWith( attachedArtifact.getClassifier(), BUILD_PREFIX ) ) - { - // generated sources artifact - restoreGeneratedSources( attachedArtifact, attachedArtifactFile, project ); + // restoring generated sources might be unnecessary in CI, could be disabled for + // performance reasons + if ( cacheConfig.isRestoreGeneratedSources() ) + { + // generated sources artifact + final Path attachedArtifactFile = localCache.getArtifactFile( context, + cacheResult.getSource(), attachedArtifactInfo ); + restoreGeneratedSources( attachedArtifactInfo, attachedArtifactFile, project ); + } } else { - artifacts.add( new ArtifactToAttach( attachedArtifact, attachedArtifactFile ) ); + Future downloadTask = + createDownloadTask( cacheResult, context, project, attachedArtifactInfo ); + final RestoredArtifact restoredAttachedArtifact = + restoredArtifact( restoredProjectArtifact == null ? project.getArtifact() + : restoredProjectArtifact, + attachedArtifactInfo.getType(), + attachedArtifactInfo.getClassifier(), + downloadTask ); + restoredAttachedArtifacts.add( restoredAttachedArtifact ); } - putChecksum( attachedArtifact, context.getInputInfo().getChecksum() ); + putChecksum( attachedArtifactInfo, context.getInputInfo().getChecksum() ); } } // Actually modify project at the end in case something went wrong during restoration, // in which case, the project is unmodified and we continue with normal build. - if ( file != null ) + if ( restoredProjectArtifact != null ) { - project.getArtifact().setFile( file ); - project.getArtifact().setResolved( true ); + project.setArtifact( restoredProjectArtifact ); } - artifacts.forEach( a -> projectHelper.attachArtifact( project, a.type, a.classifier, a.file ) ); + restoredAttachedArtifacts.forEach( a -> project.addAttachedArtifact( a ) ); return true; } catch ( Exception e ) @@ -360,6 +367,64 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) } } + /** + * Helper method similar to {@link org.apache.maven.project.MavenProjectHelper#attachArtifact} to work specifically + * with restored from cache artifacts + */ + private RestoredArtifact restoredArtifact( org.apache.maven.artifact.Artifact parent, String artifactType, + String artifactClassifier, + Future artifactFile ) + { + ArtifactHandler handler = null; + + if ( artifactType != null ) + { + handler = artifactHandlerManager.getArtifactHandler( artifactType ); + } + + if ( handler == null ) + { + handler = artifactHandlerManager.getArtifactHandler( "jar" ); + } + + // todo: probably need update download url to cache + RestoredArtifact artifact = new RestoredArtifact( parent, artifactFile, artifactType, artifactClassifier, + handler ); + artifact.setResolved( true ); + + return artifact; + } + + private Future createDownloadTask( CacheResult cacheResult, CacheContext context, MavenProject project, + Artifact artifact ) + { + final FutureTask downloadTask = new FutureTask<>( () -> + { + try + { + LOGGER.debug( "Downloading artifact {}", artifact.getArtifactId() ); + final Path artifactFile = localCache.getArtifactFile( context, cacheResult.getSource(), + artifact ); + if ( !Files.exists( artifactFile ) ) + { + throw new FileNotFoundException( + "Missing file for cached build, cannot restore. File: " + artifactFile ); + } + LOGGER.debug( "Downloaded artifact " + artifact.getArtifactId() + " to: " + artifactFile ); + return artifactFile.toFile(); + } + catch ( IOException e ) + { + throw new RuntimeException( "Cannot download artifact: " + artifact.getArtifactId(), e ); + } + } ); + if ( !cacheConfig.isLazyRestore() ) + { + downloadTask.run(); + } + return downloadTask; + } + private void putChecksum( Artifact artifact, String projectChecksum ) { final DigestItem projectArtifact = DtoUtils.createdDigestedByProjectChecksum( artifact, projectChecksum ); @@ -525,7 +590,7 @@ public void produceDiffReport( CacheResult cacheResult, Build build ) if ( baselinePom.isPresent() ) { Files.write( reportOutputDir.resolve( - "effective-pom-baseline-" + baselineInputs.getChecksum() + ".xml" ), + "effective-pom-baseline-" + baselineInputs.getChecksum() + ".xml" ), baselinePom.get().getValue().getBytes( StandardCharsets.UTF_8 ), TRUNCATE_EXISTING, CREATE ); } @@ -917,24 +982,4 @@ private boolean isOutputArtifact( String name ) } return true; } - - private static class ArtifactToAttach - { - private final String type; - private final String classifier; - private final File file; - - ArtifactToAttach( String type, String classifier, File file ) - { - this.type = type; - this.classifier = classifier; - this.file = file; - } - - ArtifactToAttach( Artifact attachedArtifact, Path attachedArtifactFile ) - { - this( attachedArtifact.getType(), attachedArtifact.getClassifier(), attachedArtifactFile.toFile() ); - } - } - } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/artifact/RestoredArtifact.java b/maven-caching/src/main/java/org/apache/maven/caching/artifact/RestoredArtifact.java new file mode 100644 index 000000000000..3ee320d0c973 --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/artifact/RestoredArtifact.java @@ -0,0 +1,115 @@ +package org.apache.maven.caching.artifact; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.commons.lang3.concurrent.ConcurrentException; +import org.apache.commons.lang3.concurrent.ConcurrentUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.InvalidArtifactRTException; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.RunnableFuture; + +import static java.util.Objects.requireNonNull; + +/** + * Overrides default file behavior with async file holder to restore files from cache lazy. Similar to {@link + * org.apache.maven.project.artifact.AttachedArtifact} + */ +public class RestoredArtifact extends DefaultArtifact +{ + + private static final Logger LOGGER = LoggerFactory.getLogger( RestoredArtifact.class ); + + private volatile Future fileFuture; + + public RestoredArtifact( Artifact parent, Future fileFuture, String type, String classifier, + ArtifactHandler handler ) + { + super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type, + classifier, handler, parent.isOptional() ); + this.fileFuture = requireNonNull( fileFuture, "fileFuture == null" ); + } + + /** + * Returns file using caller thread to download it if necessary + */ + @Override + public File getFile() + { + + if ( !fileFuture.isDone() ) + { + if ( fileFuture instanceof RunnableFuture ) + { + try + { + LOGGER.trace( "Artifact file {} is not yet retrieved, downloading directly", + getDependencyConflictId() ); + ( (RunnableFuture) fileFuture ).run(); + } + catch ( RuntimeException e ) + { + throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), + getVersion(), getType(), + "Error retrieving artifact file", e ); + } + } + else + { + LOGGER.trace( "Artifact file {} is not yet retrieved, waiting for download to complete", + getDependencyConflictId() ); + } + } + + try + { + return fileFuture.get(); + } + catch ( InterruptedException e ) + { + Thread.currentThread().interrupt(); + throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), + getVersion(), getType(), + "Interrupted while retrieving artifact file" ); + } + catch ( ExecutionException e ) + { + final ConcurrentException cause = ConcurrentUtils.extractCause( e ); + throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), + getVersion(), getType(), "Error retrieving artifact file", + cause ); + } + } + + + @Override + public void setFile( File destination ) + { + this.fileFuture = CompletableFuture.completedFuture( destination ); + } +} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java index 63ed1430cabb..7bf8540cdfa5 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java @@ -105,4 +105,19 @@ public interface CacheConfig boolean isBaselineDiffEnabled(); String getBaselineCacheUrl(); + + /** + * Artifacts restore policy. Eager policy (default) resolves all cached artifacts before restoring project and + * allows safe to fallback ro normal execution in case of restore failure. Lazy policy restores artifacts on demand + * minimizing need for downloading any artifacts from cache + *

    + * Use: -Dremote.cache.lazyRestore=(true|false) + */ + boolean isLazyRestore(); + + /** + * Flag to restore (default) or not generated sources as it might be desired to disable it in continuous integration + * scenarios + */ + boolean isRestoreGeneratedSources(); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 2a013b8ea8b7..294da4067beb 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -82,6 +82,8 @@ public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig public static final String SAVE_NON_OVERRIDEABLE_NAME = "remote.cache.save.final"; public static final String FAIL_FAST_PROPERTY_NAME = "remote.cache.failFast"; public static final String BASELINE_BUILD_URL_PROPERTY_NAME = "remote.cache.baselineUrl"; + public static final String LAZY_RESTORE_PROPERTY_NAME = "remote.cache.lazyRestore"; + public static final String RESTORE_GENERATED_SOURCES_PROPERTY_NAME = "remote.cache.restoreGeneratedSources"; private static final Logger LOGGER = LoggerFactory.getLogger( CacheConfigImpl.class ); @@ -335,7 +337,7 @@ public PluginScanConfig getExecutionDirScanConfig( Plugin plugin, PluginExecutio } private ExecutionConfigurationScan findExecutionScanConfig( PluginExecution execution, - List scanConfigs ) + List scanConfigs ) { for ( ExecutionConfigurationScan executionScanConfig : scanConfigs ) { @@ -502,6 +504,21 @@ public String getBaselineCacheUrl() return getProperty( BASELINE_BUILD_URL_PROPERTY_NAME, null ); } + @Override + public boolean isLazyRestore() + { + final String lazyRestore = getProperty( LAZY_RESTORE_PROPERTY_NAME, "false" ); + return Boolean.parseBoolean( lazyRestore ); + } + + @Override + public boolean isRestoreGeneratedSources() + { + final String restoreGeneratedSources = getProperty( RESTORE_GENERATED_SOURCES_PROPERTY_NAME, "true" ); + return Boolean.parseBoolean( restoreGeneratedSources ); + } + + @Override public String getUrl() { From 6aeeea1d1dfcf4ceb7ded6350d31fb957c2b8eea Mon Sep 17 00:00:00 2001 From: Alexander Ashitkin Date: Tue, 23 Nov 2021 12:21:06 -0500 Subject: [PATCH 162/188] [MNG-7129] Rework http repo to java 8 --- .../maven/caching/CacheControllerImpl.java | 99 +++++++------- .../apache/maven/caching/CacheRepository.java | 5 +- .../caching/HttpCacheRepositoryImpl.java | 123 ++++++++---------- .../maven/caching/LocalCacheRepository.java | 6 +- .../caching/LocalCacheRepositoryImpl.java | 48 ++++--- .../maven/caching/RemoteCacheRepository.java | 10 +- 6 files changed, 148 insertions(+), 143 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 068e8be09dfd..49527d69b138 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -193,91 +193,92 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, private CacheResult findCachedBuild( List mojoExecutions, CacheContext context ) { - Build cachedBuild = null; + Optional cachedBuild = Optional.empty(); try { cachedBuild = localCache.findBuild( context ); - return analyzeResult( context, mojoExecutions, cachedBuild ); + if ( cachedBuild.isPresent() ) + { + return analyzeResult( context, mojoExecutions, cachedBuild.get() ); + } } catch ( Exception e ) { - LOGGER.error( "Cannot read cached build", e ); - return cachedBuild != null ? failure( cachedBuild, context ) : failure( context ); + LOGGER.error( "Cannot read cached remote build", e ); } + return cachedBuild.map( build -> failure( build, context ) ) + .orElseGet( () -> empty( context ) ); } private CacheResult findLocalBuild( List mojoExecutions, CacheContext context ) { - Build localBuild = null; + Optional localBuild = Optional.empty(); try { localBuild = localCache.findLocalBuild( context ); - return analyzeResult( context, mojoExecutions, localBuild ); + if ( localBuild.isPresent() ) + { + return analyzeResult( context, mojoExecutions, localBuild.get() ); + } } catch ( Exception e ) { LOGGER.error( "Cannot read local build", e ); - return localBuild != null ? failure( localBuild, context ) : failure( context ); } + return localBuild.map( build -> failure( build, context ) ) + .orElseGet( () -> empty( context ) ); } - private CacheResult analyzeResult( CacheContext context, List mojoExecutions, Build info ) + private CacheResult analyzeResult( CacheContext context, List mojoExecutions, Build build ) { try { - if ( info != null ) - { - final ProjectsInputInfo inputInfo = context.getInputInfo(); - - LOGGER.info( "Found cached build, restoring from cache {}", inputInfo.getChecksum() ); - LOGGER.debug( "Cached build details: {}", info ); + final ProjectsInputInfo inputInfo = context.getInputInfo(); - final String cacheImplementationVersion = info.getCacheImplementationVersion(); - if ( !CACHE_IMPLEMENTATION_VERSION.equals( cacheImplementationVersion ) ) - { - LOGGER.warn( - "Maven and cached build implementations mismatch, caching might not work correctly. " - + "Implementation version: " + CACHE_IMPLEMENTATION_VERSION + ", cached build: {}", - info.getCacheImplementationVersion() ); - } - - List cachedSegment = lifecyclePhasesHelper.getCachedSegment( mojoExecutions, info ); - List missingMojos = info.getMissingExecutions( cachedSegment ); - if ( !missingMojos.isEmpty() ) - { - LOGGER.warn( "Cached build doesn't contains all requested plugin executions " - + "(missing: {}), cannot restore", missingMojos ); - return failure( info, context ); - } + LOGGER.info( "Found cached build, restoring from cache {}", inputInfo.getChecksum() ); + LOGGER.debug( "Cached build details: {}", build ); - if ( !isCachedSegmentPropertiesPresent( context.getProject(), info, cachedSegment ) ) - { - LOGGER.info( "Cached build violates cache rules, cannot restore" ); - return failure( info, context ); - } + final String cacheImplementationVersion = build.getCacheImplementationVersion(); + if ( !CACHE_IMPLEMENTATION_VERSION.equals( cacheImplementationVersion ) ) + { + LOGGER.warn( + "Maven and cached build implementations mismatch, caching might not work correctly. " + + "Implementation version: " + CACHE_IMPLEMENTATION_VERSION + ", cached build: {}", + build.getCacheImplementationVersion() ); + } - final String highestRequestPhase = CacheUtils.getLast( mojoExecutions ).getLifecyclePhase(); - if ( lifecyclePhasesHelper.isLaterPhaseThanBuild( highestRequestPhase, info ) - && !canIgnoreMissingSegment( info, mojoExecutions ) ) - { - LOGGER.info( "Project restored partially. Highest cached goal: {}, requested: {}", - info.getHighestCompletedGoal(), highestRequestPhase ); - return partialSuccess( info, context ); - } + List cachedSegment = lifecyclePhasesHelper.getCachedSegment( mojoExecutions, build ); + List missingMojos = build.getMissingExecutions( cachedSegment ); + if ( !missingMojos.isEmpty() ) + { + LOGGER.warn( "Cached build doesn't contains all requested plugin executions " + + "(missing: {}), cannot restore", missingMojos ); + return failure( build, context ); + } - return success( info, context ); + if ( !isCachedSegmentPropertiesPresent( context.getProject(), build, cachedSegment ) ) + { + LOGGER.info( "Cached build violates cache rules, cannot restore" ); + return failure( build, context ); } - else + + final String highestRequestPhase = CacheUtils.getLast( mojoExecutions ).getLifecyclePhase(); + if ( lifecyclePhasesHelper.isLaterPhaseThanBuild( highestRequestPhase, build ) + && !canIgnoreMissingSegment( build, mojoExecutions ) ) { - LOGGER.info( "Project is not found in cache" ); - return empty( context ); + LOGGER.info( "Project restored partially. Highest cached goal: {}, requested: {}", + build.getHighestCompletedGoal(), highestRequestPhase ); + return partialSuccess( build, context ); } + + return success( build, context ); + } catch ( Exception e ) { LOGGER.error( "Failed to restore project", e ); localCache.clearCache( context ); - return empty( context ); + return failure( build, context ); } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheRepository.java index d1930bac79d0..1cbd4d0d6824 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheRepository.java @@ -24,7 +24,9 @@ import org.apache.maven.caching.xml.Build; import org.apache.maven.execution.MavenSession; +import javax.annotation.Nonnull; import java.io.IOException; +import java.util.Optional; /** * Cache repository. @@ -32,7 +34,8 @@ public interface CacheRepository { - Build findBuild( CacheContext context ) throws IOException; + @Nonnull + Optional findBuild( CacheContext context ) throws IOException; void saveBuildInfo( CacheResult cacheResult, Build build ) throws IOException; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java index 23229e9fefc5..9530ea4377c9 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java @@ -27,6 +27,7 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; +import javax.annotation.Nonnull; import javax.inject.Inject; import javax.inject.Named; @@ -51,6 +52,8 @@ import org.apache.maven.caching.xml.report.ProjectReport; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Configurable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -93,21 +96,18 @@ private static CloseableHttpClient newHttpClient() return HttpClientBuilder.create().setDefaultRequestConfig( config ).build(); } + @Nonnull @Override - public Build findBuild( CacheContext context ) + public Optional findBuild( CacheContext context ) { final String resourceUrl = getResourceUrl( context, BUILDINFO_XML ); - final byte[] bytes = getResourceContent( resourceUrl ); - if ( bytes != null ) - { - final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( bytes ); - return new Build( dto, CacheSource.REMOTE ); - } - return null; + return getResourceContent( resourceUrl ) + .map( content -> new Build( xmlService.loadBuild( content ), CacheSource.REMOTE ) ); } + @Nonnull @Override - public byte[] getArtifactContent( CacheContext context, Artifact artifact ) + public Optional getArtifactContent( CacheContext context, Artifact artifact ) { return getResourceContent( getResourceUrl( context, artifact.getFileName() ) ); } @@ -149,23 +149,23 @@ public void saveArtifactFile( CacheResult cacheResult, * * @return null or content */ - public byte[] getResourceContent( String url ) + @Nonnull + public Optional getResourceContent( String url ) { - HttpGet get = null; + HttpGet get = new HttpGet( url ); try { - get = new HttpGet( url ); LOGGER.info( "Downloading {}", url ); HttpResponse response = httpClient.get().execute( get ); int statusCode = response.getStatusLine().getStatusCode(); if ( statusCode != HttpStatus.SC_OK ) { LOGGER.info( "Cannot download {}, status code: {}", url, statusCode ); - return null; + return Optional.empty(); } try ( InputStream content = response.getEntity().getContent() ) { - return IOUtils.toByteArray( content ); + return Optional.of( IOUtils.toByteArray( content ) ); } } catch ( IOException e ) @@ -174,13 +174,11 @@ public byte[] getResourceContent( String url ) } finally { - if ( get != null ) - { - get.releaseConnection(); - } + get.releaseConnection(); } } + @Nonnull @Override public String getResourceUrl( CacheContext context, String filename ) { @@ -199,10 +197,9 @@ private String getResourceUrl( String filename, String groupId, String artifactI */ private void putToRemoteCache( InputStream instream, String url ) throws IOException { - HttpPut httpPut = null; + HttpPut httpPut = new HttpPut( url );; try { - httpPut = new HttpPut( url ); httpPut.setEntity( new InputStreamEntity( instream ) ); HttpResponse response = httpClient.get().execute( httpPut ); int statusCode = response.getStatusLine().getStatusCode(); @@ -210,86 +207,70 @@ private void putToRemoteCache( InputStream instream, String url ) throws IOExcep } finally { - if ( httpPut != null ) - { - httpPut.releaseConnection(); - } + httpPut.releaseConnection(); } } private final AtomicReference> cacheReportSupplier = new AtomicReference<>(); + @Nonnull @Override public Optional findBaselineBuild( MavenProject project ) { final Optional> cachedProjectsHolder = findCacheInfo() .map( CacheReport::getProjects ); + if ( !cachedProjectsHolder.isPresent() ) { return Optional.empty(); } - Optional cachedProjectHolder = Optional.empty(); - for ( ProjectReport p : cachedProjectsHolder.get() ) + final List projects = cachedProjectsHolder.get(); + final Optional projectReportHolder = projects.stream().filter( p -> + project.getArtifactId().equals( p.getArtifactId() ) + && project.getGroupId().equals( p.getGroupId() ) ).findFirst(); + + if ( !projectReportHolder.isPresent() ) { - if ( project.getArtifactId().equals( p.getArtifactId() ) - && project.getGroupId().equals( p.getGroupId() ) ) - { - cachedProjectHolder = Optional.of( p ); - break; - } + return Optional.empty(); } - - if ( cachedProjectHolder.isPresent() ) + + final ProjectReport projectReport = projectReportHolder.get(); + + String url; + if ( projectReport.getUrl() != null ) { - String url; - final ProjectReport projectReport = cachedProjectHolder.get(); - if ( projectReport.getUrl() != null ) - { - url = cachedProjectHolder.get().getUrl(); - LOGGER.info( "Retrieving baseline buildinfo: {}", projectReport.getUrl() ); - } - else - { - url = getResourceUrl( BUILDINFO_XML, project.getGroupId(), - project.getArtifactId(), projectReport.getChecksum() ); - LOGGER.info( "Baseline project record doesn't have url, trying default location" ); - } + url = projectReport.getUrl(); + LOGGER.info( "Retrieving baseline buildinfo: {}", url ); + } + else + { + url = getResourceUrl( BUILDINFO_XML, project.getGroupId(), + project.getArtifactId(), projectReport.getChecksum() ); + LOGGER.info( "Baseline project record doesn't have url, trying default location {}", url ); + } - try - { - byte[] content = getResourceContent( url ); - if ( content != null ) - { - final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( content ); - return Optional.of( new Build( dto, CacheSource.REMOTE ) ); - } - else - { - LOGGER.info( "Project buildinfo not found, skipping diff" ); - } - } - catch ( Exception e ) - { - LOGGER.warn( "Error restoring baseline build at url: {}, skipping diff", - projectReport.getUrl() ); - return Optional.empty(); - } + try + { + return getResourceContent( url ) + .map( content -> new Build( xmlService.loadBuild( content ), CacheSource.REMOTE ) ); + } + catch ( Exception e ) + { + LOGGER.warn( "Error restoring baseline build at url: {}, skipping diff", url, e ); + return Optional.empty(); } - return Optional.empty(); } private Optional findCacheInfo() { Optional report = cacheReportSupplier.get(); - if ( report == null ) + if ( !report.isPresent() ) { try { LOGGER.info( "Downloading baseline cache report from: {}", cacheConfig.getBaselineCacheUrl() ); - byte[] content = getResourceContent( cacheConfig.getBaselineCacheUrl() ); - CacheReport cacheReportType = xmlService.loadCacheReport( content ); - report = Optional.of( cacheReportType ); + report = getResourceContent( cacheConfig.getBaselineCacheUrl() ).map( xmlService::loadCacheReport ); } catch ( Exception e ) { diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepository.java index c2b55d42ab60..48f48038d9a1 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepository.java @@ -29,6 +29,8 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; +import javax.annotation.Nonnull; + /** * Local cache repository. */ @@ -41,7 +43,9 @@ public interface LocalCacheRepository extends CacheRepository void clearCache( CacheContext context ); + @Nonnull Optional findBestMatchingBuild( MavenSession session, Dependency dependency ) throws IOException; - Build findLocalBuild( CacheContext context ) throws IOException; + @Nonnull + Optional findLocalBuild( CacheContext context ) throws IOException; } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java index b24c7c748143..2ebee18132dc 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.DirectoryStream; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; @@ -40,6 +41,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; +import javax.annotation.Nonnull; import javax.inject.Inject; import javax.inject.Named; @@ -56,6 +58,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; +import org.graalvm.compiler.nodes.calc.IntegerDivRemNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -103,8 +106,9 @@ public LocalCacheRepositoryImpl( this.cacheConfig = cacheConfig; } + @Nonnull @Override - public Build findLocalBuild( CacheContext context ) throws IOException + public Optional findLocalBuild( CacheContext context ) throws IOException { Path localBuildInfoPath = localBuildPath( context, BUILDINFO_XML, false ); LOGGER.debug( "Checking local build info: {}", localBuildInfoPath ); @@ -114,7 +118,7 @@ public Build findLocalBuild( CacheContext context ) throws IOException try { org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( localBuildInfoPath.toFile() ); - return new Build( dto, CacheSource.LOCAL ); + return Optional.of( new Build( dto, CacheSource.LOCAL ) ); } catch ( Exception e ) { @@ -122,11 +126,12 @@ public Build findLocalBuild( CacheContext context ) throws IOException Files.delete( localBuildInfoPath ); } } - return null; + return Optional.empty(); } + @Nonnull @Override - public Build findBuild( CacheContext context ) throws IOException + public Optional findBuild( CacheContext context ) throws IOException { Path buildInfoPath = remoteBuildPath( context, BUILDINFO_XML ); LOGGER.debug( "Checking if build is already downloaded: {}", buildInfoPath ); @@ -137,7 +142,7 @@ public Build findBuild( CacheContext context ) throws IOException try { org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( buildInfoPath.toFile() ); - return new Build( dto, CacheSource.REMOTE ); + return Optional.of( new Build( dto, CacheSource.REMOTE ) ); } catch ( Exception e ) { @@ -148,7 +153,7 @@ public Build findBuild( CacheContext context ) throws IOException if ( !cacheConfig.isRemoteCacheEnabled() ) { - return null; + return Optional.empty(); } try @@ -165,26 +170,26 @@ public Build findBuild( CacheContext context ) throws IOException if ( now < created + ONE_HOUR_MILLIS && now < lastModified + ONE_MINUTE_MILLIS ) { // fresh file, allow lookup every minute LOGGER.info( "Skipping remote lookup, last unsuccessful lookup less than 1m ago." ); - return null; + return Optional.empty(); } else if ( now < created + ONE_DAY_MILLIS && now < lastModified + ONE_HOUR_MILLIS ) { // less than 1 day file, allow 1 per hour lookup LOGGER.info( "Skipping remote lookup, last unsuccessful lookup less than 1h ago." ); - return null; + return Optional.empty(); } else if ( now > created + ONE_DAY_MILLIS && now < lastModified + ONE_DAY_MILLIS ) { // more than 1 day file, allow 1 per day lookup LOGGER.info( "Skipping remote lookup, last unsuccessful lookup less than 1d ago." ); - return null; + return Optional.empty(); } } - final Build build = remoteRepository.findBuild( context ); - if ( build != null ) + final Optional build = remoteRepository.findBuild( context ); + if ( build.isPresent() ) { LOGGER.info( "Build info downloaded from remote repo, saving to: {}", buildInfoPath ); Files.createDirectories( buildInfoPath.getParent() ); - Files.write( buildInfoPath, xmlService.toBytes( build.getDto() ), CREATE_NEW ); + Files.write( buildInfoPath, xmlService.toBytes( build.get().getDto() ), CREATE_NEW ); } else { @@ -195,7 +200,7 @@ else if ( now > created + ONE_DAY_MILLIS && now < lastModified + ONE_DAY_MILLIS catch ( Exception e ) { LOGGER.error( "Remote build info is not valid, cached data is not compatible", e ); - return null; + return Optional.empty(); } } @@ -213,11 +218,14 @@ public void clearCache( CacheContext context ) } List cacheDirs = new ArrayList<>(); - for ( Path dir : Files.newDirectoryStream( artifactCacheDir ) ) + try ( final DirectoryStream paths = Files.newDirectoryStream( artifactCacheDir ) ) { - if ( Files.isDirectory( dir ) ) + for ( Path dir : paths ) { - cacheDirs.add( dir ); + if ( Files.isDirectory( dir ) ) + { + cacheDirs.add( dir ); + } } } int maxLocalBuildsCached = cacheConfig.getMaxLocalBuildsCached() - 1; @@ -244,6 +252,7 @@ public void clearCache( CacheContext context ) } } + @Nonnull @Override public Optional findBestMatchingBuild( MavenSession session, Dependency dependency ) @@ -251,6 +260,7 @@ public Optional findBestMatchingBuild( return bestBuildCache.computeIfAbsent( Pair.of( session, dependency ), this::findBestMatchingBuildImpl ); } + @Nonnull private Optional findBestMatchingBuildImpl( Pair dependencySession ) { @@ -364,10 +374,10 @@ public Path getArtifactFile( CacheContext context, CacheSource source, Artifact Path cachePath = remoteBuildPath( context, artifact.getFileName() ); if ( !Files.exists( cachePath ) && cacheConfig.isRemoteCacheEnabled() ) { - final byte[] artifactContent = remoteRepository.getArtifactContent( context, artifact ); - if ( artifactContent != null ) + final Optional artifactContent = remoteRepository.getArtifactContent( context, artifact ); + if ( artifactContent.isPresent() ) { - Files.write( cachePath, artifactContent, CREATE_NEW ); + Files.write( cachePath, artifactContent.get(), CREATE_NEW ); } } return cachePath; diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java index c09f71193ecf..cc4cc135d3fa 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java @@ -26,17 +26,23 @@ import org.apache.maven.caching.xml.build.Artifact; import org.apache.maven.project.MavenProject; +import javax.annotation.Nonnull; + /** * Remote cache repository. */ public interface RemoteCacheRepository extends CacheRepository { - byte[] getArtifactContent( CacheContext context, Artifact artifact ) throws IOException; + @Nonnull + Optional getArtifactContent( CacheContext context, Artifact artifact ) throws IOException; - byte[] getResourceContent( String resourceUrl ); + @Nonnull + Optional getResourceContent( String resourceUrl ); + @Nonnull String getResourceUrl( CacheContext context, String filename ); + @Nonnull Optional findBaselineBuild( MavenProject project ); } From 8b3b955ea4f24f68e6d30e4e979ae7341e0bbb6b Mon Sep 17 00:00:00 2001 From: Alexander Ashitkin Date: Tue, 23 Nov 2021 13:54:52 -0500 Subject: [PATCH 163/188] [MNG-7129] Rework http repo to java 8 --- .../org/apache/maven/caching/HttpCacheRepositoryImpl.java | 6 ++---- .../org/apache/maven/caching/LocalCacheRepositoryImpl.java | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java index 9530ea4377c9..4d2c1bea331a 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java @@ -52,8 +52,6 @@ import org.apache.maven.caching.xml.report.ProjectReport; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Configurable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -197,7 +195,7 @@ private String getResourceUrl( String filename, String groupId, String artifactI */ private void putToRemoteCache( InputStream instream, String url ) throws IOException { - HttpPut httpPut = new HttpPut( url );; + HttpPut httpPut = new HttpPut( url ); try { httpPut.setEntity( new InputStreamEntity( instream ) ); @@ -217,7 +215,7 @@ private void putToRemoteCache( InputStream instream, String url ) throws IOExcep @Override public Optional findBaselineBuild( MavenProject project ) { - final Optional> cachedProjectsHolder = findCacheInfo() + Optional> cachedProjectsHolder = findCacheInfo() .map( CacheReport::getProjects ); if ( !cachedProjectsHolder.isPresent() ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java index 2ebee18132dc..937f48a588a6 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java @@ -58,7 +58,6 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; -import org.graalvm.compiler.nodes.calc.IntegerDivRemNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -218,7 +217,7 @@ public void clearCache( CacheContext context ) } List cacheDirs = new ArrayList<>(); - try ( final DirectoryStream paths = Files.newDirectoryStream( artifactCacheDir ) ) + try ( DirectoryStream paths = Files.newDirectoryStream( artifactCacheDir ) ) { for ( Path dir : paths ) { From e4a05db758456fb937a4c4fe4f21d2c6e5053f3a Mon Sep 17 00:00:00 2001 From: Andrey Petrenko Date: Thu, 25 Nov 2021 02:43:07 +0300 Subject: [PATCH 164/188] MNG-7129: caching extension --- .../maven/caching/CacheControllerImpl.java | 197 ++++++++++----- .../org/apache/maven/caching/CacheUtils.java | 3 +- .../caching/DefaultMultiModuleSupport.java | 202 ++++++++++++++++ .../DefaultNormalizedModelProvider.java | 181 ++++++++++++++ .../DefaultProjectInputCalculator.java | 127 ++++++++++ ...lStrategy.java => MultiModuleSupport.java} | 31 +-- .../caching/NormalizedModelProvider.java | 40 +++ ...ategy.java => ProjectInputCalculator.java} | 14 +- .../maven/caching/checksum/KeyUtils.java | 36 ++- .../caching/checksum/MavenProjectInput.java | 228 ++++-------------- .../apache/maven/caching/xml/CacheConfig.java | 4 - .../maven/caching/xml/CacheConfigImpl.java | 16 -- .../caching/xml/SentinelVersionStrategy.java | 51 ---- maven-caching/src/main/mdo/cache-config.mdo | 19 -- 14 files changed, 774 insertions(+), 375 deletions(-) create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/DefaultMultiModuleSupport.java create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/DefaultNormalizedModelProvider.java create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/DefaultProjectInputCalculator.java rename maven-caching/src/main/java/org/apache/maven/caching/{xml/AllExternalStrategy.java => MultiModuleSupport.java} (61%) create mode 100644 maven-caching/src/main/java/org/apache/maven/caching/NormalizedModelProvider.java rename maven-caching/src/main/java/org/apache/maven/caching/{checksum/MultimoduleDiscoveryStrategy.java => ProjectInputCalculator.java} (71%) delete mode 100644 maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStrategy.java diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java index 49527d69b138..02072d784b90 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java @@ -19,9 +19,12 @@ * under the License. */ +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.FileVisitResult; import java.nio.file.Files; @@ -31,6 +34,7 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Collections; +import java.util.Enumeration; import java.util.List; import java.util.Map; import java.util.Objects; @@ -42,9 +46,11 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; -import java.util.function.Function; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.JarOutputStream; import java.util.regex.Pattern; -import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.inject.Inject; @@ -52,14 +58,13 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.mutable.MutableBoolean; import org.apache.maven.SessionScoped; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.caching.artifact.RestoredArtifact; -import org.apache.maven.caching.checksum.KeyUtils; -import org.apache.maven.caching.checksum.MavenProjectInput; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.xml.Build; @@ -79,7 +84,6 @@ import org.apache.maven.caching.xml.report.ProjectReport; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MojoExecutionEvent; -import org.apache.maven.lifecycle.internal.builder.BuilderCommon; import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.descriptor.Parameter; @@ -122,16 +126,15 @@ public class CacheControllerImpl implements CacheController private static final Logger LOGGER = LoggerFactory.getLogger( CacheControllerImpl.class ); private final MavenProjectHelper projectHelper; - private final RepositorySystem repoSystem; private final ArtifactHandlerManager artifactHandlerManager; private final XmlService xmlService; private final CacheConfig cacheConfig; private final LocalCacheRepository localCache; private final RemoteCacheRepository remoteCache; - private final ConcurrentMap artifactDigestByKey = new ConcurrentHashMap<>(); private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); private final LifecyclePhasesHelper lifecyclePhasesHelper; private volatile Map projectIndex; + private final ProjectInputCalculator projectInputCalculator; private volatile Scm scm; @Inject @@ -143,6 +146,7 @@ public CacheControllerImpl( LocalCacheRepository localCache, RemoteCacheRepository remoteCache, CacheConfig cacheConfig, + ProjectInputCalculator projectInputCalculator, LifecyclePhasesHelper lifecyclePhasesHelper, MavenSession session ) { @@ -150,10 +154,10 @@ public CacheControllerImpl( this.localCache = localCache; this.remoteCache = remoteCache; this.cacheConfig = cacheConfig; - this.repoSystem = repoSystem; this.artifactHandlerManager = artifactHandlerManager; this.xmlService = xmlService; this.lifecyclePhasesHelper = lifecyclePhasesHelper; + this.projectInputCalculator = projectInputCalculator; } @Override @@ -169,7 +173,7 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, LOGGER.info( "Attempting to restore project from build cache" ); - ProjectsInputInfo inputInfo = calculateInput( project, session ); + ProjectsInputInfo inputInfo = projectInputCalculator.calculateInput( project ); final CacheContext context = new CacheContext( project, inputInfo, session ); // remote build first @@ -185,6 +189,10 @@ public CacheResult findCachedBuild( MavenSession session, MavenProject project, { result = localBuild; } + else + { + LOGGER.info( "Local build was not found by checksum " + inputInfo.getChecksum() ); + } } cacheResults.put( getVersionlessProjectKey( project ), result ); @@ -311,17 +319,23 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) if ( build.getArtifact() != null && isNotBlank( build.getArtifact().getFileName() ) ) { final Artifact artifactInfo = build.getArtifact(); + String originalVersion = artifactInfo.getVersion(); artifactInfo.setVersion( project.getVersion() ); // TODO if remote is forced, probably need to refresh or reconcile all files - final Future downloadTask = createDownloadTask( cacheResult, context, project, artifactInfo ); + final Future downloadTask = createDownloadTask( + cacheResult, + context, + project, + artifactInfo, + originalVersion ); restoredProjectArtifact = restoredArtifact( project.getArtifact(), artifactInfo.getType(), artifactInfo.getClassifier(), downloadTask ); - putChecksum( artifactInfo, context.getInputInfo().getChecksum() ); } for ( Artifact attachedArtifactInfo : build.getAttachedArtifacts() ) { + String originalVersion = attachedArtifactInfo.getVersion(); attachedArtifactInfo.setVersion( project.getVersion() ); if ( isNotBlank( attachedArtifactInfo.getFileName() ) ) { @@ -340,7 +354,13 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) else { Future downloadTask = - createDownloadTask( cacheResult, context, project, attachedArtifactInfo ); + createDownloadTask( + cacheResult, + context, + project, + attachedArtifactInfo, + originalVersion + ); final RestoredArtifact restoredAttachedArtifact = restoredArtifact( restoredProjectArtifact == null ? project.getArtifact() : restoredProjectArtifact, @@ -349,7 +369,6 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) downloadTask ); restoredAttachedArtifacts.add( restoredAttachedArtifact ); } - putChecksum( attachedArtifactInfo, context.getInputInfo().getChecksum() ); } } // Actually modify project at the end in case something went wrong during restoration, @@ -358,7 +377,7 @@ public boolean restoreProjectArtifacts( CacheResult cacheResult ) { project.setArtifact( restoredProjectArtifact ); } - restoredAttachedArtifacts.forEach( a -> project.addAttachedArtifact( a ) ); + restoredAttachedArtifacts.forEach( project::addAttachedArtifact ); return true; } catch ( Exception e ) @@ -396,10 +415,109 @@ private RestoredArtifact restoredArtifact( org.apache.maven.artifact.Artifact pa return artifact; } + //we might store in cache artifact which was build with previous version + //1.0-SNAPSHOT is kept in cache but real version of project is 2.0 + //for pom packaging this is done automatically by maven but for jar and other there might be + //sensitive metadata with previous version. Versions mismatch could lead errors + private Path adjustArchiveArtifactVersion( MavenProject project, String originalArtifactVersion, Path artifactFile ) + throws IOException + { + + File file = artifactFile.toFile(); + if ( project.getVersion().equals( originalArtifactVersion ) || !isArchive( file ) ) + { + return artifactFile; + } + + String currentVersion = project.getVersion(); + File tmpJarFile = File.createTempFile( artifactFile.toFile().getName(), + '.' + FilenameUtils.getExtension( file.getName() ) ); + tmpJarFile.deleteOnExit(); + String originalImplVersion = Attributes.Name.IMPLEMENTATION_VERSION + ": " + originalArtifactVersion; + String implVersion = Attributes.Name.IMPLEMENTATION_VERSION + ": " + currentVersion; + String commonXmlOriginalVersion = "" + originalArtifactVersion + ""; + String commonXmlVersion = "" + currentVersion + ""; + String originalPomPropsVersion = "version=" + originalArtifactVersion; + String pomPropsVersion = "version=" + currentVersion; + try ( JarFile jarFile = new JarFile( artifactFile.toFile() ) ) + { + try ( JarOutputStream jos = new JarOutputStream( + new BufferedOutputStream( new FileOutputStream( tmpJarFile ) ) ) ) + { + //Copy original jar file to the temporary one. + Enumeration jarEntries = jarFile.entries(); + byte[] buffer = new byte[1024]; + while ( jarEntries.hasMoreElements() ) + { + JarEntry entry = jarEntries.nextElement(); + String entryName = entry.getName(); + + if ( entryName.startsWith( "META-INF/maven" ) + && ( entryName.endsWith( "plugin.xml" ) || entryName.endsWith( "plugin-help.xml" ) ) ) + { + replaceEntry( jarFile, entry, commonXmlOriginalVersion, commonXmlVersion, jos ); + continue; + } + + if ( entryName.endsWith( "pom.xml" ) ) + { + replaceEntry( jarFile, entry, commonXmlOriginalVersion, commonXmlVersion, jos ); + continue; + } + + if ( entryName.endsWith( "pom.properties" ) ) + { + replaceEntry( jarFile, entry, originalPomPropsVersion, pomPropsVersion, jos ); + continue; + } + + if ( JarFile.MANIFEST_NAME.equals( entryName ) ) + { + replaceEntry( jarFile, entry, originalImplVersion, implVersion, jos ); + continue; + } + jos.putNextEntry( entry ); + try ( InputStream entryInputStream = jarFile.getInputStream( entry ) ) + { + int bytesRead; + while ( ( bytesRead = entryInputStream.read( buffer ) ) != -1 ) + { + jos.write( buffer, 0, bytesRead ); + } + } + } + } + } + return tmpJarFile.toPath(); + } + + private static void replaceEntry( JarFile jarFile, JarEntry entry, + String toReplace, String replacement, JarOutputStream jos ) throws IOException + { + String fullManifest = IOUtils.toString( jarFile.getInputStream( entry ), StandardCharsets.UTF_8 ); + String modified = fullManifest.replaceAll( toReplace, replacement ); + + byte[] bytes = modified.getBytes( StandardCharsets.UTF_8 ); + JarEntry newEntry = new JarEntry( entry.getName() ); + jos.putNextEntry( newEntry ); + jos.write( bytes ); + } + + private static boolean isArchive( File file ) + { + String fileName = file.getName(); + if ( !file.isFile() || file.isHidden() ) + { + return false; + } + return fileName.endsWith( ".jar" ) || fileName.endsWith( ".zip" ) + || fileName.endsWith( ".war" ) || fileName.endsWith( ".ear" ); + } + private Future createDownloadTask( CacheResult cacheResult, CacheContext context, MavenProject project, - Artifact artifact ) + Artifact artifact, String originalVersion ) { - final FutureTask downloadTask = new FutureTask<>( () -> + final FutureTask downloadTask = new FutureTask<>( () -> { try { @@ -412,7 +530,7 @@ private Future createDownloadTask( CacheResult cacheResult, CacheContext c "Missing file for cached build, cannot restore. File: " + artifactFile ); } LOGGER.debug( "Downloaded artifact " + artifact.getArtifactId() + " to: " + artifactFile ); - return artifactFile.toFile(); + return adjustArchiveArtifactVersion( project, originalVersion, artifactFile ).toFile(); } catch ( IOException e ) { @@ -426,44 +544,6 @@ private Future createDownloadTask( CacheResult cacheResult, CacheContext c return downloadTask; } - private void putChecksum( Artifact artifact, String projectChecksum ) - { - final DigestItem projectArtifact = DtoUtils.createdDigestedByProjectChecksum( artifact, projectChecksum ); - final String dependencyKey = KeyUtils.getArtifactKey( artifact ); - artifactDigestByKey.put( dependencyKey, projectArtifact ); - - final ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() ); - String packaging = artifactHandler.getPackaging(); - if ( !Objects.equals( packaging, artifact.getType() ) ) - { - artifactDigestByKey.put( KeyUtils.getArtifactKey( artifact, packaging ), projectArtifact ); - } - String extension = artifactHandler.getExtension(); - if ( !Objects.equals( extension, artifact.getType() ) && !Objects.equals( extension, packaging ) ) - { - artifactDigestByKey.put( KeyUtils.getArtifactKey( artifact, extension ), projectArtifact ); - } - } - - private ProjectsInputInfo calculateInput( MavenProject project, MavenSession session ) - { - try - { - if ( projectIndex == null ) - { - projectIndex = session.getProjects().stream() - .collect( Collectors.toMap( BuilderCommon::getKey, Function.identity() ) ); - } - final MavenProjectInput inputs = new MavenProjectInput( project, projectIndex, session, cacheConfig, - artifactDigestByKey, repoSystem, localCache, remoteCache ); - return inputs.calculateChecksum(); - } - catch ( Exception e ) - { - throw new RuntimeException( "Failed to calculate checksums for " + project.getArtifactId(), e ); - } - } - @Override public void save( CacheResult cacheResult, List mojoExecutions, Map executionEvents ) @@ -518,7 +598,6 @@ public void save( CacheResult cacheResult, List mojoExecutions, if ( projectArtifact.getFile() != null ) { localCache.saveArtifactFile( cacheResult, projectArtifact ); - putChecksum( projectArtifactDto, context.getInputInfo().getChecksum() ); } for ( org.apache.maven.artifact.Artifact attachedArtifact : attachedArtifacts ) { @@ -528,10 +607,6 @@ public void save( CacheResult cacheResult, List mojoExecutions, localCache.saveArtifactFile( cacheResult, attachedArtifact ); } } - for ( Artifact attachedArtifactDto : attachedArtifactDtos ) - { - putChecksum( attachedArtifactDto, context.getInputInfo().getChecksum() ); - } } else { @@ -591,7 +666,7 @@ public void produceDiffReport( CacheResult cacheResult, Build build ) if ( baselinePom.isPresent() ) { Files.write( reportOutputDir.resolve( - "effective-pom-baseline-" + baselineInputs.getChecksum() + ".xml" ), + "effective-pom-baseline-" + baselineInputs.getChecksum() + ".xml" ), baselinePom.get().getValue().getBytes( StandardCharsets.UTF_8 ), TRUNCATE_EXISTING, CREATE ); } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java index feac5df68e9a..7d42d43de6e9 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java @@ -100,8 +100,7 @@ public static String mojoExecutionKey( MojoExecution mojo ) StringUtils.defaultIfEmpty( mojo.getGoal(), "emptyGoal" ), StringUtils.defaultIfEmpty( mojo.getLifecyclePhase(), "emptyLifecyclePhase" ), StringUtils.defaultIfEmpty( mojo.getArtifactId(), "emptyArtifactId" ), - StringUtils.defaultIfEmpty( mojo.getGroupId(), "emptyGroupId" ), - StringUtils.defaultIfEmpty( mojo.getVersion(), "emptyVersion" ) ), ":" ); + StringUtils.defaultIfEmpty( mojo.getGroupId(), "emptyGroupId" ) ), ":" ); } public static Path getMultimoduleRoot( MavenSession session ) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/DefaultMultiModuleSupport.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultMultiModuleSupport.java new file mode 100644 index 000000000000..d4c6b56365f6 --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/DefaultMultiModuleSupport.java @@ -0,0 +1,202 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.SessionScoped; +import org.apache.maven.caching.checksum.KeyUtils; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.project.DefaultProjectBuildingRequest; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.project.ProjectBuildingResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import javax.inject.Named; +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Properties; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +@SessionScoped +@Named +public class DefaultMultiModuleSupport implements MultiModuleSupport +{ + + private static final Logger LOGGER = LoggerFactory.getLogger( DefaultMultiModuleSupport.class ); + + private final ProjectBuilder projectBuilder; + private final MavenSession session; + + private volatile boolean built; + private volatile Map projectMap; + private volatile Map sessionProjectMap; + + @Inject + public DefaultMultiModuleSupport( ProjectBuilder projectBuilder, MavenSession session ) + { + this.projectBuilder = projectBuilder; + this.session = session; + } + + @Override + public boolean isPartOfSession( String groupId, String artifactId, String version ) + { + return getProjectMap( session ) + .containsKey( KeyUtils.getProjectKey( groupId, artifactId, version ) ); + } + + @Override + public Optional tryToResolveProject( String groupId, String artifactId, String version ) + { + return Optional.ofNullable( getMultiModuleProjectsMap() + .get( KeyUtils.getProjectKey( groupId, artifactId, version ) ) ); + } + + @Override + public boolean isPartOfMultiModule( String groupId, String artifactId, String version ) + { + String projectKey = KeyUtils.getProjectKey( groupId, artifactId, version ); + return getProjectMap( session ).containsKey( projectKey ) + || getMultiModuleProjectsMap().containsKey( projectKey ); + } + + private Map getProjectMap( MavenSession session ) + { + if ( sessionProjectMap != null ) + { + return sessionProjectMap; + } + sessionProjectMap = session.getProjects().stream().collect( Collectors.toMap( + KeyUtils::getProjectKey, + Function.identity() + ) ); + return sessionProjectMap; + } + + private Map getMultiModuleProjectsMap() + { + if ( projectMap != null ) + { + return projectMap; + } + return getMultiModuleProjectsMapInner( session ); + } + + private synchronized Map getMultiModuleProjectsMapInner( MavenSession session ) + { + if ( projectMap != null ) + { + return projectMap; + } + buildModel( session ); + return projectMap; + } + + private synchronized void buildModel( MavenSession session ) + { + if ( built ) + { + return; + } + //TODO: re-work hardcode + Set scanProfiles = Collections.singleton( "abfx-all" ); + MavenProject currentProject = session.getCurrentProject(); + File multiModulePomFile = getMultiModulePomFile( session ); + + ProjectBuildingRequest projectBuildingRequest = currentProject.getProjectBuildingRequest(); + boolean profilesMatched = projectBuildingRequest.getActiveProfileIds().containsAll( scanProfiles ); + + if ( currentProject.getFile().getAbsolutePath().equals( multiModulePomFile.getAbsolutePath() ) + && profilesMatched ) + { + projectMap = buildProjectMap( session.getProjects() ); + return; + } + + long t0 = System.currentTimeMillis(); + + ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest( projectBuildingRequest ); + //clear properties because after first build request some properties could be set to profiles + //these properties could change effective pom when we try to rebuild whole multi module project again + //for example the first model build process do not resolve ${os.detected.classifier} + //but once build completed this property is set to profile + //if we try to rebuild model for the whole project here string interpolator replaces this value + //and effective pom could be different (depending on OS) if this property is used in pom.xml + buildingRequest.setProfiles( + buildingRequest.getProfiles().stream() + .peek( it -> it.setProperties( new Properties() ) ) + .collect( Collectors.toList() ) + ); + if ( !profilesMatched ) + { + Set profiles = new LinkedHashSet<>( buildingRequest.getActiveProfileIds() ); + //remove duplicates + profiles.addAll( scanProfiles ); + buildingRequest.setActiveProfileIds( new ArrayList<>( profiles ) ); + } + try + { + List buildingResults = projectBuilder.build( + Collections.singletonList( multiModulePomFile ), + true, + buildingRequest + ); + LOGGER.info( "Multi module project model calculated [activeProfiles={}, time={} ms ", + buildingRequest.getActiveProfileIds(), System.currentTimeMillis() - t0 ); + + List projectList = buildingResults.stream().map( ProjectBuildingResult::getProject ) + .collect( Collectors.toList() ); + projectMap = buildProjectMap( projectList ); + + } + catch ( ProjectBuildingException e ) + { + LOGGER.error( "Unable to build model", e ); + } + finally + { + built = true; + } + } + + private Map buildProjectMap( List projectList ) + { + return projectList.stream().collect( Collectors.toMap( + KeyUtils::getProjectKey, + Function.identity() + ) ); + } + + private static File getMultiModulePomFile( MavenSession session ) + { + return new File( session.getRequest().getMultiModuleProjectDirectory() + "/pom.xml" ); + } +} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/DefaultNormalizedModelProvider.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultNormalizedModelProvider.java new file mode 100644 index 000000000000..702524075379 --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/DefaultNormalizedModelProvider.java @@ -0,0 +1,181 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.SessionScoped; +import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.lifecycle.internal.builder.BuilderCommon; +import org.apache.maven.model.Build; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +import javax.inject.Inject; +import javax.inject.Named; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.stream.Collectors; + +@SessionScoped +@Named +public class DefaultNormalizedModelProvider implements NormalizedModelProvider +{ + private static final String NORMALIZED_VERSION = "cache-extension-version"; + + private final CacheConfig cacheConfig; + private final MultiModuleSupport multiModuleSupport; + //private final MultiModuleSupport multiModuleSupport; + private final ConcurrentMap modelCache = new ConcurrentHashMap<>(); + + @Inject + public DefaultNormalizedModelProvider( MultiModuleSupport multiModuleSupport, CacheConfig cacheConfig ) + { + this.multiModuleSupport = multiModuleSupport; + this.cacheConfig = cacheConfig; + } + + @Override + public Model normalizedModel( MavenProject project ) + { + MavenProject validatedProject = Objects.requireNonNull( project, "project" ); + return modelCache.computeIfAbsent( BuilderCommon.getKey( validatedProject ), + k -> normalizedModelInner( validatedProject ) ); + } + + private Model normalizedModelInner( MavenProject project ) + { + //prefer project from multimodule than reactor because effective pom of reactor project + //could be built with maven local/remote dependencies but not with artifacts from cache + MavenProject projectToNormalize = multiModuleSupport.tryToResolveProject( + project.getGroupId(), + project.getArtifactId(), + project.getVersion() ) + .orElse( project ); + Model prototype = projectToNormalize.getModel(); + + //TODO validate status of the model - it should be in resolved state + Model resultModel = new Model(); + + resultModel.setGroupId( prototype.getGroupId() ); + resultModel.setArtifactId( prototype.getArtifactId() ); + //does not make sense to add project version to calculate hash + resultModel.setVersion( NORMALIZED_VERSION ); + resultModel.setModules( prototype.getModules() ); + + resultModel.setDependencies( normalizeDependencies( prototype.getDependencies() ) ); + + org.apache.maven.model.Build protoBuild = prototype.getBuild(); + if ( protoBuild == null ) + { + return resultModel; + } + + Build build = new Build(); + List plugins = prototype.getBuild().getPlugins(); + build.setPlugins( normalizePlugins( plugins ) ); + resultModel.setBuild( build ); + return resultModel; + } + + private List normalizeDependencies( Collection source ) + { + return source.stream().map( it -> + { + if ( !multiModuleSupport.isPartOfMultiModule( it.getGroupId(), it.getArtifactId(), it.getVersion() ) ) + { + return it; + } + Dependency cloned = it.clone(); + cloned.setVersion( NORMALIZED_VERSION ); + return cloned; + } ).sorted( DefaultNormalizedModelProvider::compareDependencies ).collect( Collectors.toList() ); + } + + private List normalizePlugins( List plugins ) + { + if ( plugins.isEmpty() ) + { + return plugins; + } + + return plugins.stream().map( + plugin -> + { + Plugin copy = plugin.clone(); + List excludeProperties = cacheConfig.getEffectivePomExcludeProperties( copy ); + removeBlacklistedAttributes( (Xpp3Dom) copy.getConfiguration(), excludeProperties ); + for ( PluginExecution execution : copy.getExecutions() ) + { + Xpp3Dom config = (Xpp3Dom) execution.getConfiguration(); + removeBlacklistedAttributes( config, excludeProperties ); + } + + copy.setDependencies( + normalizeDependencies( + copy.getDependencies() + .stream() + .sorted( DefaultNormalizedModelProvider::compareDependencies ) + .collect( Collectors.toList() ) + ) + ); + if ( multiModuleSupport.isPartOfMultiModule( + copy.getGroupId(), + copy.getArtifactId(), + copy.getVersion() ) ) + { + copy.setVersion( NORMALIZED_VERSION ); + } + return copy; + } + ).collect( Collectors.toList() ); + } + + private void removeBlacklistedAttributes( Xpp3Dom node, List excludeProperties ) + { + if ( node == null ) + { + return; + } + + Xpp3Dom[] children = node.getChildren(); + int indexToRemove = 0; + for ( Xpp3Dom child : children ) + { + if ( excludeProperties.contains( child.getName() ) ) + { + node.removeChild( indexToRemove ); + continue; + } + indexToRemove++; + removeBlacklistedAttributes( child, excludeProperties ); + } + } + + private static int compareDependencies( Dependency d1, Dependency d2 ) + { + return d1.getArtifactId().compareTo( d2.getArtifactId() ); + } +} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/DefaultProjectInputCalculator.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultProjectInputCalculator.java new file mode 100644 index 000000000000..e9ebbde41a07 --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/DefaultProjectInputCalculator.java @@ -0,0 +1,127 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.SessionScoped; +import org.apache.maven.caching.checksum.MavenProjectInput; +import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.build.ProjectsInputInfo; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.internal.builder.BuilderCommon; +import org.apache.maven.project.MavenProject; +import org.apache.maven.repository.RepositorySystem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import javax.inject.Named; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +@SessionScoped +@Named +public class DefaultProjectInputCalculator implements ProjectInputCalculator +{ + private static final Logger LOGGER = LoggerFactory.getLogger( DefaultProjectInputCalculator.class ); + + private final MavenSession mavenSession; + private final RemoteCacheRepository remoteCache; + private final CacheConfig cacheConfig; + private final RepositorySystem repoSystem; + private final NormalizedModelProvider normalizedModelProvider; + private final MultiModuleSupport multiModuleSupport; + + private final ConcurrentMap checkSumMap = new ConcurrentHashMap<>(); + + private static final ThreadLocal> CURRENTLY_CALCULATING = ThreadLocal.withInitial( + LinkedHashSet::new + ); + + @Inject + public DefaultProjectInputCalculator( MavenSession mavenSession, + RemoteCacheRepository remoteCache, + CacheConfig cacheConfig, + RepositorySystem repoSystem, + NormalizedModelProvider rawModelProvider, + MultiModuleSupport multiModuleSupport ) + { + this.mavenSession = mavenSession; + this.remoteCache = remoteCache; + this.cacheConfig = cacheConfig; + this.repoSystem = repoSystem; + this.normalizedModelProvider = rawModelProvider; + this.multiModuleSupport = multiModuleSupport; + } + + @Override + public ProjectsInputInfo calculateInput( MavenProject project ) + { + LOGGER.info( "Going to calculate checksum for project [groupId=" + project.getGroupId() + + ", artifactId=" + project.getArtifactId() + "]" ); + + String key = BuilderCommon.getKey( project ); + ProjectsInputInfo projectsInputInfo = checkSumMap.get( key ); + if ( projectsInputInfo != null ) + { + return projectsInputInfo; + } + projectsInputInfo = calculateInputInternal( key, project ); + checkSumMap.put( key, projectsInputInfo ); + return projectsInputInfo; + + } + + private ProjectsInputInfo calculateInputInternal( String key, + MavenProject project ) + { + Set projectsSet = CURRENTLY_CALCULATING.get(); + + if ( !projectsSet.add( key ) ) + { + throw new IllegalStateException( "Checksum for project is already calculating. " + + "Is there a cyclic dependencies? [project=" + key + + ", setOfCalculatingProjects=" + projectsSet + "]" ); + } + try + { + final MavenProjectInput input = new MavenProjectInput( + project, + normalizedModelProvider, + multiModuleSupport, + this, + mavenSession, + cacheConfig, + repoSystem, + remoteCache + ); + return input.calculateChecksum(); + } + catch ( Exception e ) + { + throw new RuntimeException( "Failed to calculate checksums for " + project.getArtifactId(), e ); + } + finally + { + projectsSet.remove( key ); + } + } +} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/AllExternalStrategy.java b/maven-caching/src/main/java/org/apache/maven/caching/MultiModuleSupport.java similarity index 61% rename from maven-caching/src/main/java/org/apache/maven/caching/xml/AllExternalStrategy.java rename to maven-caching/src/main/java/org/apache/maven/caching/MultiModuleSupport.java index 97d7691d81a2..3c3c3c138dde 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/AllExternalStrategy.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/MultiModuleSupport.java @@ -1,4 +1,4 @@ -package org.apache.maven.caching.xml; +package org.apache.maven.caching; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -19,24 +19,17 @@ * under the License. */ -import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; -import org.apache.maven.model.Dependency; +import org.apache.maven.project.MavenProject; -/** - * AllExternalStrategy - */ -public class AllExternalStrategy implements MultimoduleDiscoveryStrategy +import java.util.Optional; + +public interface MultiModuleSupport { - @Override - public boolean isPartOfMultiModule( Dependency dependency ) - { - return false; - } - - @Override - public boolean isLookupRemoteMavenRepo( Artifact artifact ) - { - return true; - } + + Optional tryToResolveProject( String groupId, String artifactId, String version ); + + boolean isPartOfMultiModule( String groupId, String artifactId, String version ); + + boolean isPartOfSession( String groupId, String artifactId, String version ); + } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/NormalizedModelProvider.java b/maven-caching/src/main/java/org/apache/maven/caching/NormalizedModelProvider.java new file mode 100644 index 000000000000..45b69b835e77 --- /dev/null +++ b/maven-caching/src/main/java/org/apache/maven/caching/NormalizedModelProvider.java @@ -0,0 +1,40 @@ +package org.apache.maven.caching; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.model.Model; +import org.apache.maven.project.MavenProject; + +/** + * Calculate normalized model for project. The idea is to have model where not all properties resolved. In particular + * ${project....} and ${pom....} replaced to some constant value. This helps to calculate correct checksum when changed + * only project version for example build 1 : 1.0-SNAPSHOT, build 2 : 2.0-SNAPSHOT in this case 2nd build could be + * completely restored from cache. + */ +public interface NormalizedModelProvider +{ + + /** + * @param project - the project which model will be calculated for + * @return normalized model for project + */ + Model normalizedModel( MavenProject project ); + +} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java b/maven-caching/src/main/java/org/apache/maven/caching/ProjectInputCalculator.java similarity index 71% rename from maven-caching/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java rename to maven-caching/src/main/java/org/apache/maven/caching/ProjectInputCalculator.java index b968f7764dca..3697d456eb42 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MultimoduleDiscoveryStrategy.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/ProjectInputCalculator.java @@ -1,4 +1,4 @@ -package org.apache.maven.caching.checksum; +package org.apache.maven.caching; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -19,15 +19,15 @@ * under the License. */ -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Dependency; +import org.apache.maven.caching.xml.build.ProjectsInputInfo; +import org.apache.maven.project.MavenProject; /** - * MultimoduleDiscoveryStrategy + * */ -public interface MultimoduleDiscoveryStrategy +public interface ProjectInputCalculator { - boolean isPartOfMultiModule( Dependency dependency ); - boolean isLookupRemoteMavenRepo( Artifact dependency ); + ProjectsInputInfo calculateInput( MavenProject project ); + } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java index f94ddd11fc85..1be6743f433a 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java @@ -21,7 +21,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.caching.xml.build.Artifact; -import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; /** @@ -34,17 +33,17 @@ public class KeyUtils public static String getProjectKey( MavenProject project ) { - return StringUtils.joinWith( SEPARATOR, project.getGroupId(), project.getArtifactId(), project.getVersion() ); + return getProjectKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ); } - public static String getVersionlessProjectKey( MavenProject project ) + public static String getProjectKey( String groupId, String artifactId, String version ) { - return StringUtils.joinWith( SEPARATOR, project.getGroupId(), project.getArtifactId() ); + return StringUtils.joinWith( SEPARATOR, groupId, artifactId, version ); } - public static String getVersionlessDependencyKey( Dependency dependency ) + public static String getVersionlessProjectKey( MavenProject project ) { - return StringUtils.joinWith( SEPARATOR, dependency.getGroupId(), dependency.getArtifactId() ); + return StringUtils.joinWith( SEPARATOR, project.getGroupId(), project.getArtifactId() ); } public static String getArtifactKey( Artifact artifact ) @@ -53,9 +52,15 @@ public static String getArtifactKey( Artifact artifact ) artifact.getClassifier(), artifact.getVersion() ); } + public static String getVersionlessArtifactKey( org.apache.maven.artifact.Artifact artifact ) + { + return getVersionlessArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), + artifact.getClassifier() ); + } + + /** - * Computes the key for the given artifact, using the given type instead of the one - * defined in the artifact. + * Computes the key for the given artifact, using the given type instead of the one defined in the artifact. */ public static String getArtifactKey( Artifact artifact, String type ) { @@ -66,7 +71,7 @@ public static String getArtifactKey( Artifact artifact, String type ) public static String getArtifactKey( org.apache.maven.artifact.Artifact artifact ) { return getArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), - artifact.getClassifier(), artifact.getVersion() ); + artifact.getClassifier(), artifact.getVersion() ); } public static String getArtifactKey( String groupId, String artifactId, String type, @@ -81,4 +86,17 @@ public static String getArtifactKey( String groupId, String artifactId, String t return StringUtils.joinWith( SEPARATOR, groupId, artifactId, type, version ); } } + + public static String getVersionlessArtifactKey( String groupId, String artifactId, String type, + String classifier ) + { + if ( classifier != null ) + { + return StringUtils.joinWith( SEPARATOR, groupId, artifactId, type, classifier ); + } + else + { + return StringUtils.joinWith( SEPARATOR, groupId, artifactId, type ); + } + } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java index 96ec30f075c0..7edffbedf6dc 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java @@ -44,9 +44,7 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; -import java.util.concurrent.ConcurrentMap; import java.util.function.Predicate; -import java.util.stream.Collectors; import javax.annotation.Nonnull; @@ -54,14 +52,15 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.caching.LocalCacheRepository; +import org.apache.maven.caching.MultiModuleSupport; +import org.apache.maven.caching.NormalizedModelProvider; import org.apache.maven.caching.PluginScanConfig; import org.apache.maven.caching.CacheUtils; +import org.apache.maven.caching.ProjectInputCalculator; import org.apache.maven.caching.RemoteCacheRepository; import org.apache.maven.caching.ScanConfigProperties; import org.apache.maven.caching.hash.HashAlgorithm; import org.apache.maven.caching.hash.HashChecksum; -import org.apache.maven.caching.xml.Build; import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.caching.xml.DtoUtils; import org.apache.maven.caching.xml.build.DigestItem; @@ -69,12 +68,10 @@ import org.apache.maven.caching.xml.config.Exclude; import org.apache.maven.caching.xml.config.Include; import org.apache.maven.execution.MavenSession; -import org.apache.maven.lifecycle.internal.builder.BuilderCommon; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; -import org.apache.maven.model.PluginManagement; import org.apache.maven.model.Resource; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.project.MavenProject; @@ -134,37 +131,36 @@ public class MavenProjectInput private final MavenProject project; private final MavenSession session; - private final LocalCacheRepository localCache; private final RemoteCacheRepository remoteCache; private final RepositorySystem repoSystem; private final CacheConfig config; - private final ConcurrentMap projectArtifactsByKey; private final PathIgnoringCaseComparator fileComparator; - private final DependencyComparator dependencyComparator; private final List filteredOutPaths; + private final NormalizedModelProvider normalizedModelProvider; + private final MultiModuleSupport multiModuleSupport; + private final ProjectInputCalculator projectInputCalculator; private final Path baseDirPath; private final String dirGlob; private final boolean processPlugins; - private final Map projectIndex; @SuppressWarnings( "checkstyle:parameternumber" ) public MavenProjectInput( MavenProject project, - Map projectIndex, + NormalizedModelProvider normalizedModelProvider, + MultiModuleSupport multiModuleSupport, + ProjectInputCalculator projectInputCalculator, MavenSession session, CacheConfig config, - ConcurrentMap artifactsByKey, RepositorySystem repoSystem, - LocalCacheRepository localCache, RemoteCacheRepository remoteCache ) { this.project = project; + this.normalizedModelProvider = normalizedModelProvider; + this.multiModuleSupport = multiModuleSupport; + this.projectInputCalculator = projectInputCalculator; this.session = session; this.config = config; - this.projectIndex = projectIndex; - this.projectArtifactsByKey = artifactsByKey; this.baseDirPath = project.getBasedir().toPath().toAbsolutePath(); this.repoSystem = repoSystem; - this.localCache = localCache; this.remoteCache = remoteCache; Properties properties = project.getProperties(); this.dirGlob = properties.getProperty( CACHE_INPUT_GLOB_NAME, config.getDefaultGlob() ); @@ -190,16 +186,15 @@ public MavenProjectInput( MavenProject project, } this.fileComparator = new PathIgnoringCaseComparator(); - this.dependencyComparator = new DependencyComparator(); } public ProjectsInputInfo calculateChecksum() throws IOException { final long t0 = System.currentTimeMillis(); - final String effectivePom = getEffectivePom( project.getModel() ); + final String effectivePom = getEffectivePom( normalizedModelProvider.normalizedModel( project ) ); final SortedSet inputFiles = isPom( project ) ? Collections.emptySortedSet() : getInputFiles(); - final SortedMap dependenciesChecksum = getMutableDependencies(); + final SortedMap dependenciesChecksum = getMutableDependencies(); final long t1 = System.currentTimeMillis(); @@ -239,10 +234,10 @@ public ProjectsInputInfo calculateChecksum() throws IOException } boolean dependenciesMatched = true; - for ( Map.Entry entry : dependenciesChecksum.entrySet() ) + for ( Map.Entry entry : dependenciesChecksum.entrySet() ) { DigestItem dependencyDigest = - DigestUtils.dependency( checksum, entry.getKey(), entry.getValue().getHash() ); + DigestUtils.dependency( checksum, entry.getKey(), entry.getValue() ); items.add( dependencyDigest ); if ( compareWithBaseline ) { @@ -327,48 +322,6 @@ private boolean checkItemMatchesBaseline( ProjectsInputInfo baselineBuild, Diges return matched; } - //prototype must not be affected - private Model normalizeModel( Model prototype ) - { - // TODO validate status of the model - it should be in resolved state - Model toHash = new Model(); - - toHash.setGroupId( prototype.getGroupId() ); - toHash.setArtifactId( prototype.getArtifactId() ); - toHash.setVersion( prototype.getVersion() ); - toHash.setModules( prototype.getModules() ); - - toHash.setDependencies( - prototype.getDependencies().stream() - .sorted( dependencyComparator ) - .collect( Collectors.toList() ) - ); - - org.apache.maven.model.Build protoBuild = prototype.getBuild(); - if ( protoBuild == null ) - { - return toHash; - } - - org.apache.maven.model.Build buildToHash = new org.apache.maven.model.Build(); - - List plugins = normalizePlugins( prototype.getBuild().getPlugins() ); - buildToHash.setPlugins( plugins ); - - PluginManagement pluginManagement = buildToHash.getPluginManagement(); - //if it is not a pom packaging no need to track plugin management section in effective pom - //as it contributes into plugins section - if ( pluginManagement != null && isPom( this.project ) ) - { - PluginManagement pluginManagementToHash = pluginManagement.clone(); - pluginManagementToHash.setPlugins( normalizePlugins( pluginManagement.getPlugins() ) ); - buildToHash.setPluginManagement( pluginManagementToHash ); - } - - toHash.setBuild( buildToHash ); - return toHash; - } - /** * @param prototype effective model fully resolved by maven build. Do not pass here just parsed Model. */ @@ -380,7 +333,7 @@ private String getEffectivePom( Model prototype ) throws IOException try { writer = WriterFactory.newXmlWriter( output ); - new MavenXpp3Writer().write( writer, normalizeModel( prototype ) ); + new MavenXpp3Writer().write( writer, prototype ); //normalize env specifics final String[] searchList = {baseDirPath.toString(), "\\", "windows", "linux"}; @@ -725,10 +678,9 @@ private boolean isFilteredOutSubpath( Path path ) return false; } - private SortedMap getMutableDependencies() throws IOException + private SortedMap getMutableDependencies() throws IOException { - MultimoduleDiscoveryStrategy strategy = config.getMultimoduleDiscoveryStrategy(); - SortedMap result = new TreeMap<>(); + SortedMap result = new TreeMap<>(); for ( Dependency dependency : project.getDependencies() ) { @@ -743,67 +695,41 @@ private SortedMap getMutableDependencies() throws IOExceptio } // saved to index by the end of dependency build - final boolean currentlyBuilding = isBuilding( dependency ); - final boolean partOfMultiModule = strategy.isPartOfMultiModule( dependency ); - if ( !currentlyBuilding && !partOfMultiModule && !isSnapshot( dependency.getVersion() ) ) + MavenProject dependencyProject = multiModuleSupport.tryToResolveProject( + dependency.getGroupId(), + dependency.getArtifactId(), + dependency.getVersion() ) + .orElse( null ); + boolean isSnapshot = isSnapshot( dependency.getVersion() ); + if ( dependencyProject == null && !isSnapshot ) { // external immutable dependency, should skip continue; } - - final Artifact dependencyArtifact = repoSystem.createDependencyArtifact( dependency ); - final String artifactKey = KeyUtils.getArtifactKey( dependencyArtifact ); - DigestItem resolved = null; - if ( currentlyBuilding ) + String projectHash; + if ( dependencyProject != null ) //part of multi module { - resolved = projectArtifactsByKey.get( artifactKey ); - if ( resolved == null ) - { - throw new DependencyNotResolvedException( "Expected dependency not resolved: " + dependency ); - } + projectHash = projectInputCalculator.calculateInput( dependencyProject ).getChecksum(); } - else + else //this is a snapshot dependency { - if ( partOfMultiModule ) - { - // TODO lookup in remote cache is not necessary for abfx, for versioned projects - make sense - final Optional bestMatchResult = localCache.findBestMatchingBuild( session, dependency ); - if ( bestMatchResult.isPresent() ) - { - final Build bestMatched = bestMatchResult.get(); - resolved = bestMatched.findArtifact( dependency ); - } - } - if ( resolved != null ) - { - continue; - } - try - { - resolved = resolveArtifact( dependencyArtifact, strategy ); - } - catch ( Exception e ) - { - throw new RuntimeException( "Cannot resolve dependency " + dependency, e ); - } + DigestItem resolved = resolveArtifact( + repoSystem.createDependencyArtifact( dependency ), + false + ); + projectHash = resolved.getHash(); } - result.put( artifactKey, resolved ); + result.put( + KeyUtils.getVersionlessArtifactKey( repoSystem.createDependencyArtifact( dependency ) ), + projectHash + ); } return result; } - private boolean isBuilding( Dependency dependency ) - { - final MavenProject key = new MavenProject(); - key.setGroupId( dependency.getGroupId() ); - key.setArtifactId( dependency.getArtifactId() ); - key.setVersion( dependency.getVersion() ); - return projectIndex.containsKey( BuilderCommon.getKey( key ) ); - } - @Nonnull private DigestItem resolveArtifact( final Artifact dependencyArtifact, - MultimoduleDiscoveryStrategy strategy ) throws IOException + boolean isOffline ) throws IOException { ArtifactResolutionRequest request = new ArtifactResolutionRequest() .setArtifact( dependencyArtifact ) @@ -811,7 +737,7 @@ private DigestItem resolveArtifact( final Artifact dependencyArtifact, .setResolveTransitively( false ) .setLocalRepository( session.getLocalRepository() ) .setRemoteRepositories( project.getRemoteArtifactRepositories() ) - .setOffline( session.isOffline() || !strategy.isLookupRemoteMavenRepo( dependencyArtifact ) ) + .setOffline( session.isOffline() || isOffline ) .setForceUpdate( session.getRequest().isUpdateSnapshots() ) .setServers( session.getRequest().getServers() ) .setMirrors( session.getRequest().getMirrors() ) @@ -863,76 +789,4 @@ public int compare( Path f1, Path f2 ) } } - /** - * DependencyComparator - */ - public static class DependencyComparator implements Comparator - { - @Override - public int compare( Dependency d1, Dependency d2 ) - { - return d1.getArtifactId().compareTo( d2.getArtifactId() ); - } - - } - - private List normalizePlugins( List plugins ) - { - return plugins.stream() - .map( it -> - { - //do not touch original plugin, work with copy to calculate checksum - Plugin plugin = it.clone(); - List excludeProperties = config.getEffectivePomExcludeProperties( plugin ); - removeBlacklistedAttributes( (Xpp3Dom) plugin.getConfiguration(), excludeProperties ); - for ( PluginExecution execution : plugin.getExecutions() ) - { - Xpp3Dom config = (Xpp3Dom) execution.getConfiguration(); - removeBlacklistedAttributes( config, excludeProperties ); - } - //list could be immutable here hence we must not modify it but set new one - plugin.setDependencies( - it.getDependencies().stream() - .sorted( dependencyComparator ) - .collect( Collectors.toList() ) - ); - return plugin; - } ) - .collect( Collectors.toList() ); - } - - private void removeBlacklistedAttributes( Xpp3Dom node, List excludeProperties ) - { - if ( node == null ) - { - return; - } - - Xpp3Dom[] children = node.getChildren(); - for ( int i = 0; i < children.length; i++ ) - { - Xpp3Dom child = children[i]; - if ( excludeProperties.contains( child.getName() ) ) - { - node.removeChild( i ); - continue; - } - removeBlacklistedAttributes( child, excludeProperties ); - } - } - - public CacheConfig getConfig() - { - return config; - } - - public MavenSession getSession() - { - return session; - } - - public MavenProject getProject() - { - return project; - } } diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java index 7bf8540cdfa5..e0db2e4371af 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java @@ -20,7 +20,6 @@ */ import org.apache.maven.caching.PluginScanConfig; -import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.xml.config.Exclude; import org.apache.maven.caching.xml.config.Include; @@ -73,9 +72,6 @@ public interface CacheConfig @Nonnull PluginScanConfig getExecutionDirScanConfig( Plugin plugin, PluginExecution exec ); - @Nonnull - MultimoduleDiscoveryStrategy getMultimoduleDiscoveryStrategy(); - @Nonnull HashFactory getHashFactory(); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 294da4067beb..9cb9f8691888 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -36,7 +36,6 @@ import org.apache.maven.caching.DefaultPluginScanConfig; import org.apache.maven.caching.PluginScanConfig; import org.apache.maven.caching.PluginScanConfigImpl; -import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.xml.config.AttachedOutputs; import org.apache.maven.caching.xml.config.CacheConfig; @@ -53,7 +52,6 @@ import org.apache.maven.caching.xml.config.Local; import org.apache.maven.caching.xml.config.PluginConfigurationScan; import org.apache.maven.caching.xml.config.PluginSet; -import org.apache.maven.caching.xml.config.ProjectDiscoveryStrategy; import org.apache.maven.caching.xml.config.PropertyName; import org.apache.maven.caching.xml.config.Remote; import org.apache.maven.caching.xml.config.TrackedProperty; @@ -379,20 +377,6 @@ public List getGlobalExcludePaths() return cacheConfig.getInput().getGlobal().getExcludes(); } - @Nonnull - @Override - public MultimoduleDiscoveryStrategy getMultimoduleDiscoveryStrategy() - { - checkInitializedState(); - final ProjectDiscoveryStrategy projectDiscoveryStrategy = - cacheConfig.getConfiguration().getProjectDiscoveryStrategy(); - if ( projectDiscoveryStrategy != null && projectDiscoveryStrategy.getSpecificVersion() != null ) - { - return new SentinelVersionStrategy( projectDiscoveryStrategy.getSpecificVersion() ); - } - return new AllExternalStrategy(); - } - @Nonnull @Override public HashFactory getHashFactory() diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStrategy.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStrategy.java deleted file mode 100644 index e198899097f3..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/SentinelVersionStrategy.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.apache.maven.caching.xml; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.checksum.MultimoduleDiscoveryStrategy; -import org.apache.maven.model.Dependency; -import org.codehaus.plexus.util.StringUtils; - -/** - * SentinelVersionStrategy - */ -public class SentinelVersionStrategy implements MultimoduleDiscoveryStrategy -{ - private final String version; - - public SentinelVersionStrategy( String version ) - { - this.version = version; - } - - @Override - public boolean isPartOfMultiModule( Dependency dependency ) - { - return StringUtils.equals( version, dependency.getVersion() ); - } - - @Override - public boolean isLookupRemoteMavenRepo( Artifact artifact ) - { - // TODO abfx specific - should be config driven - return !StringUtils.equals( version, artifact.getVersion() ); - } -} diff --git a/maven-caching/src/main/mdo/cache-config.mdo b/maven-caching/src/main/mdo/cache-config.mdo index 07bef41bfe2b..16f455186b53 100644 --- a/maven-caching/src/main/mdo/cache-config.mdo +++ b/maven-caching/src/main/mdo/cache-config.mdo @@ -128,25 +128,6 @@ under the License. - - - - Specifies how to identify belonging to a cached project then submodule is being build. - - - - - - - - Any project dependency this this version will be considered cache eligible and will - be processed cache aware - - - - - - From 74cf06f1df6212da39f391a10e697f65cca94f3d Mon Sep 17 00:00:00 2001 From: Andrey Petrenko Date: Thu, 25 Nov 2021 03:37:37 +0300 Subject: [PATCH 165/188] MNG-7129: caching extension --- .../org/apache/maven/caching/DefaultNormalizedModelProvider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/DefaultNormalizedModelProvider.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultNormalizedModelProvider.java index 702524075379..c263d5fe17ed 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/DefaultNormalizedModelProvider.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/DefaultNormalizedModelProvider.java @@ -47,7 +47,6 @@ public class DefaultNormalizedModelProvider implements NormalizedModelProvider private final CacheConfig cacheConfig; private final MultiModuleSupport multiModuleSupport; - //private final MultiModuleSupport multiModuleSupport; private final ConcurrentMap modelCache = new ConcurrentHashMap<>(); @Inject From dba502f9fa6ea00a231210b5042c316860ce9dff Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 25 Nov 2021 10:27:43 +0100 Subject: [PATCH 166/188] Revert "[MNG-7336] Define a Feature for caching" This reverts commit fdab508a77b7808a9455af2194e91518e5975873. # Conflicts: # maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java --- .../java/org/apache/maven/caching/xml/CacheConfigImpl.java | 5 +++-- .../src/main/java/org/apache/maven/feature/Features.java | 5 ----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 294da4067beb..ea83509c6f61 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -58,7 +58,6 @@ import org.apache.maven.caching.xml.config.Remote; import org.apache.maven.caching.xml.config.TrackedProperty; import org.apache.maven.execution.MavenSession; -import org.apache.maven.feature.Features; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; import org.apache.maven.plugin.MojoExecution; @@ -78,6 +77,7 @@ public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig { public static final String CONFIG_PATH_PROPERTY_NAME = "remote.cache.configPath"; + public static final String CACHE_ENABLED_PROPERTY_NAME = "remote.cache.enabled"; public static final String SAVE_TO_REMOTE_PROPERTY_NAME = "remote.cache.save.enabled"; public static final String SAVE_NON_OVERRIDEABLE_NAME = "remote.cache.save.final"; public static final String FAIL_FAST_PROPERTY_NAME = "remote.cache.failFast"; @@ -108,7 +108,8 @@ public CacheState initialize() { if ( state == null ) { - if ( !Features.caching( session.getUserProperties() ).isActive() ) + final String enabled = getProperty( CACHE_ENABLED_PROPERTY_NAME, "true" ); + if ( !Boolean.parseBoolean( enabled ) ) { LOGGER.info( "Cache disabled by command line flag, project will be built fully and not cached" ); state = CacheState.DISABLED; diff --git a/maven-model-builder/src/main/java/org/apache/maven/feature/Features.java b/maven-model-builder/src/main/java/org/apache/maven/feature/Features.java index 5c9156349d0e..47608a6a0186 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/feature/Features.java +++ b/maven-model-builder/src/main/java/org/apache/maven/feature/Features.java @@ -38,11 +38,6 @@ public static Feature buildConsumer( Properties userProperties ) return new Feature( userProperties, "maven.experimental.buildconsumer", "true" ); } - public static Feature caching( Properties userProperties ) - { - return new Feature( userProperties, "maven.experimental.caching", "true" ); - } - /** * Represents some feature * From 3f09c817ee1b062db697c57fb8613a90bfe71f08 Mon Sep 17 00:00:00 2001 From: Andrey Petrenko Date: Thu, 25 Nov 2021 13:35:49 +0300 Subject: [PATCH 167/188] MNG-7129: caching extension --- .../caching/DefaultMultiModuleSupport.java | 16 ++++- .../apache/maven/caching/xml/CacheConfig.java | 5 ++ .../maven/caching/xml/CacheConfigImpl.java | 10 +++ maven-caching/src/main/mdo/cache-config.mdo | 71 ++++++++++++++++--- 4 files changed, 89 insertions(+), 13 deletions(-) diff --git a/maven-caching/src/main/java/org/apache/maven/caching/DefaultMultiModuleSupport.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultMultiModuleSupport.java index d4c6b56365f6..d606f835a6ef 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/DefaultMultiModuleSupport.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/DefaultMultiModuleSupport.java @@ -21,6 +21,9 @@ import org.apache.maven.SessionScoped; import org.apache.maven.caching.checksum.KeyUtils; +import org.apache.maven.caching.xml.CacheConfig; +import org.apache.maven.caching.xml.config.Discovery; +import org.apache.maven.caching.xml.config.MultiModule; import org.apache.maven.execution.MavenSession; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; @@ -42,6 +45,7 @@ import java.util.Optional; import java.util.Properties; import java.util.Set; +import java.util.TreeSet; import java.util.function.Function; import java.util.stream.Collectors; @@ -53,6 +57,7 @@ public class DefaultMultiModuleSupport implements MultiModuleSupport private static final Logger LOGGER = LoggerFactory.getLogger( DefaultMultiModuleSupport.class ); private final ProjectBuilder projectBuilder; + private final CacheConfig cacheConfig; private final MavenSession session; private volatile boolean built; @@ -60,9 +65,12 @@ public class DefaultMultiModuleSupport implements MultiModuleSupport private volatile Map sessionProjectMap; @Inject - public DefaultMultiModuleSupport( ProjectBuilder projectBuilder, MavenSession session ) + public DefaultMultiModuleSupport( ProjectBuilder projectBuilder, + CacheConfig cacheConfig, + MavenSession session ) { this.projectBuilder = projectBuilder; + this.cacheConfig = cacheConfig; this.session = session; } @@ -126,8 +134,10 @@ private synchronized void buildModel( MavenSession session ) { return; } - //TODO: re-work hardcode - Set scanProfiles = Collections.singleton( "abfx-all" ); + Set scanProfiles = new TreeSet<>( Optional.ofNullable( cacheConfig.getMultiModule() ) + .map( MultiModule::getDiscovery ) + .map( Discovery::getScanProfiles ) + .orElse( Collections.emptyList() ) ); MavenProject currentProject = session.getCurrentProject(); File multiModulePomFile = getMultiModulePomFile( session ); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java index e0db2e4371af..4a63b47d8e6d 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java @@ -23,6 +23,7 @@ import org.apache.maven.caching.hash.HashFactory; import org.apache.maven.caching.xml.config.Exclude; import org.apache.maven.caching.xml.config.Include; +import org.apache.maven.caching.xml.config.MultiModule; import org.apache.maven.caching.xml.config.PropertyName; import org.apache.maven.caching.xml.config.TrackedProperty; import org.apache.maven.model.Plugin; @@ -30,6 +31,7 @@ import org.apache.maven.plugin.MojoExecution; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.List; import java.util.regex.Pattern; @@ -56,6 +58,9 @@ public interface CacheConfig @Nonnull List getEffectivePomExcludeProperties( Plugin plugin ); + @Nullable + MultiModule getMultiModule(); + String isProcessPlugins(); String getDefaultGlob(); diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java index 9cb9f8691888..4d4c7fdcca66 100644 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java @@ -28,6 +28,7 @@ import java.util.regex.Pattern; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Named; @@ -50,6 +51,7 @@ import org.apache.maven.caching.xml.config.GoalsList; import org.apache.maven.caching.xml.config.Include; import org.apache.maven.caching.xml.config.Local; +import org.apache.maven.caching.xml.config.MultiModule; import org.apache.maven.caching.xml.config.PluginConfigurationScan; import org.apache.maven.caching.xml.config.PluginSet; import org.apache.maven.caching.xml.config.PropertyName; @@ -274,6 +276,14 @@ public List getEffectivePomExcludeProperties( Plugin plugin ) return Collections.emptyList(); } + @Nullable + @Override + public MultiModule getMultiModule() + { + checkInitializedState(); + return cacheConfig.getConfiguration().getMultiModule(); + } + private PluginConfigurationScan findPluginScanConfig( Plugin plugin ) { if ( cacheConfig.getInput() == null ) diff --git a/maven-caching/src/main/mdo/cache-config.mdo b/maven-caching/src/main/mdo/cache-config.mdo index 16f455186b53..6f6748c3d4c9 100644 --- a/maven-caching/src/main/mdo/cache-config.mdo +++ b/maven-caching/src/main/mdo/cache-config.mdo @@ -219,11 +219,11 @@ under the License. Validate cache config and builds metadata against xsd. - projectDiscoveryStrategy + multiModule - ProjectDiscoveryStrategy + MultiModule - Specifies how to identify belonging to a cached project then submodule is being build. + Specifies related to multi module projects configuration. remote @@ -269,20 +269,71 @@ under the License. --> + - ProjectDiscoveryStrategy + MultiModule - specificVersion - String - - Any project dependency this this version will be considered cache eligible and will - be processed cache aware - + discovery + + Discovery + + Section to specify how to discover multi module projects. + + + + + + + + Discovery + + + scanProfiles + + String + * + + Profiles to discover multi module project + + Configuration @@ -241,6 +201,13 @@ under the License. Specifies related to multi module projects configuration. + + projectVersioning + + ProjectVersioning + + Specifies parameters to handle project version changes. + remote @@ -350,6 +317,31 @@ under the License. --> + + ProjectVersioning + + + adjustMetaInf + boolean + Determines whether version in metadata must be changed according to building project version. + + + + + + - - - 4.0.0 - - - org.apache.maven - maven - 4.0.0-alpha-1-SNAPSHOT - - - maven-caching - - Maven Caching - Maven Caching classes. - - - - - org.apache.maven - maven-core - provided - - - org.apache.httpcomponents - httpclient - 4.5.13 - - - net.openhft - zero-allocation-hashing - 0.9 - - - com.github.albfernandez - juniversalchardet - 2.4.0 - - - org.apache.commons - commons-lang3 - - - org.apache.commons - commons-io - 1.3.2 - - - javax.annotation - javax.annotation-api - - - org.codehaus.plexus - plexus-utils - - - org.apache.maven.wagon - wagon-http - ${wagonVersion} - - - org.apache.maven.resolver - maven-resolver-util - - - com.google.code.findbugs - jsr305 - 3.0.2 - compile - - - org.junit.jupiter - junit-jupiter-engine - test - - - - - - - org.codehaus.modello - modello-maven-plugin - - - src/main/mdo/cache-config.mdo - src/main/mdo/cache-build.mdo - src/main/mdo/cache-diff.mdo - src/main/mdo/cache-report.mdo - - 1.0.0 - - - - modello-cache - generate-sources - - java - xpp3-reader - xpp3-writer - - - - modello-cache-xsd - generate-resources - - xsd - - - ${basedir}/target/generated-resources/modello - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.2.0 - - - add-resources - generate-resources - - add-test-resource - - - - - ${basedir}/target/generated-test-resources/modello - - - - - - - - - diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java deleted file mode 100644 index 81a2a318d166..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheContext.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.caching.xml.build.ProjectsInputInfo; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; - -import static java.util.Objects.requireNonNull; - -/** - * CacheContext - */ -public class CacheContext -{ - private final MavenProject project; - private final ProjectsInputInfo inputInfo; - private final MavenSession session; - - public CacheContext( MavenProject project, ProjectsInputInfo inputInfo, MavenSession session ) - { - this.project = requireNonNull( project ); - this.inputInfo = requireNonNull( inputInfo ); - this.session = requireNonNull( session ); - } - - public MavenProject getProject() - { - return project; - } - - public ProjectsInputInfo getInputInfo() - { - return inputInfo; - } - - public MavenSession getSession() - { - return session; - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheController.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheController.java deleted file mode 100644 index 5a28a984e111..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheController.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.execution.MojoExecutionEvent; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.project.MavenProject; - -import java.util.List; -import java.util.Map; - -/** - * CacheController - */ -public interface CacheController -{ - - CacheResult findCachedBuild( MavenSession session, - MavenProject project, - List mojoExecutions ); - - boolean restoreProjectArtifacts( CacheResult cacheResult ); - - void save( CacheResult cacheResult, - List mojoExecutions, - Map executionEvents ); - - boolean isForcedExecution( MavenProject project, MojoExecution execution ); - - void saveCacheReport( MavenSession session ); - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java deleted file mode 100644 index 6c5c63eb2035..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheControllerImpl.java +++ /dev/null @@ -1,952 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.mutable.MutableBoolean; -import org.apache.maven.SessionScoped; -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; -import org.apache.maven.caching.artifact.RestoredArtifact; -import org.apache.maven.caching.hash.HashAlgorithm; -import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.xml.Build; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.CacheSource; -import org.apache.maven.caching.xml.DtoUtils; -import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.caching.xml.build.Artifact; -import org.apache.maven.caching.xml.build.CompletedExecution; -import org.apache.maven.caching.xml.build.DigestItem; -import org.apache.maven.caching.xml.build.ProjectsInputInfo; -import org.apache.maven.caching.xml.build.Scm; -import org.apache.maven.caching.xml.config.PropertyName; -import org.apache.maven.caching.xml.config.TrackedProperty; -import org.apache.maven.caching.xml.diff.Diff; -import org.apache.maven.caching.xml.report.CacheReport; -import org.apache.maven.caching.xml.report.ProjectReport; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.execution.MojoExecutionEvent; -import org.apache.maven.plugin.Mojo; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectHelper; -import org.apache.maven.repository.RepositorySystem; -import org.codehaus.plexus.util.ReflectionUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nonnull; -import javax.inject.Inject; -import javax.inject.Named; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.TreeSet; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.Future; -import java.util.concurrent.FutureTask; -import java.util.regex.Pattern; - -import static java.nio.file.StandardOpenOption.CREATE; -import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; -import static org.apache.commons.lang3.StringUtils.isNotBlank; -import static org.apache.commons.lang3.StringUtils.replace; -import static org.apache.commons.lang3.StringUtils.split; -import static org.apache.maven.caching.CacheResult.empty; -import static org.apache.maven.caching.CacheResult.failure; -import static org.apache.maven.caching.CacheResult.partialSuccess; -import static org.apache.maven.caching.CacheResult.rebuilded; -import static org.apache.maven.caching.CacheResult.success; -import static org.apache.maven.caching.HttpCacheRepositoryImpl.BUILDINFO_XML; -import static org.apache.maven.caching.checksum.KeyUtils.getVersionlessProjectKey; -import static org.apache.maven.caching.checksum.MavenProjectInput.CACHE_IMPLEMENTATION_VERSION; - -/** - * CacheControllerImpl - */ -@SessionScoped -@Named -@SuppressWarnings( "unused" ) -public class CacheControllerImpl implements CacheController -{ - - public static final String FILE_SEPARATOR_SUBST = "_"; - /** - * Prefix for generated sources stored as a separate artifact in cache - */ - private static final String BUILD_PREFIX = "build" + FILE_SEPARATOR_SUBST; - - private static final Logger LOGGER = LoggerFactory.getLogger( CacheControllerImpl.class ); - - private final MavenProjectHelper projectHelper; - private final ArtifactHandlerManager artifactHandlerManager; - private final XmlService xmlService; - private final CacheConfig cacheConfig; - private final LocalCacheRepository localCache; - private final RemoteCacheRepository remoteCache; - private final ConcurrentMap cacheResults = new ConcurrentHashMap<>(); - private final LifecyclePhasesHelper lifecyclePhasesHelper; - private volatile Map projectIndex; - private final ProjectInputCalculator projectInputCalculator; - private final RestoredArtifactHandler restoreArtifactHandler; - private volatile Scm scm; - - @Inject - public CacheControllerImpl( - MavenProjectHelper projectHelper, - RepositorySystem repoSystem, - ArtifactHandlerManager artifactHandlerManager, - XmlService xmlService, - LocalCacheRepository localCache, - RemoteCacheRepository remoteCache, - CacheConfig cacheConfig, - ProjectInputCalculator projectInputCalculator, - RestoredArtifactHandler restoreArtifactHandler, - LifecyclePhasesHelper lifecyclePhasesHelper, - MavenSession session ) - { - this.projectHelper = projectHelper; - this.localCache = localCache; - this.remoteCache = remoteCache; - this.cacheConfig = cacheConfig; - this.artifactHandlerManager = artifactHandlerManager; - this.xmlService = xmlService; - this.lifecyclePhasesHelper = lifecyclePhasesHelper; - this.projectInputCalculator = projectInputCalculator; - this.restoreArtifactHandler = restoreArtifactHandler; - } - - @Override - @Nonnull - public CacheResult findCachedBuild( MavenSession session, MavenProject project, - List mojoExecutions ) - { - final String highestRequestPhase = CacheUtils.getLast( mojoExecutions ).getLifecyclePhase(); - if ( !lifecyclePhasesHelper.isLaterPhaseThanClean( highestRequestPhase ) ) - { - return empty(); - } - - LOGGER.info( "Attempting to restore project from build cache" ); - - ProjectsInputInfo inputInfo = projectInputCalculator.calculateInput( project ); - - final CacheContext context = new CacheContext( project, inputInfo, session ); - // remote build first - CacheResult result = findCachedBuild( mojoExecutions, context ); - - if ( !result.isSuccess() && result.getContext() != null ) - { - LOGGER.debug( "Remote cache is incomplete or missing, trying local build" ); - - CacheResult localBuild = findLocalBuild( mojoExecutions, context ); - - if ( localBuild.isSuccess() || ( localBuild.isPartialSuccess() && !result.isPartialSuccess() ) ) - { - result = localBuild; - } - else - { - LOGGER.info( "Local build was not found by checksum " + inputInfo.getChecksum() ); - } - } - cacheResults.put( getVersionlessProjectKey( project ), result ); - - return result; - } - - private CacheResult findCachedBuild( List mojoExecutions, CacheContext context ) - { - Optional cachedBuild = Optional.empty(); - try - { - cachedBuild = localCache.findBuild( context ); - if ( cachedBuild.isPresent() ) - { - return analyzeResult( context, mojoExecutions, cachedBuild.get() ); - } - } - catch ( Exception e ) - { - LOGGER.error( "Cannot read cached remote build", e ); - } - return cachedBuild.map( build -> failure( build, context ) ) - .orElseGet( () -> empty( context ) ); - } - - private CacheResult findLocalBuild( List mojoExecutions, CacheContext context ) - { - Optional localBuild = Optional.empty(); - try - { - localBuild = localCache.findLocalBuild( context ); - if ( localBuild.isPresent() ) - { - return analyzeResult( context, mojoExecutions, localBuild.get() ); - } - } - catch ( Exception e ) - { - LOGGER.error( "Cannot read local build", e ); - } - return localBuild.map( build -> failure( build, context ) ) - .orElseGet( () -> empty( context ) ); - } - - private CacheResult analyzeResult( CacheContext context, List mojoExecutions, Build build ) - { - try - { - final ProjectsInputInfo inputInfo = context.getInputInfo(); - - LOGGER.info( "Found cached build, restoring from cache {}", inputInfo.getChecksum() ); - LOGGER.debug( "Cached build details: {}", build ); - - final String cacheImplementationVersion = build.getCacheImplementationVersion(); - if ( !CACHE_IMPLEMENTATION_VERSION.equals( cacheImplementationVersion ) ) - { - LOGGER.warn( - "Maven and cached build implementations mismatch, caching might not work correctly. " - + "Implementation version: " + CACHE_IMPLEMENTATION_VERSION + ", cached build: {}", - build.getCacheImplementationVersion() ); - } - - List cachedSegment = lifecyclePhasesHelper.getCachedSegment( mojoExecutions, build ); - List missingMojos = build.getMissingExecutions( cachedSegment ); - if ( !missingMojos.isEmpty() ) - { - LOGGER.warn( "Cached build doesn't contains all requested plugin executions " - + "(missing: {}), cannot restore", missingMojos ); - return failure( build, context ); - } - - if ( !isCachedSegmentPropertiesPresent( context.getProject(), build, cachedSegment ) ) - { - LOGGER.info( "Cached build violates cache rules, cannot restore" ); - return failure( build, context ); - } - - final String highestRequestPhase = CacheUtils.getLast( mojoExecutions ).getLifecyclePhase(); - if ( lifecyclePhasesHelper.isLaterPhaseThanBuild( highestRequestPhase, build ) - && !canIgnoreMissingSegment( build, mojoExecutions ) ) - { - LOGGER.info( "Project restored partially. Highest cached goal: {}, requested: {}", - build.getHighestCompletedGoal(), highestRequestPhase ); - return partialSuccess( build, context ); - } - - return success( build, context ); - - } - catch ( Exception e ) - { - LOGGER.error( "Failed to restore project", e ); - localCache.clearCache( context ); - return failure( build, context ); - } - } - - private boolean canIgnoreMissingSegment( Build info, List mojoExecutions ) - { - final List postCachedSegment = - lifecyclePhasesHelper.getPostCachedSegment( mojoExecutions, info ); - for ( MojoExecution mojoExecution : postCachedSegment ) - { - if ( !cacheConfig.canIgnore( mojoExecution ) ) - { - return false; - } - } - return true; - } - - @Override - public boolean restoreProjectArtifacts( CacheResult cacheResult ) - { - final Build build = cacheResult.getBuildInfo(); - final CacheContext context = cacheResult.getContext(); - final MavenProject project = context.getProject(); - - try - { - RestoredArtifact restoredProjectArtifact = null; - List restoredAttachedArtifacts = new ArrayList<>(); - - if ( build.getArtifact() != null && isNotBlank( build.getArtifact().getFileName() ) ) - { - final Artifact artifactInfo = build.getArtifact(); - String originalVersion = artifactInfo.getVersion(); - artifactInfo.setVersion( project.getVersion() ); - // TODO if remote is forced, probably need to refresh or reconcile all files - final Future downloadTask = createDownloadTask( - cacheResult, - context, - project, - artifactInfo, - originalVersion ); - restoredProjectArtifact = - restoredArtifact( project.getArtifact(), artifactInfo.getType(), artifactInfo.getClassifier(), - downloadTask ); - } - - for ( Artifact attachedArtifactInfo : build.getAttachedArtifacts() ) - { - String originalVersion = attachedArtifactInfo.getVersion(); - attachedArtifactInfo.setVersion( project.getVersion() ); - if ( isNotBlank( attachedArtifactInfo.getFileName() ) ) - { - if ( StringUtils.startsWith( attachedArtifactInfo.getClassifier(), BUILD_PREFIX ) ) - { - // restoring generated sources might be unnecessary in CI, could be disabled for - // performance reasons - if ( cacheConfig.isRestoreGeneratedSources() ) - { - // generated sources artifact - final Path attachedArtifactFile = localCache.getArtifactFile( context, - cacheResult.getSource(), attachedArtifactInfo ); - restoreGeneratedSources( attachedArtifactInfo, attachedArtifactFile, project ); - } - } - else - { - Future downloadTask = - createDownloadTask( - cacheResult, - context, - project, - attachedArtifactInfo, - originalVersion - ); - final RestoredArtifact restoredAttachedArtifact = - restoredArtifact( restoredProjectArtifact == null ? project.getArtifact() - : restoredProjectArtifact, - attachedArtifactInfo.getType(), - attachedArtifactInfo.getClassifier(), - downloadTask ); - restoredAttachedArtifacts.add( restoredAttachedArtifact ); - } - } - } - // Actually modify project at the end in case something went wrong during restoration, - // in which case, the project is unmodified and we continue with normal build. - if ( restoredProjectArtifact != null ) - { - project.setArtifact( restoredProjectArtifact ); - } - restoredAttachedArtifacts.forEach( project::addAttachedArtifact ); - return true; - } - catch ( Exception e ) - { - LOGGER.debug( "Cannot restore cache, continuing with normal build.", e ); - return false; - } - } - - /** - * Helper method similar to {@link org.apache.maven.project.MavenProjectHelper#attachArtifact} to work specifically - * with restored from cache artifacts - */ - private RestoredArtifact restoredArtifact( org.apache.maven.artifact.Artifact parent, String artifactType, - String artifactClassifier, - Future artifactFile ) - { - ArtifactHandler handler = null; - - if ( artifactType != null ) - { - handler = artifactHandlerManager.getArtifactHandler( artifactType ); - } - - if ( handler == null ) - { - handler = artifactHandlerManager.getArtifactHandler( "jar" ); - } - - // todo: probably need update download url to cache - RestoredArtifact artifact = new RestoredArtifact( parent, artifactFile, artifactType, artifactClassifier, - handler ); - artifact.setResolved( true ); - - return artifact; - } - - - private Future createDownloadTask( CacheResult cacheResult, CacheContext context, MavenProject project, - Artifact artifact, String originalVersion ) - { - final FutureTask downloadTask = new FutureTask<>( () -> - { - LOGGER.debug( "Downloading artifact {}", artifact.getArtifactId() ); - final Path artifactFile = localCache.getArtifactFile( context, cacheResult.getSource(), - artifact ); - if ( !Files.exists( artifactFile ) ) - { - throw new FileNotFoundException( - "Missing file for cached build, cannot restore. File: " + artifactFile ); - } - LOGGER.debug( "Downloaded artifact " + artifact.getArtifactId() + " to: " + artifactFile ); - return restoreArtifactHandler.adjustArchiveArtifactVersion( - project, - originalVersion, - artifactFile ).toFile(); - } ); - if ( !cacheConfig.isLazyRestore() ) - { - downloadTask.run(); - } - return downloadTask; - } - - @Override - public void save( CacheResult cacheResult, List mojoExecutions, - Map executionEvents ) - { - CacheContext context = cacheResult.getContext(); - - if ( context == null || context.getInputInfo() == null ) - { - LOGGER.info( "Cannot save project in cache, skipping" ); - return; - } - - final MavenProject project = context.getProject(); - final MavenSession session = context.getSession(); - try - { - final HashFactory hashFactory = cacheConfig.getHashFactory(); - final org.apache.maven.artifact.Artifact projectArtifact = project.getArtifact(); - final List attachedArtifacts; - final List attachedArtifactDtos; - final Artifact projectArtifactDto; - if ( project.hasLifecyclePhase( "package" ) ) - { - final HashAlgorithm algorithm = hashFactory.createAlgorithm(); - attachGeneratedSources( project ); - attachOutputs( project ); - attachedArtifacts = project.getAttachedArtifacts() != null - ? project.getAttachedArtifacts() : Collections.emptyList(); - attachedArtifactDtos = artifactDtos( attachedArtifacts, algorithm ); - projectArtifactDto = artifactDto( project.getArtifact(), algorithm ); - } - else - { - attachedArtifacts = Collections.emptyList(); - attachedArtifactDtos = new ArrayList<>(); - projectArtifactDto = null; - } - - List completedExecution = buildExecutionInfo( mojoExecutions, executionEvents ); - - final Build build = new Build( session.getGoals(), projectArtifactDto, attachedArtifactDtos, - context.getInputInfo(), completedExecution, hashFactory.getAlgorithm() ); - populateGitInfo( build, session ); - build.getDto().set_final( cacheConfig.isSaveFinal() ); - cacheResults.put( getVersionlessProjectKey( project ), rebuilded( cacheResult, build ) ); - - // if package phase presence means new artifacts were packaged - if ( project.hasLifecyclePhase( "package" ) ) - { - localCache.beforeSave( context ); - localCache.saveBuildInfo( cacheResult, build ); - if ( projectArtifact.getFile() != null ) - { - localCache.saveArtifactFile( cacheResult, projectArtifact ); - } - for ( org.apache.maven.artifact.Artifact attachedArtifact : attachedArtifacts ) - { - if ( attachedArtifact.getFile() != null && isOutputArtifact( - attachedArtifact.getFile().getName() ) ) - { - localCache.saveArtifactFile( cacheResult, attachedArtifact ); - } - } - } - else - { - localCache.saveBuildInfo( cacheResult, build ); - } - - if ( cacheConfig.isBaselineDiffEnabled() ) - { - produceDiffReport( cacheResult, build ); - } - - } - catch ( Exception e ) - { - LOGGER.error( "Failed to save project, cleaning cache. Project: {}", project, e ); - try - { - localCache.clearCache( context ); - } - catch ( Exception ex ) - { - LOGGER.error( "Failed to clean cache due to unexpected error:", ex ); - } - } - } - - public void produceDiffReport( CacheResult cacheResult, Build build ) - { - MavenProject project = cacheResult.getContext().getProject(); - Optional baselineHolder = remoteCache.findBaselineBuild( project ); - if ( baselineHolder.isPresent() ) - { - Build baseline = baselineHolder.get(); - String outputDirectory = project.getBuild().getDirectory(); - Path reportOutputDir = Paths.get( outputDirectory, "incremental-maven" ); - LOGGER.info( "Saving cache builds diff to: {}", reportOutputDir ); - Diff diff = new CacheDiff( build.getDto(), baseline.getDto(), cacheConfig ).compare(); - try - { - Files.createDirectories( reportOutputDir ); - final ProjectsInputInfo baselineInputs = baseline.getDto().getProjectsInputInfo(); - final String checksum = baselineInputs.getChecksum(); - Files.write( reportOutputDir.resolve( "buildinfo-baseline-" + checksum + ".xml" ), - xmlService.toBytes( baseline.getDto() ), TRUNCATE_EXISTING, CREATE ); - Files.write( reportOutputDir.resolve( "buildinfo-" + checksum + ".xml" ), - xmlService.toBytes( build.getDto() ), TRUNCATE_EXISTING, CREATE ); - Files.write( reportOutputDir.resolve( "buildsdiff-" + checksum + ".xml" ), - xmlService.toBytes( diff ), TRUNCATE_EXISTING, CREATE ); - final Optional pom = CacheDiff.findPom( build.getDto().getProjectsInputInfo() ); - if ( pom.isPresent() ) - { - Files.write( reportOutputDir.resolve( "effective-pom-" + checksum + ".xml" ), - pom.get().getValue().getBytes( StandardCharsets.UTF_8 ), - TRUNCATE_EXISTING, CREATE ); - } - final Optional baselinePom = CacheDiff.findPom( baselineInputs ); - if ( baselinePom.isPresent() ) - { - Files.write( reportOutputDir.resolve( - "effective-pom-baseline-" + baselineInputs.getChecksum() + ".xml" ), - baselinePom.get().getValue().getBytes( StandardCharsets.UTF_8 ), - TRUNCATE_EXISTING, CREATE ); - } - } - catch ( IOException e ) - { - LOGGER.error( "Cannot produce build diff for project", e ); - } - } - else - { - LOGGER.info( "Cannot find project in baseline build, skipping diff" ); - } - } - - private List artifactDtos( List attachedArtifacts, - HashAlgorithm digest ) throws IOException - { - List result = new ArrayList<>(); - for ( org.apache.maven.artifact.Artifact attachedArtifact : attachedArtifacts ) - { - if ( attachedArtifact.getFile() != null && isOutputArtifact( attachedArtifact.getFile().getName() ) ) - { - result.add( artifactDto( attachedArtifact, digest ) ); - } - } - return result; - } - - private Artifact artifactDto( org.apache.maven.artifact.Artifact projectArtifact, - HashAlgorithm algorithm ) throws IOException - { - final Artifact dto = DtoUtils.createDto( projectArtifact ); - if ( projectArtifact.getFile() != null && projectArtifact.getFile().isFile() ) - { - final Path file = projectArtifact.getFile().toPath(); - dto.setFileHash( algorithm.hash( file ) ); - dto.setFileSize( Files.size( file ) ); - } - return dto; - } - - private List buildExecutionInfo( List mojoExecutions, - Map executionEvents ) - { - List list = new ArrayList<>(); - for ( MojoExecution mojoExecution : mojoExecutions ) - { - final String executionKey = CacheUtils.mojoExecutionKey( mojoExecution ); - final MojoExecutionEvent executionEvent = - executionEvents != null ? executionEvents.get( executionKey ) : null; - CompletedExecution executionInfo = new CompletedExecution(); - executionInfo.setExecutionKey( executionKey ); - executionInfo.setMojoClassName( mojoExecution.getMojoDescriptor().getImplementation() ); - if ( executionEvent != null ) - { - recordMojoProperties( executionInfo, executionEvent ); - } - list.add( executionInfo ); - } - return list; - } - - private void recordMojoProperties( CompletedExecution execution, MojoExecutionEvent executionEvent ) - { - final MojoExecution mojoExecution = executionEvent.getExecution(); - - final boolean logAll = cacheConfig.isLogAllProperties( mojoExecution ); - List trackedProperties = cacheConfig.getTrackedProperties( mojoExecution ); - List noLogProperties = cacheConfig.getNologProperties( mojoExecution ); - List forceLogProperties = cacheConfig.getLoggedProperties( mojoExecution ); - final Mojo mojo = executionEvent.getMojo(); - - final File baseDir = executionEvent.getProject().getBasedir(); - final String baseDirPath = FilenameUtils.normalizeNoEndSeparator( baseDir.getAbsolutePath() ) + File.separator; - - final List parameters = mojoExecution.getMojoDescriptor().getParameters(); - for ( Parameter parameter : parameters ) - { - // editable parameters could be configured by user - if ( !parameter.isEditable() ) - { - continue; - } - - final String propertyName = parameter.getName(); - final boolean tracked = isTracked( propertyName, trackedProperties ); - if ( !tracked && isExcluded( propertyName, logAll, noLogProperties, forceLogProperties ) ) - { - continue; - } - - try - { - final Object value = ReflectionUtils.getValueIncludingSuperclasses( propertyName, mojo ); - DtoUtils.addProperty( execution, propertyName, value, baseDirPath, tracked ); - } - catch ( IllegalAccessException e ) - { - LOGGER.info( "Cannot get property {} value from {}: {}", propertyName, mojo, e.getMessage() ); - if ( tracked ) - { - throw new IllegalArgumentException( "Property configured in cache introspection config " - + "for " + mojo + " is not accessible: " + propertyName ); - } - } - } - } - - private boolean isExcluded( String propertyName, boolean logAll, List excludedProperties, - List forceLogProperties ) - { - if ( !forceLogProperties.isEmpty() ) - { - for ( PropertyName logProperty : forceLogProperties ) - { - if ( StringUtils.equals( propertyName, logProperty.getPropertyName() ) ) - { - return false; - } - } - return true; - } - - if ( !excludedProperties.isEmpty() ) - { - for ( PropertyName excludedProperty : excludedProperties ) - { - if ( StringUtils.equals( propertyName, excludedProperty.getPropertyName() ) ) - { - return true; - } - } - return false; - } - - return !logAll; - } - - private boolean isTracked( String propertyName, List trackedProperties ) - { - for ( TrackedProperty trackedProperty : trackedProperties ) - { - if ( StringUtils.equals( propertyName, trackedProperty.getPropertyName() ) ) - { - return true; - } - } - return false; - } - - private boolean isCachedSegmentPropertiesPresent( MavenProject project, Build build, - List mojoExecutions ) - { - for ( MojoExecution mojoExecution : mojoExecutions ) - { - // completion of all mojos checked above, so we expect tp have execution info here - final List trackedProperties = cacheConfig.getTrackedProperties( mojoExecution ); - final CompletedExecution cachedExecution = build.findMojoExecutionInfo( mojoExecution ); - - if ( cachedExecution == null ) - { - LOGGER.info( "Execution is not cached. Plugin: {}, goal {}", - mojoExecution.getExecutionId(), mojoExecution.getGoal() ); - return false; - } - - if ( !DtoUtils.containsAllProperties( cachedExecution, trackedProperties ) ) - { - LOGGER.info( "Build info doesn't match rules. Plugin: {}", - mojoExecution.getExecutionId() ); - return false; - } - } - return true; - } - - @Override - public boolean isForcedExecution( MavenProject project, MojoExecution execution ) - { - if ( cacheConfig.isForcedExecution( execution ) ) - { - return true; - } - String alwaysRunPlugins = project.getProperties().getProperty( "remote.cache.alwaysRunPlugins" ); - if ( alwaysRunPlugins != null ) - { - String[] alwaysRunPluginsList = split( alwaysRunPlugins, "," ); - for ( String pluginAndGoal : alwaysRunPluginsList ) - { - String[] tokens = pluginAndGoal.split( ":" ); - String alwaysRunPlugin = tokens[0]; - String alwaysRunGoal = tokens.length == 1 ? "*" : tokens[1]; - if ( Objects.equals( execution.getPlugin().getArtifactId(), alwaysRunPlugin ) - && ( "*".equals( alwaysRunGoal ) || Objects.equals( execution.getGoal(), alwaysRunGoal ) ) ) - { - return true; - } - } - } - return false; - } - - @Override - public void saveCacheReport( MavenSession session ) - { - try - { - CacheReport cacheReport = new CacheReport(); - for ( CacheResult result : cacheResults.values() ) - { - ProjectReport projectReport = new ProjectReport(); - CacheContext context = result.getContext(); - MavenProject project = context.getProject(); - projectReport.setGroupId( project.getGroupId() ); - projectReport.setArtifactId( project.getArtifactId() ); - projectReport.setChecksum( context.getInputInfo().getChecksum() ); - boolean checksumMatched = result.getStatus() != RestoreStatus.EMPTY; - projectReport.setChecksumMatched( checksumMatched ); - projectReport.setLifecycleMatched( checksumMatched && result.isSuccess() ); - projectReport.setSource( String.valueOf( result.getSource() ) ); - if ( result.getSource() == CacheSource.REMOTE ) - { - projectReport.setUrl( remoteCache.getResourceUrl( context, BUILDINFO_XML ) ); - } - else if ( result.getSource() == CacheSource.BUILD && cacheConfig.isSaveToRemote() ) - { - projectReport.setSharedToRemote( true ); - projectReport.setUrl( remoteCache.getResourceUrl( context, BUILDINFO_XML ) ); - } - cacheReport.addProject( projectReport ); - } - - String buildId = UUID.randomUUID().toString(); - localCache.saveCacheReport( buildId, session, cacheReport ); - } - catch ( Exception e ) - { - LOGGER.error( "Cannot save incremental build aggregated report", e ); - } - } - - private void populateGitInfo( Build build, MavenSession session ) - { - if ( scm == null ) - { - synchronized ( this ) - { - if ( scm == null ) - { - try - { - scm = CacheUtils.readGitInfo( session ); - } - catch ( IOException e ) - { - scm = new Scm(); - LOGGER.error( "Cannot populate git info", e ); - } - } - } - } - build.getDto().setScm( scm ); - } - - private void zipAndAttachArtifact( MavenProject project, Path dir, String classifier ) throws IOException - { - Path temp = Files.createTempFile( "maven-incremental", project.getArtifactId() ); - temp.toFile().deleteOnExit(); - CacheUtils.zip( dir, temp ); - projectHelper.attachArtifact( project, "zip", classifier, temp.toFile() ); - } - - private String pathToClassifier( Path relative ) - { - final int nameCount = relative.getNameCount(); - List segments = new ArrayList<>( nameCount + 1 ); - for ( int i = 0; i < nameCount; i++ ) - { - segments.add( relative.getName( i ).toFile().getName() ); - } - // todo handle _ in file names - return BUILD_PREFIX + StringUtils.join( segments.iterator(), FILE_SEPARATOR_SUBST ); - } - - private Path classifierToPath( Path outputDir, String classifier ) - { - classifier = StringUtils.removeStart( classifier, BUILD_PREFIX ); - final String relPath = replace( classifier, FILE_SEPARATOR_SUBST, File.separator ); - return outputDir.resolve( relPath ); - } - - private void restoreGeneratedSources( Artifact artifact, Path artifactFilePath, MavenProject project ) - throws IOException - { - final Path targetDir = Paths.get( project.getBuild().getDirectory() ); - final Path outputDir = classifierToPath( targetDir, artifact.getClassifier() ); - if ( Files.exists( outputDir ) ) - { - FileUtils.cleanDirectory( outputDir.toFile() ); - } - else - { - Files.createDirectories( outputDir ); - } - CacheUtils.unzip( artifactFilePath, outputDir ); - } - - //TODO: move to config - public void attachGeneratedSources( MavenProject project ) throws IOException - { - final Path targetDir = Paths.get( project.getBuild().getDirectory() ); - - final Path generatedSourcesDir = targetDir.resolve( "generated-sources" ); - attachDirIfNotEmpty( generatedSourcesDir, targetDir, project ); - - final Path generatedTestSourcesDir = targetDir.resolve( "generated-test-sources" ); - attachDirIfNotEmpty( generatedTestSourcesDir, targetDir, project ); - - Set sourceRoots = new TreeSet<>(); - if ( project.getCompileSourceRoots() != null ) - { - sourceRoots.addAll( project.getCompileSourceRoots() ); - } - if ( project.getTestCompileSourceRoots() != null ) - { - sourceRoots.addAll( project.getTestCompileSourceRoots() ); - } - - for ( String sourceRoot : sourceRoots ) - { - final Path sourceRootPath = Paths.get( sourceRoot ); - if ( Files.isDirectory( sourceRootPath ) - && sourceRootPath.startsWith( targetDir ) - && !( sourceRootPath.startsWith( generatedSourcesDir ) - || sourceRootPath.startsWith( generatedTestSourcesDir ) ) ) - { // dir within target - attachDirIfNotEmpty( sourceRootPath, targetDir, project ); - } - } - } - - private void attachOutputs( MavenProject project ) throws IOException - { - final List attachedDirs = cacheConfig.getAttachedOutputs(); - for ( String dir : attachedDirs ) - { - final Path targetDir = Paths.get( project.getBuild().getDirectory() ); - final Path outputDir = targetDir.resolve( dir ); - attachDirIfNotEmpty( outputDir, targetDir, project ); - } - } - - private void attachDirIfNotEmpty( Path candidateSubDir, Path parentDir, MavenProject project ) throws IOException - { - if ( Files.isDirectory( candidateSubDir ) && hasFiles( candidateSubDir ) ) - { - final Path relativePath = parentDir.relativize( candidateSubDir ); - final String classifier = pathToClassifier( relativePath ); - zipAndAttachArtifact( project, candidateSubDir, classifier ); - LOGGER.debug( "Attached directory: {}", candidateSubDir ); - } - } - - private boolean hasFiles( Path candidateSubDir ) throws IOException - { - final MutableBoolean hasFiles = new MutableBoolean(); - Files.walkFileTree( candidateSubDir, new SimpleFileVisitor() - { - @Override - public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttributes ) - { - hasFiles.setTrue(); - return FileVisitResult.TERMINATE; - } - } ); - return hasFiles.booleanValue(); - } - - private boolean isOutputArtifact( String name ) - { - List excludePatterns = cacheConfig.getExcludePatterns(); - for ( Pattern pattern : excludePatterns ) - { - if ( pattern.matcher( name ).matches() ) - { - return false; - } - } - return true; - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java deleted file mode 100644 index 535cf79e2d5b..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheDiff.java +++ /dev/null @@ -1,331 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.xml.build.Build; -import org.apache.maven.caching.xml.build.CompletedExecution; -import org.apache.maven.caching.xml.build.DigestItem; -import org.apache.maven.caching.xml.build.ProjectsInputInfo; -import org.apache.maven.caching.xml.build.PropertyValue; -import org.apache.maven.caching.xml.diff.Diff; -import org.apache.maven.caching.xml.diff.Mismatch; -import org.apache.maven.caching.xml.CacheConfig; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * Utility class for comparing 2 builds - */ -public class CacheDiff -{ - - private final CacheConfig config; - private final Build current; - private final Build baseline; - private final LinkedList report; - - public CacheDiff( Build current, Build baseline, CacheConfig config ) - { - this.current = current; - this.baseline = baseline; - this.config = config; - this.report = new LinkedList<>(); - } - - public Diff compare() - { - if ( !StringUtils.equals( current.getHashFunction(), baseline.getHashFunction() ) ) - { - addNewMismatch( - "hashFunction", - current.getHashFunction(), - baseline.getHashFunction(), - "Different algorithms render caches not comparable and cached could not be reused", - "Ensure the same algorithm as remote" - ); - } - compareEffectivePoms( current.getProjectsInputInfo(), baseline.getProjectsInputInfo() ); - compareExecutions( current.getExecutions(), baseline.getExecutions() ); - compareFiles( current.getProjectsInputInfo(), baseline.getProjectsInputInfo() ); - compareDependencies( current.getProjectsInputInfo(), baseline.getProjectsInputInfo() ); - - final Diff buildDiffType = new Diff(); - buildDiffType.getMismatches().addAll( report ); - return buildDiffType; - } - - private void compareEffectivePoms( ProjectsInputInfo current, ProjectsInputInfo baseline ) - { - Optional currentPom = findPom( current ); - String currentPomHash = currentPom.map( DigestItem::getHash ).orElse( null ); - - Optional baseLinePom = findPom( baseline ); - String baselinePomHash = baseLinePom.map( DigestItem::getHash ).orElse( null ); - - if ( !StringUtils.equals( currentPomHash, baselinePomHash ) ) - { - addNewMismatch( - "effectivePom", currentPomHash, baselinePomHash, - "Difference in effective pom suggests effectively different builds which cannot be reused", - "Compare raw content of effective poms and eliminate differences. " - + "See How-To for common techniques" - ); - } - } - - public static Optional findPom( ProjectsInputInfo projectInputs ) - { - for ( DigestItem digestItemType : projectInputs.getItems() ) - { - if ( "pom".equals( digestItemType.getType() ) ) - { - return Optional.of( digestItemType ); - - } - } - return Optional.empty(); - } - - private void compareFiles( ProjectsInputInfo current, ProjectsInputInfo baseline ) - { - final Map currentFiles = current.getItems().stream() - .filter( item -> "file".equals( item.getType() ) ) - .collect( Collectors.toMap( DigestItem::getValue, item -> item ) ); - - final Map baselineFiles = baseline.getItems().stream() - .filter( item -> "file".equals( item.getType() ) ) - .collect( Collectors.toMap( DigestItem::getValue, item -> item ) ); - - if ( !Objects.equals( currentFiles.keySet(), baselineFiles.keySet() ) ) - { - Set currentVsBaseline = diff( currentFiles.keySet(), baselineFiles.keySet() ); - Set baselineVsCurrent = diff( baselineFiles.keySet(), currentFiles.keySet() ); - - addNewMismatch( "source files", - "Remote and local cache contain different sets of input files. " - + "Added files: " + currentVsBaseline + ". Removed files: " + baselineVsCurrent, - "To match remote and local caches should have identical file sets." - + " Unnecessary and transient files must be filtered out to make file sets match" - + " - see configuration guide" - ); - return; - } - - for ( Map.Entry entry : currentFiles.entrySet() ) - { - String filePath = entry.getKey(); - DigestItem currentFile = entry.getValue(); - // should be null safe because sets are compared above for differences - final DigestItem baselineFile = baselineFiles.get( filePath ); - if ( !StringUtils.equals( currentFile.getHash(), baselineFile.getHash() ) ) - { - String reason = "File content is different."; - if ( currentFile.getEol() != null && baselineFile.getEol() != null && !StringUtils.equals( - baselineFile.getEol(), currentFile.getEol() ) ) - { - reason += " Different line endings detected (text files relevant). " - + "Remote: " + baselineFile.getEol() + ", local: " + currentFile.getEol() + "."; - } - if ( currentFile.getCharset() != null && baselineFile.getCharset() != null && !StringUtils.equals( - baselineFile.getCharset(), currentFile.getCharset() ) ) - { - reason += " Different charset detected (text files relevant). " - + "Remote: " + baselineFile.getEol() + ", local: " + currentFile.getEol() + "."; - } - - addNewMismatch( filePath, currentFile.getHash(), baselineFile.getHash(), reason, - "Different content manifests different build outcome. " - + "Ensure that difference is not caused by environment specifics, like line separators" - ); - } - } - } - - private void compareDependencies( ProjectsInputInfo current, ProjectsInputInfo baseline ) - { - final Map currentDependencies = current.getItems().stream() - .filter( item -> "dependency".equals( item.getType() ) ) - .collect( Collectors.toMap( DigestItem::getValue, item -> item ) ); - - final Map baselineDependencies = baseline.getItems().stream() - .filter( item -> "dependency".equals( item.getType() ) ) - .collect( Collectors.toMap( DigestItem::getValue, item -> item ) ); - - if ( !Objects.equals( currentDependencies.keySet(), baselineDependencies.keySet() ) ) - { - Set currentVsBaseline = diff( currentDependencies.keySet(), baselineDependencies.keySet() ); - Set baselineVsCurrent = diff( baselineDependencies.keySet(), currentDependencies.keySet() ); - - addNewMismatch( "dependencies files", - "Remote and local builds contain different sets of dependencies and cannot be matched. " - + "Added dependencies: " + currentVsBaseline + ". Removed dependencies: " - + baselineVsCurrent, - "Remote and local builds should have identical dependencies. " - + "The difference manifests changes in downstream dependencies or introduced snapshots." - ); - return; - } - - for ( Map.Entry entry : currentDependencies.entrySet() ) - { - String dependencyKey = entry.getKey(); - DigestItem currentDependency = entry.getValue(); - // null safe - sets compared for differences above - final DigestItem baselineDependency = baselineDependencies.get( dependencyKey ); - if ( !StringUtils.equals( currentDependency.getHash(), baselineDependency.getHash() ) ) - { - addNewMismatch( dependencyKey, currentDependency.getHash(), baselineDependency.getHash(), - "Downstream project or snapshot changed", - "Find downstream project and investigate difference in the downstream project. " - + "Enable fail fast mode and single threaded execution to simplify debug." - ); - } - } - } - - - private void compareExecutions( List current, List baseline ) - { - Map baselineExecutionsByKey = new HashMap<>(); - for ( CompletedExecution completedExecutionType : baseline ) - { - baselineExecutionsByKey.put( completedExecutionType.getExecutionKey(), completedExecutionType ); - } - - Map currentExecutionsByKey = new HashMap<>(); - for ( CompletedExecution e1 : current ) - { - currentExecutionsByKey.put( e1.getExecutionKey(), e1 ); - } - - // such situation normally means different poms and mismatch in effective poms, - // but in any case it is helpful to report - for ( CompletedExecution baselineExecution : baseline ) - { - if ( !currentExecutionsByKey.containsKey( baselineExecution.getExecutionKey() ) ) - { - addNewMismatch( - baselineExecution.getExecutionKey(), - "Baseline build contains excessive plugin " + baselineExecution.getExecutionKey(), - "Different set of plugins produces different build results. " - + "Exclude non-critical plugins or make sure plugin sets match" - ); - } - } - - for ( CompletedExecution currentExecution : current ) - { - if ( !baselineExecutionsByKey.containsKey( currentExecution.getExecutionKey() ) ) - { - addNewMismatch( - currentExecution.getExecutionKey(), - "Cached build doesn't contain plugin " + currentExecution.getExecutionKey(), - "Different set of plugins produces different build results. " - + "Filter out non-critical plugins or make sure remote cache always run full build " - + "with all plugins" - ); - continue; - } - - final CompletedExecution baselineExecution = - baselineExecutionsByKey.get( currentExecution.getExecutionKey() ); - comparePlugins( currentExecution, baselineExecution ); - } - } - - private void comparePlugins( CompletedExecution current, CompletedExecution baseline ) - { - // TODO add support for skip values - final List trackedProperties = new ArrayList<>(); - for ( PropertyValue propertyValueType : current.getProperties() ) - { - if ( propertyValueType.isTracked() ) - { - trackedProperties.add( propertyValueType ); - } - } - if ( trackedProperties.isEmpty() ) - { - return; - } - - final Map baselinePropertiesByName = new HashMap<>(); - for ( PropertyValue propertyValueType : baseline.getProperties() ) - { - baselinePropertiesByName.put( propertyValueType.getName(), propertyValueType ); - } - - for ( PropertyValue p : trackedProperties ) - { - final PropertyValue baselineValue = baselinePropertiesByName.get( p.getName() ); - if ( baselineValue == null || !StringUtils.equals( baselineValue.getValue(), p.getValue() ) ) - { - addNewMismatch( - p.getName(), - p.getValue(), - baselineValue == null ? null : baselineValue.getValue(), - "Plugin: " + current.getExecutionKey() - + " has mismatch in tracked property and cannot be reused", - "Align properties between remote and local build or remove property from tracked " - + "list if mismatch could be tolerated. In some cases it is possible to add skip value " - + "to ignore lax mismatch" - ); - } - } - } - - private void addNewMismatch( String item, String current, String baseline, String reason, - String resolution ) - { - final Mismatch mismatch = new Mismatch(); - mismatch.setItem( item ); - mismatch.setCurrent( current ); - mismatch.setBaseline( baseline ); - mismatch.setReason( reason ); - mismatch.setResolution( resolution ); - report.add( mismatch ); - } - - private void addNewMismatch( String property, String reason, String resolution ) - { - final Mismatch mismatchType = new Mismatch(); - mismatchType.setItem( property ); - mismatchType.setReason( reason ); - mismatchType.setResolution( resolution ); - report.add( mismatchType ); - } - - private static Set diff( Set a, Set b ) - { - return a.stream() - .filter( v -> !b.contains( v ) ) - .collect( Collectors.toSet() ); - - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheLifecycleParticipant.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheLifecycleParticipant.java deleted file mode 100644 index 9554f3027c5f..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheLifecycleParticipant.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import javax.inject.Inject; -import javax.inject.Named; - -import org.apache.maven.AbstractMavenLifecycleParticipant; -import org.apache.maven.MavenExecutionException; -import org.apache.maven.SessionScoped; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.execution.MavenSession; - -@SessionScoped -@Named -@SuppressWarnings( "unused" ) -public class CacheLifecycleParticipant extends AbstractMavenLifecycleParticipant -{ - private final CacheConfig cacheConfig; - private final CacheController cacheController; - - @Inject - public CacheLifecycleParticipant( CacheConfig cacheConfig, CacheController cacheController ) - { - this.cacheConfig = cacheConfig; - this.cacheController = cacheController; - } - - @Override - public void afterSessionEnd( MavenSession session ) throws MavenExecutionException - { - if ( cacheConfig.isEnabled() ) - { - cacheController.saveCacheReport( session ); - } - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheRepository.java deleted file mode 100644 index 1cbd4d0d6824..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheRepository.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.caching.xml.report.CacheReport; -import org.apache.maven.caching.xml.Build; -import org.apache.maven.execution.MavenSession; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.util.Optional; - -/** - * Cache repository. - */ -public interface CacheRepository -{ - - @Nonnull - Optional findBuild( CacheContext context ) throws IOException; - - void saveBuildInfo( CacheResult cacheResult, Build build ) throws IOException; - - void saveArtifactFile( CacheResult cacheResult, Artifact artifact ) throws IOException; - - void saveCacheReport( String buildId, MavenSession session, CacheReport cacheReport ) throws IOException; -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheResult.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheResult.java deleted file mode 100644 index e96abe6bb46e..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheResult.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.caching.xml.Build; -import org.apache.maven.caching.xml.CacheSource; - -import static java.util.Objects.requireNonNull; - -/** - * CacheResult - */ -public class CacheResult -{ - private final RestoreStatus status; - private final Build build; - private final CacheContext context; - - private CacheResult( RestoreStatus status, Build build, CacheContext context ) - { - this.status = requireNonNull( status ); - this.build = build; - this.context = context; - } - - public static CacheResult empty( CacheContext context ) - { - requireNonNull( context ); - return new CacheResult( RestoreStatus.EMPTY, null, context ); - } - - public static CacheResult empty() - { - return new CacheResult( RestoreStatus.EMPTY, null, null ); - } - - public static CacheResult failure( Build build, CacheContext context ) - { - requireNonNull( build ); - requireNonNull( context ); - return new CacheResult( RestoreStatus.FAILURE, build, context ); - } - - public static CacheResult success( Build build, CacheContext context ) - { - requireNonNull( build ); - requireNonNull( context ); - return new CacheResult( RestoreStatus.SUCCESS, build, context ); - } - - public static CacheResult partialSuccess( Build build, CacheContext context ) - { - requireNonNull( build ); - requireNonNull( context ); - return new CacheResult( RestoreStatus.PARTIAL, build, context ); - } - - public static CacheResult failure( CacheContext context ) - { - requireNonNull( context ); - return new CacheResult( RestoreStatus.FAILURE, null, context ); - } - - public static CacheResult rebuilded( CacheResult orig, Build build ) - { - requireNonNull( orig ); - requireNonNull( build ); - return new CacheResult( orig.status, build, orig.context ); - } - - public boolean isSuccess() - { - return status == RestoreStatus.SUCCESS; - } - - public Build getBuildInfo() - { - return build; - } - - public CacheSource getSource() - { - return build != null ? build.getSource() : null; - } - - public CacheContext getContext() - { - return context; - } - - public boolean isPartialSuccess() - { - return status == RestoreStatus.PARTIAL; - } - - public RestoreStatus getStatus() - { - return status; - } - - public boolean isFinal() - { - return build != null && build.getDto().is_final(); - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java deleted file mode 100644 index 32c97e9f15d6..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/CacheUtils.java +++ /dev/null @@ -1,233 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.caching.xml.build.Scm; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Dependency; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.project.MavenProject; -import org.eclipse.aether.SessionData; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.FileTime; -import java.util.Arrays; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.function.Supplier; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; - -import static org.apache.commons.lang3.StringUtils.removeStart; -import static org.apache.commons.lang3.StringUtils.trim; -import static org.apache.maven.artifact.Artifact.LATEST_VERSION; -import static org.apache.maven.artifact.Artifact.SNAPSHOT_VERSION; - -/** - * ProjectUtils - */ -public class CacheUtils -{ - - public static boolean isPom( MavenProject project ) - { - return project.getPackaging().equals( "pom" ); - } - - public static boolean isPom( Dependency dependency ) - { - return dependency.getType().equals( "pom" ); - } - - public static boolean isSnapshot( String version ) - { - return version.endsWith( SNAPSHOT_VERSION ) || version.endsWith( LATEST_VERSION ); - } - - public static String normalizedName( Artifact artifact ) - { - if ( artifact.getFile() == null ) - { - return null; - } - - StringBuilder filename = new StringBuilder( artifact.getArtifactId() ); - - if ( artifact.hasClassifier() ) - { - filename.append( "-" ).append( artifact.getClassifier() ); - } - - final ArtifactHandler artifactHandler = artifact.getArtifactHandler(); - if ( artifactHandler != null && StringUtils.isNotBlank( artifactHandler.getExtension() ) ) - { - filename.append( "." ).append( artifactHandler.getExtension() ); - } - return filename.toString(); - } - - public static String mojoExecutionKey( MojoExecution mojo ) - { - return StringUtils.join( Arrays.asList( - StringUtils.defaultIfEmpty( mojo.getExecutionId(), "emptyExecId" ), - StringUtils.defaultIfEmpty( mojo.getGoal(), "emptyGoal" ), - StringUtils.defaultIfEmpty( mojo.getLifecyclePhase(), "emptyLifecyclePhase" ), - StringUtils.defaultIfEmpty( mojo.getArtifactId(), "emptyArtifactId" ), - StringUtils.defaultIfEmpty( mojo.getGroupId(), "emptyGroupId" ) ), ":" ); - } - - public static Path getMultimoduleRoot( MavenSession session ) - { - return session.getRequest().getMultiModuleProjectDirectory().toPath(); - } - - public static Scm readGitInfo( MavenSession session ) throws IOException - { - final Scm scmCandidate = new Scm(); - final Path gitDir = getMultimoduleRoot( session ).resolve( ".git" ); - if ( Files.isDirectory( gitDir ) ) - { - final Path headFile = gitDir.resolve( "HEAD" ); - if ( Files.exists( headFile ) ) - { - String headRef = readFirstLine( headFile, "" ); - if ( headRef.startsWith( "ref: " ) ) - { - String branch = trim( removeStart( headRef, "ref: " ) ); - scmCandidate.setSourceBranch( branch ); - final Path refPath = gitDir.resolve( branch ); - if ( Files.exists( refPath ) ) - { - String revision = readFirstLine( refPath, "" ); - scmCandidate.setRevision( trim( revision ) ); - } - } - else - { - scmCandidate.setSourceBranch( headRef ); - scmCandidate.setRevision( headRef ); - } - } - } - return scmCandidate; - } - - - private static String readFirstLine( Path path, String defaultValue ) throws IOException - { - return Files.lines( path, StandardCharsets.UTF_8 ).findFirst().orElse( defaultValue ); - } - - - public static T getLast( List list ) - { - int size = list.size(); - if ( size > 0 ) - { - return list.get( size - 1 ); - } - throw new NoSuchElementException(); - } - - public static T getOrCreate( MavenSession session, Object key, Supplier supplier ) - { - SessionData data = session.getRepositorySession().getData(); - while ( true ) - { - T t = (T) data.get( key ); - if ( t == null ) - { - t = supplier.get(); - if ( data.set( key, null, t ) ) - { - continue; - } - } - return t; - } - } - - public static boolean isArchive( File file ) - { - String fileName = file.getName(); - if ( !file.isFile() || file.isHidden() ) - { - return false; - } - return StringUtils.endsWithAny( fileName, ".jar", ".zip", ".war", ".ear" ); - } - - - public static void zip( Path dir, Path zip ) throws IOException - { - try ( ZipOutputStream zipOutputStream = new ZipOutputStream( Files.newOutputStream( zip ) ) ) - { - Files.walkFileTree( dir, new SimpleFileVisitor() - { - @Override - public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttributes ) - throws IOException - { - final ZipEntry zipEntry = new ZipEntry( dir.relativize( path ).toString() ); - zipOutputStream.putNextEntry( zipEntry ); - Files.copy( path, zipOutputStream ); - zipOutputStream.closeEntry(); - return FileVisitResult.CONTINUE; - } - } ); - } - } - - public static void unzip( Path zip, Path out ) throws IOException - { - try ( ZipInputStream zis = new ZipInputStream( Files.newInputStream( zip ) ) ) - { - ZipEntry entry = zis.getNextEntry(); - while ( entry != null ) - { - Path file = out.resolve( entry.getName() ); - if ( entry.isDirectory() ) - { - Files.createDirectory( file ); - } - else - { - Path parent = file.getParent(); - Files.createDirectories( parent ); - Files.copy( zis, file ); - } - Files.setLastModifiedTime( file, FileTime.fromMillis( entry.getTime() ) ); - entry = zis.getNextEntry(); - } - } - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojosExecutionStrategy.java b/maven-caching/src/main/java/org/apache/maven/caching/CachingMojosExecutionStrategy.java deleted file mode 100644 index 4d8211c5d63e..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/CachingMojosExecutionStrategy.java +++ /dev/null @@ -1,330 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.List; -import java.util.Map; - -import javax.annotation.Priority; -import javax.inject.Inject; -import javax.inject.Named; - -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.SessionScoped; -import org.apache.maven.caching.xml.Build; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.CacheState; -import org.apache.maven.caching.xml.DtoUtils; -import org.apache.maven.caching.xml.build.CompletedExecution; -import org.apache.maven.caching.xml.config.TrackedProperty; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.execution.MojoExecutionEvent; -import org.apache.maven.lifecycle.LifecycleExecutionException; -import org.apache.maven.plugin.MavenPluginManager; -import org.apache.maven.plugin.Mojo; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.MojoExecution.Source; -import org.apache.maven.plugin.MojoExecutionRunner; -import org.apache.maven.plugin.MojosExecutionStrategy; -import org.apache.maven.plugin.PluginConfigurationException; -import org.apache.maven.plugin.PluginContainerException; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.ReflectionUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.apache.maven.caching.CacheUtils.mojoExecutionKey; -import static org.apache.maven.caching.checksum.KeyUtils.getVersionlessProjectKey; -import static org.apache.maven.caching.xml.CacheState.DISABLED; -import static org.apache.maven.caching.xml.CacheState.INITIALIZED; - - -/** - *

    - * Cache-enabled version of the MojoExecutor - *

    - */ -@SessionScoped -@Named -@Priority( 10 ) -@SuppressWarnings( "unused" ) -public class CachingMojosExecutionStrategy implements MojosExecutionStrategy -{ - private static final Logger LOGGER = LoggerFactory.getLogger( CachingMojosExecutionStrategy.class ); - - private final CacheController cacheController; - private final CacheConfig cacheConfig; - private final MojoParametersListener mojoListener; - private final LifecyclePhasesHelper lifecyclePhasesHelper; - private final MavenPluginManager mavenPluginManager; - - @Inject - public CachingMojosExecutionStrategy( - CacheController cacheController, - CacheConfig cacheConfig, - MojoParametersListener mojoListener, - LifecyclePhasesHelper lifecyclePhasesHelper, - MavenPluginManager mavenPluginManager ) - { - this.cacheController = cacheController; - this.cacheConfig = cacheConfig; - this.mojoListener = mojoListener; - this.lifecyclePhasesHelper = lifecyclePhasesHelper; - this.mavenPluginManager = mavenPluginManager; - } - - public void execute( List mojoExecutions, - MavenSession session, - MojoExecutionRunner mojoExecutionRunner ) - throws LifecycleExecutionException - { - final MavenProject project = session.getCurrentProject(); - final Source source = getSource( mojoExecutions ); - - // execute clean bound goals before restoring to not interfere/slowdown clean - CacheState cacheState = DISABLED; - CacheResult result = CacheResult.empty(); - if ( source == Source.LIFECYCLE ) - { - List cleanPhase = lifecyclePhasesHelper.getCleanSegment( mojoExecutions ); - for ( MojoExecution mojoExecution : cleanPhase ) - { - mojoExecutionRunner.run( mojoExecution ); - } - cacheState = cacheConfig.initialize(); - if ( cacheState == INITIALIZED ) - { - result = cacheController.findCachedBuild( session, project, mojoExecutions ); - } - } - - boolean restorable = result.isSuccess() || result.isPartialSuccess(); - boolean restored = result.isSuccess(); // if partially restored need to save increment - if ( restorable ) - { - restored &= restoreProject( result, mojoExecutions, mojoExecutionRunner, cacheConfig ); - } - else - { - for ( MojoExecution mojoExecution : mojoExecutions ) - { - if ( source == Source.CLI - || mojoExecution.getLifecyclePhase() == null - || lifecyclePhasesHelper.isLaterPhaseThanClean( mojoExecution.getLifecyclePhase() ) ) - { - mojoExecutionRunner.run( mojoExecution ); - } - } - } - - if ( cacheState == INITIALIZED && ( !restorable || !restored ) ) - { - final Map executionEvents = mojoListener.getProjectExecutions( project ); - cacheController.save( result, mojoExecutions, executionEvents ); - } - - if ( cacheConfig.isFailFast() && !result.isSuccess() ) - { - throw new LifecycleExecutionException( - "Failed to restore project[" + getVersionlessProjectKey( project ) + "] from cache, failing build.", - project ); - } - } - - private Source getSource( List mojoExecutions ) - { - if ( mojoExecutions == null || mojoExecutions.isEmpty() ) - { - return null; - } - for ( MojoExecution mojoExecution : mojoExecutions ) - { - if ( mojoExecution.getSource() == Source.CLI ) - { - return Source.CLI; - } - } - return Source.LIFECYCLE; - } - - private boolean restoreProject( CacheResult cacheResult, - List mojoExecutions, - MojoExecutionRunner mojoExecutionRunner, - CacheConfig cacheConfig ) throws LifecycleExecutionException - { - final Build build = cacheResult.getBuildInfo(); - final MavenProject project = cacheResult.getContext().getProject(); - final MavenSession session = cacheResult.getContext().getSession(); - final List cachedSegment = lifecyclePhasesHelper.getCachedSegment( mojoExecutions, build ); - - boolean restored = cacheController.restoreProjectArtifacts( cacheResult ); - if ( !restored ) - { - LOGGER.info( "Cannot restore project artifacts, continuing with non cached build" ); - return false; - } - - for ( MojoExecution cacheCandidate : cachedSegment ) - { - if ( cacheController.isForcedExecution( project, cacheCandidate ) ) - { - LOGGER.info( "Mojo execution is forced by project property: {}", - cacheCandidate.getMojoDescriptor().getFullGoalName() ); - mojoExecutionRunner.run( cacheCandidate ); - } - else - { - restored = verifyCacheConsistency( cacheCandidate, build, project, session, - mojoExecutionRunner, cacheConfig ); - if ( !restored ) - { - break; - } - } - } - - if ( !restored ) - { - // cleanup partial state - project.getArtifact().setFile( null ); - project.getArtifact().setResolved( false ); - project.getAttachedArtifacts().clear(); - mojoListener.remove( project ); - // build as usual - for ( MojoExecution mojoExecution : cachedSegment ) - { - mojoExecutionRunner.run( mojoExecution ); - } - } - - for ( MojoExecution mojoExecution : lifecyclePhasesHelper.getPostCachedSegment( mojoExecutions, build ) ) - { - mojoExecutionRunner.run( mojoExecution ); - } - return restored; - } - - private boolean verifyCacheConsistency( MojoExecution cacheCandidate, - Build cachedBuild, - MavenProject project, - MavenSession session, - MojoExecutionRunner mojoExecutionRunner, - CacheConfig cacheConfig ) throws LifecycleExecutionException - { - long createdTimestamp = System.currentTimeMillis(); - boolean consistent = true; - - if ( !cacheConfig.getTrackedProperties( cacheCandidate ).isEmpty() ) - { - Mojo mojo = null; - try - { - mojo = mavenPluginManager.getConfiguredMojo( Mojo.class, session, cacheCandidate ); - final CompletedExecution completedExecution = cachedBuild.findMojoExecutionInfo( cacheCandidate ); - final String fullGoalName = cacheCandidate.getMojoDescriptor().getFullGoalName(); - - if ( completedExecution != null - && !isParamsMatched( cacheCandidate, mojo, completedExecution ) ) - { - LOGGER.info( "Mojo cached parameters mismatch with actual, forcing full project build. Mojo: {}", - fullGoalName ); - consistent = false; - } - - if ( consistent ) - { - long elapsed = System.currentTimeMillis() - createdTimestamp; - LOGGER.info( "Skipping plugin execution (reconciled in {} millis): {}", elapsed, fullGoalName ); - } - - if ( LOGGER.isDebugEnabled() ) - { - LOGGER.debug( "Checked {}, resolved mojo: {}, cached params: {}", - fullGoalName, mojo, completedExecution ); - } - } - catch ( PluginContainerException | PluginConfigurationException e ) - { - throw new LifecycleExecutionException( "Cannot get configured mojo", e ); - } - finally - { - if ( mojo != null ) - { - mavenPluginManager.releaseMojo( mojo, cacheCandidate ); - } - } - } - else - { - LOGGER.info( "Skipping plugin execution (cached): {}", - cacheCandidate.getMojoDescriptor().getFullGoalName() ); - } - - return consistent; - } - - private boolean isParamsMatched( MojoExecution mojoExecution, - Mojo mojo, - CompletedExecution completedExecution ) - { - List tracked = cacheConfig.getTrackedProperties( mojoExecution ); - - for ( TrackedProperty trackedProperty : tracked ) - { - final String propertyName = trackedProperty.getPropertyName(); - - String expectedValue = DtoUtils.findPropertyValue( propertyName, completedExecution ); - if ( expectedValue == null && trackedProperty.getDefaultValue() != null ) - { - expectedValue = trackedProperty.getDefaultValue(); - } - - final String currentValue; - try - { - currentValue = String.valueOf( ReflectionUtils.getValueIncludingSuperclasses( propertyName, mojo ) ); - } - catch ( IllegalAccessException e ) - { - LOGGER.error( "Cannot extract plugin property {} from mojo {}", propertyName, mojo, e ); - return false; - } - - if ( !StringUtils.equals( currentValue, expectedValue ) ) - { - if ( !StringUtils.equals( currentValue, trackedProperty.getSkipValue() ) ) - { - LOGGER.info( "Plugin parameter mismatch found. Parameter: {}, expected: {}, actual: {}", - propertyName, expectedValue, currentValue ); - return false; - } - else - { - LOGGER.warn( "Cache contains plugin execution with skip flag and might be incomplete. " - + "Property: {}, execution {}", - propertyName, mojoExecutionKey( mojoExecution ) ); - } - } - } - return true; - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/DefaultMultiModuleSupport.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultMultiModuleSupport.java deleted file mode 100644 index a02c8a605f24..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/DefaultMultiModuleSupport.java +++ /dev/null @@ -1,224 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.SessionScoped; -import org.apache.maven.caching.checksum.KeyUtils; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.config.Discovery; -import org.apache.maven.caching.xml.config.MultiModule; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.DefaultProjectBuildingRequest; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.ProjectBuilder; -import org.apache.maven.project.ProjectBuildingException; -import org.apache.maven.project.ProjectBuildingRequest; -import org.apache.maven.project.ProjectBuildingResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import javax.inject.Named; -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Properties; -import java.util.Set; -import java.util.TreeSet; -import java.util.function.Function; -import java.util.stream.Collectors; - -@SessionScoped -@Named -public class DefaultMultiModuleSupport implements MultiModuleSupport -{ - - private static final Logger LOGGER = LoggerFactory.getLogger( DefaultMultiModuleSupport.class ); - - private final ProjectBuilder projectBuilder; - private final CacheConfig cacheConfig; - private final MavenSession session; - - private volatile boolean built; - private volatile Map projectMap; - private volatile Map sessionProjectMap; - - @Inject - public DefaultMultiModuleSupport( ProjectBuilder projectBuilder, - CacheConfig cacheConfig, - MavenSession session ) - { - this.projectBuilder = projectBuilder; - this.cacheConfig = cacheConfig; - this.session = session; - } - - @Override - public boolean isPartOfSession( String groupId, String artifactId, String version ) - { - return getProjectMap( session ) - .containsKey( KeyUtils.getProjectKey( groupId, artifactId, version ) ); - } - - @Override - public Optional tryToResolveProject( String groupId, String artifactId, String version ) - { - return Optional.ofNullable( getMultiModuleProjectsMap() - .get( KeyUtils.getProjectKey( groupId, artifactId, version ) ) ); - } - - @Override - public boolean isPartOfMultiModule( String groupId, String artifactId, String version ) - { - String projectKey = KeyUtils.getProjectKey( groupId, artifactId, version ); - return getProjectMap( session ).containsKey( projectKey ) - || getMultiModuleProjectsMap().containsKey( projectKey ); - } - - private Map getProjectMap( MavenSession session ) - { - if ( sessionProjectMap != null ) - { - return sessionProjectMap; - } - sessionProjectMap = session.getProjects().stream().collect( Collectors.toMap( - KeyUtils::getProjectKey, - Function.identity() - ) ); - return sessionProjectMap; - } - - private Map getMultiModuleProjectsMap() - { - if ( projectMap != null ) - { - return projectMap; - } - return getMultiModuleProjectsMapInner( session ); - } - - private synchronized Map getMultiModuleProjectsMapInner( MavenSession session ) - { - if ( projectMap != null ) - { - return projectMap; - } - buildModel( session ); - return projectMap; - } - - private synchronized void buildModel( MavenSession session ) - { - if ( built ) - { - return; - } - - Optional multiModuleDiscovery = - Optional.ofNullable( cacheConfig.getMultiModule() ).map( MultiModule::getDiscovery ); - - //no discovery configuration, use only projects in session - if ( !multiModuleDiscovery.isPresent() ) - { - projectMap = buildProjectMap( session.getProjects() ); - return; - } - - Set scanProfiles = new TreeSet<>( - multiModuleDiscovery - .map( Discovery::getScanProfiles ) - .orElse( Collections.emptyList() ) ); - MavenProject currentProject = session.getCurrentProject(); - File multiModulePomFile = getMultiModulePomFile( session ); - - ProjectBuildingRequest projectBuildingRequest = currentProject.getProjectBuildingRequest(); - boolean profilesMatched = projectBuildingRequest.getActiveProfileIds().containsAll( scanProfiles ); - - //we are building from root with the same profiles, no need to re-scan the whole multi-module project - if ( currentProject.getFile().getAbsolutePath().equals( multiModulePomFile.getAbsolutePath() ) - && profilesMatched ) - { - projectMap = buildProjectMap( session.getProjects() ); - return; - } - - long t0 = System.currentTimeMillis(); - - ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest( projectBuildingRequest ); - //clear properties because after first build request some properties could be set to profiles - //these properties could change effective pom when we try to rebuild whole multi module project again - //for example the first model build process do not resolve ${os.detected.classifier} - //but once build completed this property is set to profile - //if we try to rebuild model for the whole project here string interpolator replaces this value - //and effective pom could be different (depending on OS) if this property is used in pom.xml - buildingRequest.setProfiles( - buildingRequest.getProfiles().stream() - .peek( it -> it.setProperties( new Properties() ) ) - .collect( Collectors.toList() ) - ); - if ( !profilesMatched ) - { - Set profiles = new LinkedHashSet<>( buildingRequest.getActiveProfileIds() ); - //remove duplicates - profiles.addAll( scanProfiles ); - buildingRequest.setActiveProfileIds( new ArrayList<>( profiles ) ); - } - try - { - List buildingResults = projectBuilder.build( - Collections.singletonList( multiModulePomFile ), - true, - buildingRequest - ); - LOGGER.info( "Multi module project model calculated [activeProfiles={}, time={} ms ", - buildingRequest.getActiveProfileIds(), System.currentTimeMillis() - t0 ); - - List projectList = buildingResults.stream().map( ProjectBuildingResult::getProject ) - .collect( Collectors.toList() ); - projectMap = buildProjectMap( projectList ); - - } - catch ( ProjectBuildingException e ) - { - LOGGER.error( "Unable to build model", e ); - } - finally - { - built = true; - } - } - - private Map buildProjectMap( List projectList ) - { - return projectList.stream().collect( Collectors.toMap( - KeyUtils::getProjectKey, - Function.identity() - ) ); - } - - private static File getMultiModulePomFile( MavenSession session ) - { - return CacheUtils.getMultimoduleRoot( session ).resolve( "pom.xml" ).toFile(); - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/DefaultNormalizedModelProvider.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultNormalizedModelProvider.java deleted file mode 100644 index c263d5fe17ed..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/DefaultNormalizedModelProvider.java +++ /dev/null @@ -1,180 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.SessionScoped; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.lifecycle.internal.builder.BuilderCommon; -import org.apache.maven.model.Build; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Model; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginExecution; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -import javax.inject.Inject; -import javax.inject.Named; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.stream.Collectors; - -@SessionScoped -@Named -public class DefaultNormalizedModelProvider implements NormalizedModelProvider -{ - private static final String NORMALIZED_VERSION = "cache-extension-version"; - - private final CacheConfig cacheConfig; - private final MultiModuleSupport multiModuleSupport; - private final ConcurrentMap modelCache = new ConcurrentHashMap<>(); - - @Inject - public DefaultNormalizedModelProvider( MultiModuleSupport multiModuleSupport, CacheConfig cacheConfig ) - { - this.multiModuleSupport = multiModuleSupport; - this.cacheConfig = cacheConfig; - } - - @Override - public Model normalizedModel( MavenProject project ) - { - MavenProject validatedProject = Objects.requireNonNull( project, "project" ); - return modelCache.computeIfAbsent( BuilderCommon.getKey( validatedProject ), - k -> normalizedModelInner( validatedProject ) ); - } - - private Model normalizedModelInner( MavenProject project ) - { - //prefer project from multimodule than reactor because effective pom of reactor project - //could be built with maven local/remote dependencies but not with artifacts from cache - MavenProject projectToNormalize = multiModuleSupport.tryToResolveProject( - project.getGroupId(), - project.getArtifactId(), - project.getVersion() ) - .orElse( project ); - Model prototype = projectToNormalize.getModel(); - - //TODO validate status of the model - it should be in resolved state - Model resultModel = new Model(); - - resultModel.setGroupId( prototype.getGroupId() ); - resultModel.setArtifactId( prototype.getArtifactId() ); - //does not make sense to add project version to calculate hash - resultModel.setVersion( NORMALIZED_VERSION ); - resultModel.setModules( prototype.getModules() ); - - resultModel.setDependencies( normalizeDependencies( prototype.getDependencies() ) ); - - org.apache.maven.model.Build protoBuild = prototype.getBuild(); - if ( protoBuild == null ) - { - return resultModel; - } - - Build build = new Build(); - List plugins = prototype.getBuild().getPlugins(); - build.setPlugins( normalizePlugins( plugins ) ); - resultModel.setBuild( build ); - return resultModel; - } - - private List normalizeDependencies( Collection source ) - { - return source.stream().map( it -> - { - if ( !multiModuleSupport.isPartOfMultiModule( it.getGroupId(), it.getArtifactId(), it.getVersion() ) ) - { - return it; - } - Dependency cloned = it.clone(); - cloned.setVersion( NORMALIZED_VERSION ); - return cloned; - } ).sorted( DefaultNormalizedModelProvider::compareDependencies ).collect( Collectors.toList() ); - } - - private List normalizePlugins( List plugins ) - { - if ( plugins.isEmpty() ) - { - return plugins; - } - - return plugins.stream().map( - plugin -> - { - Plugin copy = plugin.clone(); - List excludeProperties = cacheConfig.getEffectivePomExcludeProperties( copy ); - removeBlacklistedAttributes( (Xpp3Dom) copy.getConfiguration(), excludeProperties ); - for ( PluginExecution execution : copy.getExecutions() ) - { - Xpp3Dom config = (Xpp3Dom) execution.getConfiguration(); - removeBlacklistedAttributes( config, excludeProperties ); - } - - copy.setDependencies( - normalizeDependencies( - copy.getDependencies() - .stream() - .sorted( DefaultNormalizedModelProvider::compareDependencies ) - .collect( Collectors.toList() ) - ) - ); - if ( multiModuleSupport.isPartOfMultiModule( - copy.getGroupId(), - copy.getArtifactId(), - copy.getVersion() ) ) - { - copy.setVersion( NORMALIZED_VERSION ); - } - return copy; - } - ).collect( Collectors.toList() ); - } - - private void removeBlacklistedAttributes( Xpp3Dom node, List excludeProperties ) - { - if ( node == null ) - { - return; - } - - Xpp3Dom[] children = node.getChildren(); - int indexToRemove = 0; - for ( Xpp3Dom child : children ) - { - if ( excludeProperties.contains( child.getName() ) ) - { - node.removeChild( indexToRemove ); - continue; - } - indexToRemove++; - removeBlacklistedAttributes( child, excludeProperties ); - } - } - - private static int compareDependencies( Dependency d1, Dependency d2 ) - { - return d1.getArtifactId().compareTo( d2.getArtifactId() ); - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java deleted file mode 100644 index 31d7cb2ec663..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/DefaultPluginScanConfig.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.caching.xml.config.DirScanConfig; - -import javax.annotation.Nonnull; - -/** - * DefaultPluginScanConfig - */ -public class DefaultPluginScanConfig implements PluginScanConfig -{ - - @Override - public boolean isSkip() - { - return false; - } - - @Override - public boolean accept( String propertyName ) - { - return true; - } - - @Override - @Nonnull - public PluginScanConfig mergeWith( PluginScanConfig overrideSource ) - { - return overrideSource; - } - - @Nonnull - @Override - public ScanConfigProperties getTagScanProperties( String tagName ) - { - return new ScanConfigProperties( true, "*" ); - } - - @Override - public DirScanConfig dto() - { - return null; - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/DefaultProjectInputCalculator.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultProjectInputCalculator.java deleted file mode 100644 index 004166b7cb88..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/DefaultProjectInputCalculator.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.SessionScoped; -import org.apache.maven.caching.checksum.MavenProjectInput; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.build.ProjectsInputInfo; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.lifecycle.internal.builder.BuilderCommon; -import org.apache.maven.project.MavenProject; -import org.apache.maven.repository.RepositorySystem; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import javax.inject.Named; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -@SessionScoped -@Named -public class DefaultProjectInputCalculator implements ProjectInputCalculator -{ - private static final Logger LOGGER = LoggerFactory.getLogger( DefaultProjectInputCalculator.class ); - - private final MavenSession mavenSession; - private final RemoteCacheRepository remoteCache; - private final CacheConfig cacheConfig; - private final RepositorySystem repoSystem; - private final NormalizedModelProvider normalizedModelProvider; - private final MultiModuleSupport multiModuleSupport; - - private final ConcurrentMap checkSumMap = new ConcurrentHashMap<>(); - - private static final ThreadLocal> CURRENTLY_CALCULATING = ThreadLocal.withInitial( - LinkedHashSet::new - ); - - @Inject - public DefaultProjectInputCalculator( MavenSession mavenSession, - RemoteCacheRepository remoteCache, - CacheConfig cacheConfig, - RepositorySystem repoSystem, - NormalizedModelProvider rawModelProvider, - MultiModuleSupport multiModuleSupport ) - { - this.mavenSession = mavenSession; - this.remoteCache = remoteCache; - this.cacheConfig = cacheConfig; - this.repoSystem = repoSystem; - this.normalizedModelProvider = rawModelProvider; - this.multiModuleSupport = multiModuleSupport; - } - - @Override - public ProjectsInputInfo calculateInput( MavenProject project ) - { - LOGGER.info( "Going to calculate checksum for project [groupId=" + project.getGroupId() - + ", artifactId=" + project.getArtifactId() + "]" ); - - String key = BuilderCommon.getKey( project ); - //NOTE: Do not use ConcurrentHashMap.computeIfAbsent() here because of recursive calls - //this could lead to runtime exception - IllegalStateException("Recursive update") - //in jdk 8 the result of attempt to modify items with the same hash code could lead to infinite loop - ProjectsInputInfo projectsInputInfo = checkSumMap.get( key ); - if ( projectsInputInfo != null ) - { - return projectsInputInfo; - } - projectsInputInfo = calculateInputInternal( key, project ); - checkSumMap.put( key, projectsInputInfo ); - return projectsInputInfo; - - } - - private ProjectsInputInfo calculateInputInternal( String key, - MavenProject project ) - { - Set projectsSet = CURRENTLY_CALCULATING.get(); - - if ( !projectsSet.add( key ) ) - { - throw new IllegalStateException( "Checksum for project is already calculating. " - + "Is there a cyclic dependencies? [project=" + key - + ", setOfCalculatingProjects=" + projectsSet + "]" ); - } - try - { - final MavenProjectInput input = new MavenProjectInput( - project, - normalizedModelProvider, - multiModuleSupport, - this, - mavenSession, - cacheConfig, - repoSystem, - remoteCache - ); - return input.calculateChecksum(); - } - catch ( Exception e ) - { - throw new RuntimeException( "Failed to calculate checksums for " + project.getArtifactId(), e ); - } - finally - { - projectsSet.remove( key ); - } - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/DefaultRestoredArtifactHandler.java b/maven-caching/src/main/java/org/apache/maven/caching/DefaultRestoredArtifactHandler.java deleted file mode 100644 index a3d3399b1b69..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/DefaultRestoredArtifactHandler.java +++ /dev/null @@ -1,164 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.IOUtils; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.project.MavenProject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Enumeration; -import java.util.jar.Attributes; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.jar.JarOutputStream; - -@Singleton -@Named -public class DefaultRestoredArtifactHandler implements RestoredArtifactHandler -{ - - private static final Logger LOGGER = LoggerFactory.getLogger( DefaultRestoredArtifactHandler.class ); - private static final String DIR_NAME = "cache-build-tmp"; - - private final boolean adjustMetaInfVersion; - - @Inject - public DefaultRestoredArtifactHandler( CacheConfig cacheConfig ) - { - this.adjustMetaInfVersion = cacheConfig.adjustMetaInfVersion(); - } - - @Override - public Path adjustArchiveArtifactVersion( MavenProject project, String originalArtifactVersion, Path artifactFile ) - throws IOException - { - if ( !adjustMetaInfVersion ) - { - //option is disabled in cache configuration, return file as is - return artifactFile; - } - - File file = artifactFile.toFile(); - if ( project.getVersion().equals( originalArtifactVersion ) || !CacheUtils.isArchive( file ) ) - { - //versions of artifact and building project are the same or this is not an archive, return file as is - return artifactFile; - } - - File tempDirName = Paths.get( project.getBuild().getDirectory() ) - .normalize() - .resolve( DIR_NAME ) - .toFile(); - if ( tempDirName.mkdirs() ) - { - LOGGER.debug( "Temporary directory to restore artifact was created [artifactFile={}, " - + "originalVersion={}, tempDir={}]", - artifactFile, originalArtifactVersion, tempDirName ); - } - - String currentVersion = project.getVersion(); - File tmpJarFile = File.createTempFile( artifactFile.toFile().getName(), - '.' + FilenameUtils.getExtension( file.getName() ), tempDirName ); - tmpJarFile.deleteOnExit(); - String originalImplVersion = Attributes.Name.IMPLEMENTATION_VERSION + ": " + originalArtifactVersion; - String implVersion = Attributes.Name.IMPLEMENTATION_VERSION + ": " + currentVersion; - String commonXmlOriginalVersion = "" + originalArtifactVersion + ""; - String commonXmlVersion = "" + currentVersion + ""; - String originalPomPropsVersion = "version=" + originalArtifactVersion; - String pomPropsVersion = "version=" + currentVersion; - try ( JarFile jarFile = new JarFile( artifactFile.toFile() ) ) - { - try ( JarOutputStream jos = new JarOutputStream( - new BufferedOutputStream( new FileOutputStream( tmpJarFile ) ) ) ) - { - //Copy original jar file to the temporary one. - Enumeration jarEntries = jarFile.entries(); - byte[] buffer = new byte[1024]; - while ( jarEntries.hasMoreElements() ) - { - JarEntry entry = jarEntries.nextElement(); - String entryName = entry.getName(); - - if ( entryName.startsWith( "META-INF/maven" ) - && ( entryName.endsWith( "plugin.xml" ) || entryName.endsWith( "plugin-help.xml" ) ) ) - { - replaceEntry( jarFile, entry, commonXmlOriginalVersion, commonXmlVersion, jos ); - continue; - } - - if ( entryName.endsWith( "pom.xml" ) ) - { - replaceEntry( jarFile, entry, commonXmlOriginalVersion, commonXmlVersion, jos ); - continue; - } - - if ( entryName.endsWith( "pom.properties" ) ) - { - replaceEntry( jarFile, entry, originalPomPropsVersion, pomPropsVersion, jos ); - continue; - } - - if ( JarFile.MANIFEST_NAME.equals( entryName ) ) - { - replaceEntry( jarFile, entry, originalImplVersion, implVersion, jos ); - continue; - } - jos.putNextEntry( entry ); - try ( InputStream entryInputStream = jarFile.getInputStream( entry ) ) - { - int bytesRead; - while ( ( bytesRead = entryInputStream.read( buffer ) ) != -1 ) - { - jos.write( buffer, 0, bytesRead ); - } - } - } - } - } - return tmpJarFile.toPath(); - } - - private static void replaceEntry( JarFile jarFile, JarEntry entry, - String toReplace, String replacement, JarOutputStream jos ) throws IOException - { - String fullManifest = IOUtils.toString( jarFile.getInputStream( entry ), StandardCharsets.UTF_8.name() ); - String modified = fullManifest.replaceAll( toReplace, replacement ); - - byte[] bytes = modified.getBytes( StandardCharsets.UTF_8 ); - JarEntry newEntry = new JarEntry( entry.getName() ); - jos.putNextEntry( newEntry ); - jos.write( bytes ); - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java deleted file mode 100644 index bad6e48f1aa0..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/HttpCacheRepositoryImpl.java +++ /dev/null @@ -1,306 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicReference; - -import javax.annotation.Nonnull; -import javax.inject.Inject; -import javax.inject.Named; - -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.client.HttpClient; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.entity.InputStreamEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.maven.SessionScoped; -import org.apache.maven.caching.checksum.MavenProjectInput; -import org.apache.maven.caching.xml.Build; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.CacheSource; -import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.caching.xml.build.Artifact; -import org.apache.maven.caching.xml.report.CacheReport; -import org.apache.maven.caching.xml.report.ProjectReport; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * HTTP remote cache repository implementation. - */ -@SessionScoped -@Named( "http" ) -public class HttpCacheRepositoryImpl implements RemoteCacheRepository -{ - - public static final String BUILDINFO_XML = "buildinfo.xml"; - public static final String CACHE_REPORT_XML = "cache-report.xml"; - - private static final Logger LOGGER = LoggerFactory.getLogger( HttpCacheRepositoryImpl.class ); - - private final XmlService xmlService; - private final CacheConfig cacheConfig; - - @Inject - public HttpCacheRepositoryImpl( XmlService xmlService, CacheConfig cacheConfig ) - { - this.xmlService = xmlService; - this.cacheConfig = cacheConfig; - } - - @SuppressWarnings( "checkstyle:constantname" ) - private static final ThreadLocal httpClient = - ThreadLocal.withInitial( HttpCacheRepositoryImpl::newHttpClient ); - - @SuppressWarnings( "checkstyle:magicnumber" ) - private static CloseableHttpClient newHttpClient() - { - int timeoutSeconds = 60; - RequestConfig config = RequestConfig.custom() - .setConnectTimeout( timeoutSeconds * 1000 ) - .setConnectionRequestTimeout( timeoutSeconds * 1000 ) - .setSocketTimeout( timeoutSeconds * 1000 ) - .build(); - return HttpClientBuilder.create().setDefaultRequestConfig( config ).build(); - } - - @Nonnull - @Override - public Optional findBuild( CacheContext context ) throws IOException - { - final String resourceUrl = getResourceUrl( context, BUILDINFO_XML ); - return getResourceContent( resourceUrl ) - .map( content -> new Build( xmlService.loadBuild( content ), CacheSource.REMOTE ) ); - } - - @Nonnull - @Override - public boolean getArtifactContent( CacheContext context, Artifact artifact, Path target ) throws IOException - { - return getResourceContent( getResourceUrl( context, artifact.getFileName() ), target ); - } - - @Override - public void saveBuildInfo( CacheResult cacheResult, Build build ) - throws IOException - { - final String resourceUrl = getResourceUrl( cacheResult.getContext(), BUILDINFO_XML ); - putToRemoteCache( new ByteArrayInputStream( xmlService.toBytes( build.getDto() ) ), resourceUrl ); - } - - - @Override - public void saveCacheReport( String buildId, MavenSession session, CacheReport cacheReport ) throws IOException - { - MavenProject rootProject = session.getTopLevelProject(); - final String resourceUrl = cacheConfig.getUrl() + "/" + MavenProjectInput.CACHE_IMPLEMENTATION_VERSION - + "/" + rootProject.getGroupId() - + "/" + rootProject.getArtifactId() - + "/" + buildId - + "/" + CACHE_REPORT_XML; - putToRemoteCache( new ByteArrayInputStream( xmlService.toBytes( cacheReport ) ), resourceUrl ); - } - - @Override - public void saveArtifactFile( CacheResult cacheResult, - org.apache.maven.artifact.Artifact artifact ) throws IOException - { - final String resourceUrl = getResourceUrl( cacheResult.getContext(), CacheUtils.normalizedName( artifact ) ); - try ( InputStream inputStream = Files.newInputStream( artifact.getFile().toPath() ) ) - { - putToRemoteCache( inputStream, resourceUrl ); - } - } - - /** - * Downloads content of the resource - * - * @return null or content - */ - @Nonnull - public Optional getResourceContent( String url ) throws IOException - { - HttpGet get = new HttpGet( url ); - try - { - LOGGER.info( "Downloading {}", url ); - HttpResponse response = httpClient.get().execute( get ); - int statusCode = response.getStatusLine().getStatusCode(); - if ( statusCode != HttpStatus.SC_OK ) - { - LOGGER.info( "Cannot download {}, status code: {}", url, statusCode ); - return Optional.empty(); - } - try ( InputStream content = response.getEntity().getContent() ) - { - return Optional.of( IOUtils.toByteArray( content ) ); - } - } - finally - { - get.releaseConnection(); - } - } - - public boolean getResourceContent( String url, Path target ) throws IOException - { - HttpGet get = new HttpGet( url ); - try - { - LOGGER.info( "Downloading {}", url ); - HttpResponse response = httpClient.get().execute( get ); - int statusCode = response.getStatusLine().getStatusCode(); - if ( statusCode != HttpStatus.SC_OK ) - { - LOGGER.info( "Cannot download {}, status code: {}", url, statusCode ); - return false; - } - try ( InputStream content = response.getEntity().getContent() ) - { - Files.copy( content, target ); - return true; - } - } - finally - { - get.releaseConnection(); - } - } - - @Nonnull - @Override - public String getResourceUrl( CacheContext context, String filename ) - { - return getResourceUrl( filename, context.getProject().getGroupId(), context.getProject().getArtifactId(), - context.getInputInfo().getChecksum() ); - } - - private String getResourceUrl( String filename, String groupId, String artifactId, String checksum ) - { - return cacheConfig.getUrl() + "/" + MavenProjectInput.CACHE_IMPLEMENTATION_VERSION + "/" + groupId + "/" - + artifactId + "/" + checksum + "/" + filename; - } - - /** - * @param instream to be closed externally - */ - private void putToRemoteCache( InputStream instream, String url ) throws IOException - { - HttpPut httpPut = new HttpPut( url ); - try - { - httpPut.setEntity( new InputStreamEntity( instream ) ); - HttpResponse response = httpClient.get().execute( httpPut ); - int statusCode = response.getStatusLine().getStatusCode(); - LOGGER.info( "Saved to remote cache {}. Status: {}", url, statusCode ); - } - finally - { - httpPut.releaseConnection(); - } - } - - private final AtomicReference> cacheReportSupplier = new AtomicReference<>(); - - @Nonnull - @Override - public Optional findBaselineBuild( MavenProject project ) - { - Optional> cachedProjectsHolder = findCacheInfo() - .map( CacheReport::getProjects ); - - if ( !cachedProjectsHolder.isPresent() ) - { - return Optional.empty(); - } - - final List projects = cachedProjectsHolder.get(); - final Optional projectReportHolder = projects.stream().filter( p -> - project.getArtifactId().equals( p.getArtifactId() ) - && project.getGroupId().equals( p.getGroupId() ) ).findFirst(); - - if ( !projectReportHolder.isPresent() ) - { - return Optional.empty(); - } - - final ProjectReport projectReport = projectReportHolder.get(); - - String url; - if ( projectReport.getUrl() != null ) - { - url = projectReport.getUrl(); - LOGGER.info( "Retrieving baseline buildinfo: {}", url ); - } - else - { - url = getResourceUrl( BUILDINFO_XML, project.getGroupId(), - project.getArtifactId(), projectReport.getChecksum() ); - LOGGER.info( "Baseline project record doesn't have url, trying default location {}", url ); - } - - try - { - return getResourceContent( url ) - .map( content -> new Build( xmlService.loadBuild( content ), CacheSource.REMOTE ) ); - } - catch ( Exception e ) - { - LOGGER.warn( "Error restoring baseline build at url: {}, skipping diff", url, e ); - return Optional.empty(); - } - } - - private Optional findCacheInfo() - { - Optional report = cacheReportSupplier.get(); - if ( !report.isPresent() ) - { - try - { - LOGGER.info( "Downloading baseline cache report from: {}", cacheConfig.getBaselineCacheUrl() ); - report = getResourceContent( cacheConfig.getBaselineCacheUrl() ).map( xmlService::loadCacheReport ); - } - catch ( Exception e ) - { - LOGGER.error( "Error downloading baseline report from: {}, skipping diff.", - cacheConfig.getBaselineCacheUrl(), e ); - report = Optional.empty(); - } - cacheReportSupplier.compareAndSet( null, report ); - } - return report; - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LifecyclePhasesHelper.java b/maven-caching/src/main/java/org/apache/maven/caching/LifecyclePhasesHelper.java deleted file mode 100644 index 7b9caa591c5c..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/LifecyclePhasesHelper.java +++ /dev/null @@ -1,142 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.caching.xml.Build; -import org.apache.maven.lifecycle.DefaultLifecycles; -import org.apache.maven.lifecycle.Lifecycle; -import org.apache.maven.plugin.MojoExecution; - -@Singleton -@Named -public class LifecyclePhasesHelper -{ - - private final DefaultLifecycles defaultLifecycles; - private final List phases; - private final String lastCleanPhase; - - @Inject - public LifecyclePhasesHelper( DefaultLifecycles defaultLifecycles, - @Named( "clean" ) Lifecycle cleanLifecycle ) - { - this.defaultLifecycles = Objects.requireNonNull( defaultLifecycles ); - this.phases = defaultLifecycles.getLifeCycles().stream() - .flatMap( lf -> lf.getPhases().stream() ) - .collect( Collectors.toList() ); - this.lastCleanPhase = CacheUtils.getLast( cleanLifecycle.getPhases() ); - } - - /** - * Check if the given phase is later than the clean lifecycle. - */ - public boolean isLaterPhaseThanClean( String phase ) - { - return isLaterPhase( phase, lastCleanPhase ); - } - - public boolean isLaterPhaseThanBuild( String phase, Build build ) - { - return isLaterPhase( phase, build.getHighestCompletedGoal() ); - } - - /** - * Check if the given phase is later than the other in maven lifecycle. - * Example: isLaterPhase("install", "clean") returns true; - */ - public boolean isLaterPhase( String phase, String other ) - { - if ( !phases.contains( phase ) ) - { - throw new IllegalArgumentException( "Unsupported phase: " + phase ); - } - if ( !phases.contains( other ) ) - { - throw new IllegalArgumentException( "Unsupported phase: " + other ); - } - - return phases.indexOf( phase ) > phases.indexOf( other ); - } - - /** - * Computes the list of mojos executions in the clean phase - */ - public List getCleanSegment( List mojoExecutions ) - { - List list = new ArrayList<>(); - for ( MojoExecution mojoExecution : mojoExecutions ) - { - if ( mojoExecution.getLifecyclePhase() == null - || isLaterPhaseThanClean( mojoExecution.getLifecyclePhase() ) ) - { - break; - } - list.add( mojoExecution ); - } - return list; - } - - /** - * Computes the list of mojos executions that are cached. - */ - public List getCachedSegment( List mojoExecutions, Build build ) - { - List list = new ArrayList<>(); - for ( MojoExecution mojoExecution : mojoExecutions ) - { - if ( !isLaterPhaseThanClean( mojoExecution.getLifecyclePhase() ) ) - { - continue; - } - if ( isLaterPhaseThanBuild( mojoExecution.getLifecyclePhase(), build ) ) - { - break; - } - list.add( mojoExecution ); - } - return list; - } - - /** - * Computes the list of mojos executions that will have to be executed after cache restoration. - */ - public List getPostCachedSegment( List mojoExecutions, Build build ) - { - List list = new ArrayList<>(); - for ( MojoExecution mojoExecution : mojoExecutions ) - { - if ( isLaterPhaseThanBuild( mojoExecution.getLifecyclePhase(), build ) ) - { - list.add( mojoExecution ); - } - } - return list; - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepository.java deleted file mode 100644 index 48f48038d9a1..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepository.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; -import java.nio.file.Path; -import java.util.Optional; - -import org.apache.maven.caching.xml.Build; -import org.apache.maven.caching.xml.CacheSource; -import org.apache.maven.caching.xml.build.Artifact; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Dependency; - -import javax.annotation.Nonnull; - -/** - * Local cache repository. - */ -public interface LocalCacheRepository extends CacheRepository -{ - - void beforeSave( CacheContext environment ) throws IOException; - - Path getArtifactFile( CacheContext context, CacheSource source, Artifact artifact ) throws IOException; - - void clearCache( CacheContext context ); - - @Nonnull - Optional findBestMatchingBuild( MavenSession session, Dependency dependency ) throws IOException; - - @Nonnull - Optional findLocalBuild( CacheContext context ) throws IOException; -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java deleted file mode 100644 index 98d25ee1929e..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/LocalCacheRepositoryImpl.java +++ /dev/null @@ -1,488 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.File; -import java.io.IOException; -import java.nio.file.DirectoryStream; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.StandardCopyOption; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.FileTime; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -import javax.annotation.Nonnull; -import javax.inject.Inject; -import javax.inject.Named; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.maven.SessionScoped; -import org.apache.maven.caching.xml.Build; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.CacheSource; -import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.caching.xml.build.Artifact; -import org.apache.maven.caching.xml.build.Scm; -import org.apache.maven.caching.xml.report.CacheReport; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Dependency; -import org.apache.maven.project.MavenProject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static java.nio.file.StandardOpenOption.CREATE; -import static java.nio.file.StandardOpenOption.CREATE_NEW; -import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; -import static java.util.concurrent.TimeUnit.DAYS; -import static java.util.concurrent.TimeUnit.HOURS; -import static java.util.concurrent.TimeUnit.MINUTES; -import static org.apache.commons.lang3.StringUtils.isNotBlank; -import static org.apache.maven.caching.CacheUtils.getMultimoduleRoot; -import static org.apache.maven.caching.checksum.MavenProjectInput.CACHE_IMPLEMENTATION_VERSION; - -/** - * Local cache repository implementation. - */ -@SessionScoped -@Named -@SuppressWarnings( "unused" ) -public class LocalCacheRepositoryImpl implements LocalCacheRepository -{ - - private static final String BUILDINFO_XML = "buildinfo.xml"; - private static final String LOOKUPINFO_XML = "lookupinfo.xml"; - private static final long ONE_HOUR_MILLIS = HOURS.toMillis( 1 ); - private static final long ONE_MINUTE_MILLIS = MINUTES.toMillis( 1 ); - private static final long ONE_DAY_MILLIS = DAYS.toMillis( 1 ); - private static final String EMPTY = ""; - - private static final Logger LOGGER = LoggerFactory.getLogger( LocalCacheRepositoryImpl.class ); - - private final RemoteCacheRepository remoteRepository; - private final XmlService xmlService; - private final CacheConfig cacheConfig; - private final Map, Optional> bestBuildCache = new ConcurrentHashMap<>(); - - @Inject - public LocalCacheRepositoryImpl( - RemoteCacheRepository remoteRepository, - XmlService xmlService, - CacheConfig cacheConfig ) - { - this.remoteRepository = remoteRepository; - this.xmlService = xmlService; - this.cacheConfig = cacheConfig; - } - - @Nonnull - @Override - public Optional findLocalBuild( CacheContext context ) throws IOException - { - Path localBuildInfoPath = localBuildPath( context, BUILDINFO_XML, false ); - LOGGER.debug( "Checking local build info: {}", localBuildInfoPath ); - if ( Files.exists( localBuildInfoPath ) ) - { - LOGGER.info( "Local build found by checksum {}", context.getInputInfo().getChecksum() ); - try - { - org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( localBuildInfoPath.toFile() ); - return Optional.of( new Build( dto, CacheSource.LOCAL ) ); - } - catch ( Exception e ) - { - LOGGER.info( "Local build info is not valid, deleting: {}", localBuildInfoPath, e ); - Files.delete( localBuildInfoPath ); - } - } - return Optional.empty(); - } - - @Nonnull - @Override - public Optional findBuild( CacheContext context ) throws IOException - { - Path buildInfoPath = remoteBuildPath( context, BUILDINFO_XML ); - LOGGER.debug( "Checking if build is already downloaded: {}", buildInfoPath ); - - if ( Files.exists( buildInfoPath ) ) - { - LOGGER.info( "Downloaded build found by checksum {}", context.getInputInfo().getChecksum() ); - try - { - org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( buildInfoPath.toFile() ); - return Optional.of( new Build( dto, CacheSource.REMOTE ) ); - } - catch ( Exception e ) - { - LOGGER.info( "Downloaded build info is not valid, deleting: {}", buildInfoPath, e ); - Files.delete( buildInfoPath ); - } - } - - if ( !cacheConfig.isRemoteCacheEnabled() ) - { - return Optional.empty(); - } - - try - { - Path lookupInfoPath = remoteBuildPath( context, LOOKUPINFO_XML ); - if ( Files.exists( lookupInfoPath ) ) - { - final BasicFileAttributes fileAttributes = Files.readAttributes( lookupInfoPath, - BasicFileAttributes.class ); - final long lastModified = fileAttributes.lastModifiedTime().toMillis(); - final long created = fileAttributes.creationTime().toMillis(); - final long now = System.currentTimeMillis(); - // throttle remote cache calls, maven like - if ( now < created + ONE_HOUR_MILLIS && now < lastModified + ONE_MINUTE_MILLIS ) - { // fresh file, allow lookup every minute - LOGGER.info( "Skipping remote lookup, last unsuccessful lookup less than 1m ago." ); - return Optional.empty(); - } - else if ( now < created + ONE_DAY_MILLIS && now < lastModified + ONE_HOUR_MILLIS ) - { // less than 1 day file, allow 1 per hour lookup - LOGGER.info( "Skipping remote lookup, last unsuccessful lookup less than 1h ago." ); - return Optional.empty(); - } - else if ( now > created + ONE_DAY_MILLIS && now < lastModified + ONE_DAY_MILLIS ) - { // more than 1 day file, allow 1 per day lookup - LOGGER.info( "Skipping remote lookup, last unsuccessful lookup less than 1d ago." ); - return Optional.empty(); - } - } - - final Optional build = remoteRepository.findBuild( context ); - if ( build.isPresent() ) - { - LOGGER.info( "Build info downloaded from remote repo, saving to: {}", buildInfoPath ); - Files.createDirectories( buildInfoPath.getParent() ); - Files.write( buildInfoPath, xmlService.toBytes( build.get().getDto() ), CREATE_NEW ); - } - else - { - FileUtils.touch( lookupInfoPath.toFile() ); - } - return build; - } - catch ( Exception e ) - { - LOGGER.error( "Remote build info is not valid, cached data is not compatible", e ); - return Optional.empty(); - } - } - - @Override - public void clearCache( CacheContext context ) - { - try - { - final Path buildCacheDir = buildCacheDir( context ); - Path artifactCacheDir = buildCacheDir.getParent(); - - if ( !Files.exists( artifactCacheDir ) ) - { - return; - } - - List cacheDirs = new ArrayList<>(); - try ( DirectoryStream paths = Files.newDirectoryStream( artifactCacheDir ) ) - { - for ( Path dir : paths ) - { - if ( Files.isDirectory( dir ) ) - { - cacheDirs.add( dir ); - } - } - } - int maxLocalBuildsCached = cacheConfig.getMaxLocalBuildsCached() - 1; - if ( cacheDirs.size() > maxLocalBuildsCached ) - { - cacheDirs.sort( Comparator.comparing( LocalCacheRepositoryImpl::lastModifiedTime ) ); - for ( Path dir : cacheDirs.subList( 0, cacheDirs.size() - maxLocalBuildsCached ) ) - { - FileUtils.deleteDirectory( dir.toFile() ); - } - } - final Path path = localBuildDir( context ); - if ( Files.exists( path ) ) - { - FileUtils.deleteDirectory( path.toFile() ); - } - } - catch ( IOException e ) - { - final String artifactId = context.getProject().getArtifactId(); - throw new RuntimeException( - "Failed to cleanup local cache of " + artifactId + " on build failure, it might be inconsistent", - e ); - } - } - - @Nonnull - @Override - public Optional findBestMatchingBuild( - MavenSession session, Dependency dependency ) - { - return bestBuildCache.computeIfAbsent( Pair.of( session, dependency ), this::findBestMatchingBuildImpl ); - } - - @Nonnull - private Optional findBestMatchingBuildImpl( - Pair dependencySession ) - { - try - { - final MavenSession session = dependencySession.getLeft(); - final Dependency dependency = dependencySession.getRight(); - - final Path artifactCacheDir = - artifactCacheDir( session, dependency.getGroupId(), dependency.getArtifactId() ); - - final Map, Collection>> filesByVersion = new HashMap<>(); - - Files.walkFileTree( artifactCacheDir, new SimpleFileVisitor() - { - @Override - public FileVisitResult visitFile( Path path, BasicFileAttributes basicFileAttributes ) - { - final File file = path.toFile(); - if ( file.getName().equals( BUILDINFO_XML ) ) - { - try - { - final org.apache.maven.caching.xml.build.Build dto = xmlService.loadBuild( file ); - final Pair buildInfoAndFile = - Pair.of( new Build( dto, CacheSource.LOCAL ), path ); - final String cachedVersion = dto.getArtifact().getVersion(); - final String cachedBranch = getScmRef( dto.getScm() ); - add( filesByVersion, Pair.of( cachedVersion, cachedBranch ), buildInfoAndFile ); - if ( isNotBlank( cachedBranch ) ) - { - add( filesByVersion, Pair.of( EMPTY, cachedBranch ), buildInfoAndFile ); - } - if ( isNotBlank( cachedVersion ) ) - { - add( filesByVersion, Pair.of( cachedVersion, EMPTY ), buildInfoAndFile ); - } - } - catch ( Exception e ) - { - // version is unusable nothing we can do here - LOGGER.info( "Build info is not compatible to current maven " - + "implementation: {}", file, e ); - } - } - return FileVisitResult.CONTINUE; - } - } ); - - if ( filesByVersion.isEmpty() ) - { - return Optional.empty(); - } - - final String currentRef = getScmRef( CacheUtils.readGitInfo( session ) ); - // first lets try by branch and version - Collection> bestMatched = new LinkedList<>(); - if ( isNotBlank( currentRef ) ) - { - bestMatched = filesByVersion.get( Pair.of( dependency.getVersion(), currentRef ) ); - } - if ( bestMatched.isEmpty() ) - { - // then by version - bestMatched = filesByVersion.get( Pair.of( dependency.getVersion(), EMPTY ) ); - } - if ( bestMatched.isEmpty() && isNotBlank( currentRef ) ) - { - // then by branch - bestMatched = filesByVersion.get( Pair.of( EMPTY, currentRef ) ); - } - if ( bestMatched.isEmpty() ) - { - // ok lets take all - bestMatched = filesByVersion.values().stream() - .flatMap( Collection::stream ).collect( Collectors.toList() ); - } - - return bestMatched.stream() - .max( Comparator.comparing( p -> lastModifiedTime( p.getRight() ) ) ) - .map( Pair::getLeft ); - } - catch ( IOException e ) - { - LOGGER.info( "Cannot find dependency in cache", e ); - return Optional.empty(); - } - } - - private String getScmRef( Scm scm ) - { - if ( scm != null ) - { - return scm.getSourceBranch() != null ? scm.getSourceBranch() : scm.getRevision(); - } - else - { - return EMPTY; - } - } - - @Override - public Path getArtifactFile( CacheContext context, CacheSource source, Artifact artifact ) throws IOException - { - if ( source == CacheSource.LOCAL ) - { - return localBuildPath( context, artifact.getFileName(), false ); - } - else - { - Path cachePath = remoteBuildPath( context, artifact.getFileName() ); - if ( !Files.exists( cachePath ) && cacheConfig.isRemoteCacheEnabled() ) - { - if ( !remoteRepository.getArtifactContent( context, artifact, cachePath ) ) - { - Files.deleteIfExists( cachePath ); - } - } - return cachePath; - } - } - - @Override - public void beforeSave( CacheContext environment ) - { - clearCache( environment ); - } - - @Override - public void saveBuildInfo( CacheResult cacheResult, Build build ) - throws IOException - { - final Path path = localBuildPath( cacheResult.getContext(), BUILDINFO_XML, true ); - Files.write( path, xmlService.toBytes( build.getDto() ), TRUNCATE_EXISTING, CREATE ); - if ( cacheConfig.isRemoteCacheEnabled() && cacheConfig.isSaveToRemote() && !cacheResult.isFinal() ) - { - remoteRepository.saveBuildInfo( cacheResult, build ); - } - } - - @Override - public void saveCacheReport( String buildId, MavenSession session, CacheReport cacheReport ) throws IOException - { - Path path = getMultimoduleRoot( session ).resolve( "target" ).resolve( "maven-incremental" ); - Files.createDirectories( path ); - Files.write( path.resolve( "cache-report." + buildId + ".xml" ), xmlService.toBytes( cacheReport ), - TRUNCATE_EXISTING, CREATE ); - if ( cacheConfig.isRemoteCacheEnabled() && cacheConfig.isSaveToRemote() ) - { - LOGGER.info( "Saving cache report on build completion" ); - remoteRepository.saveCacheReport( buildId, session, cacheReport ); - } - } - - @Override - public void saveArtifactFile( CacheResult cacheResult, org.apache.maven.artifact.Artifact artifact ) - throws IOException - { - // safe artifacts to cache - File artifactFile = artifact.getFile(); - Path cachePath = localBuildPath( cacheResult.getContext(), CacheUtils.normalizedName( artifact ), true ); - Files.copy( artifactFile.toPath(), cachePath, StandardCopyOption.REPLACE_EXISTING ); - if ( cacheConfig.isRemoteCacheEnabled() && cacheConfig.isSaveToRemote() && !cacheResult.isFinal() ) - { - remoteRepository.saveArtifactFile( cacheResult, artifact ); - } - } - - private Path buildCacheDir( CacheContext context ) throws IOException - { - final MavenProject project = context.getProject(); - final Path artifactCacheDir = artifactCacheDir( context.getSession(), project.getGroupId(), - project.getArtifactId() ); - return artifactCacheDir.resolve( context.getInputInfo().getChecksum() ); - } - - private Path artifactCacheDir( MavenSession session, String groupId, String artifactId ) throws IOException - { - final String localRepositoryRoot = session.getLocalRepository().getBasedir(); - final Path path = Paths.get( localRepositoryRoot, "..", "cache", CACHE_IMPLEMENTATION_VERSION, groupId, - artifactId ).normalize(); - if ( !Files.exists( path ) ) - { - Files.createDirectories( path ); - } - return path; - } - - private Path remoteBuildPath( CacheContext context, String filename ) throws IOException - { - return buildCacheDir( context ).resolve( filename ); - } - - private Path localBuildPath( CacheContext context, String filename, boolean createDir ) throws IOException - { - final Path localBuildDir = localBuildDir( context ); - if ( createDir ) - { - Files.createDirectories( localBuildDir ); - } - return localBuildDir.resolve( filename ); - } - - private Path localBuildDir( CacheContext context ) throws IOException - { - return buildCacheDir( context ).resolve( "local" ); - } - - private static FileTime lastModifiedTime( Path p ) - { - try - { - return Files.getLastModifiedTime( p ); - } - catch ( IOException e ) - { - return FileTime.fromMillis( 0 ); - } - } - - private static void add( Map> map, K key, V value ) - { - map.computeIfAbsent( key, k -> new ArrayList<>() ).add( value ); - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java b/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java deleted file mode 100644 index 36779755cf20..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/MojoParametersListener.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.execution.MojoExecutionEvent; -import org.apache.maven.execution.MojoExecutionListener; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.project.MavenProject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * MojoParametersListener - */ -@Singleton -@Named -public class MojoParametersListener implements MojoExecutionListener -{ - - private static final Logger LOGGER = LoggerFactory.getLogger( MojoParametersListener.class ); - - private final ConcurrentMap> projectExecutions = - new ConcurrentHashMap<>(); - - @Override - public void beforeMojoExecution( MojoExecutionEvent event ) - { - final String executionKey = CacheUtils.mojoExecutionKey( event.getExecution() ); - LOGGER.debug( "Starting mojo execution: {}, class: {}", executionKey, event.getMojo().getClass() ); - final MavenProject project = event.getProject(); - Map projectEvents = projectExecutions.get( project ); - if ( projectEvents == null ) - { - Map candidate = new ConcurrentHashMap<>(); - projectEvents = projectExecutions.putIfAbsent( project, candidate ); - if ( projectEvents == null ) - { - projectEvents = candidate; - } - } - projectEvents.put( executionKey, event ); - } - - @Override - public void afterMojoExecutionSuccess( MojoExecutionEvent event ) throws MojoExecutionException - { - // do nothing - } - - @Override - public void afterExecutionFailure( MojoExecutionEvent event ) - { - //do nothing - } - - public Map getProjectExecutions( MavenProject project ) - { - return projectExecutions.get( project ); - } - - public void remove( MavenProject project ) - { - projectExecutions.remove( project ); - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/MultiModuleSupport.java b/maven-caching/src/main/java/org/apache/maven/caching/MultiModuleSupport.java deleted file mode 100644 index 3c3c3c138dde..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/MultiModuleSupport.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.project.MavenProject; - -import java.util.Optional; - -public interface MultiModuleSupport -{ - - Optional tryToResolveProject( String groupId, String artifactId, String version ); - - boolean isPartOfMultiModule( String groupId, String artifactId, String version ); - - boolean isPartOfSession( String groupId, String artifactId, String version ); - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/NormalizedModelProvider.java b/maven-caching/src/main/java/org/apache/maven/caching/NormalizedModelProvider.java deleted file mode 100644 index 45b69b835e77..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/NormalizedModelProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.model.Model; -import org.apache.maven.project.MavenProject; - -/** - * Calculate normalized model for project. The idea is to have model where not all properties resolved. In particular - * ${project....} and ${pom....} replaced to some constant value. This helps to calculate correct checksum when changed - * only project version for example build 1 : 1.0-SNAPSHOT, build 2 : 2.0-SNAPSHOT in this case 2nd build could be - * completely restored from cache. - */ -public interface NormalizedModelProvider -{ - - /** - * @param project - the project which model will be calculated for - * @return normalized model for project - */ - Model normalizedModel( MavenProject project ); - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfig.java deleted file mode 100644 index da5767767f8d..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.caching.xml.config.DirScanConfig; - -import javax.annotation.Nonnull; - -/** - * PluginScanConfig - */ -public interface PluginScanConfig -{ - boolean isSkip(); - - boolean accept( String propertyName ); - - PluginScanConfig mergeWith( PluginScanConfig overrideSource ); - - @Nonnull - ScanConfigProperties getTagScanProperties( String tagName ); - - DirScanConfig dto(); -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java deleted file mode 100644 index 76dee362be65..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/PluginScanConfigImpl.java +++ /dev/null @@ -1,159 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.xml.config.DirScanConfig; -import org.apache.maven.caching.xml.config.TagExclude; -import org.apache.maven.caching.xml.config.TagScanConfig; - -import javax.annotation.Nonnull; -import java.util.List; - -/** - * PluginScanConfigImpl - */ -public class PluginScanConfigImpl implements PluginScanConfig -{ - - private final DirScanConfig dto; - - public PluginScanConfigImpl( DirScanConfig scanConfig ) - { - this.dto = scanConfig; - } - - @Override - public boolean isSkip() - { - return StringUtils.equals( dto.getMode(), "skip" ); - } - - @Override - public boolean accept( String tagName ) - { - // include or exclude is a choice element, could be only obe property set - - //noinspection ConstantConditions - final List includes = dto.getIncludes(); - if ( !includes.isEmpty() ) - { - return findTagScanProperties( tagName ) != null; - } - - return !contains( dto.getExcludes(), tagName ); - } - - private boolean contains( List excludes, String tagName ) - { - for ( TagExclude exclude : excludes ) - { - if ( StringUtils.equals( exclude.getTagName(), tagName ) ) - { - return true; - } - } - return false; - } - - @Nonnull - @Override - public PluginScanConfig mergeWith( final PluginScanConfig overrideConfig ) - { - if ( dto == null ) - { - return overrideConfig; - } - - final DirScanConfig override = overrideConfig.dto(); - if ( override == null ) - { - return this; - } - - if ( override.isIgnoreParent() ) - { - return overrideConfig; - } - - DirScanConfig merged = new DirScanConfig(); - if ( override.getMode() != null ) - { - merged.setMode( override.getMode() ); - } - else - { - merged.setMode( dto.getMode() ); - } - - merged.getExcludes().addAll( dto.getExcludes() ); - merged.getExcludes().addAll( override.getExcludes() ); - - merged.getIncludes().addAll( dto.getIncludes() ); - merged.getIncludes().addAll( override.getIncludes() ); - - return new PluginScanConfigImpl( merged ); - } - - @Nonnull - public ScanConfigProperties getTagScanProperties( String tagName ) - { - ScanConfigProperties scanProperties = findTagScanProperties( tagName ); - return scanProperties != null ? scanProperties : defaultScanConfig(); - } - - @Override - public DirScanConfig dto() - { - return dto; - } - - private ScanConfigProperties findTagScanProperties( String tagName ) - { - ScanConfigProperties scanConfigProperties = findConfigByName( tagName, dto.getIncludes() ); - if ( scanConfigProperties == null ) - { - scanConfigProperties = findConfigByName( tagName, dto.getTagScanConfigs() ); - } - return scanConfigProperties; - } - - private ScanConfigProperties findConfigByName( String tagName, List configs ) - { - if ( configs == null ) - { - return null; - } - - for ( TagScanConfig config : configs ) - { - if ( StringUtils.equals( tagName, config.getTagName() ) ) - { - return new ScanConfigProperties( config.isRecursive(), config.getGlob() ); - } - } - return null; - } - - private static ScanConfigProperties defaultScanConfig() - { - return new ScanConfigProperties( true, null ); - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/ProjectInputCalculator.java b/maven-caching/src/main/java/org/apache/maven/caching/ProjectInputCalculator.java deleted file mode 100644 index 3697d456eb42..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/ProjectInputCalculator.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.caching.xml.build.ProjectsInputInfo; -import org.apache.maven.project.MavenProject; - -/** - * - */ -public interface ProjectInputCalculator -{ - - ProjectsInputInfo calculateInput( MavenProject project ); - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java deleted file mode 100644 index 901f5bcbe29c..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepository.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; -import java.nio.file.Path; -import java.util.Optional; - -import org.apache.maven.caching.xml.Build; -import org.apache.maven.caching.xml.build.Artifact; -import org.apache.maven.project.MavenProject; - -import javax.annotation.Nonnull; - -/** - * Remote cache repository. - */ -public interface RemoteCacheRepository extends CacheRepository -{ - - /** - * Download an artifact to the given location. - * Returns true if success, false if the artifact does not exists - * and throws an IOException if a problem occurs. - */ - boolean getArtifactContent( CacheContext context, Artifact artifact, Path target ) throws IOException; - - @Nonnull - String getResourceUrl( CacheContext context, String filename ); - - @Nonnull - Optional findBaselineBuild( MavenProject project ); -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryProvider.java b/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryProvider.java deleted file mode 100644 index d9c7ebc8b94b..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/RemoteCacheRepositoryProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import javax.annotation.Priority; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Provider; -import javax.inject.Singleton; - -import org.apache.maven.caching.xml.CacheConfig; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; - -/** - * Remote cache repository. - */ -@Singleton -@Named( "#factory#" ) -@Priority( 10 ) -public class RemoteCacheRepositoryProvider implements Provider -{ - - private final RemoteCacheRepository repository; - - @Inject - public RemoteCacheRepositoryProvider( CacheConfig config, PlexusContainer container ) - throws ComponentLookupException - { - config.initialize(); - String hint = config.getTransport(); - repository = container.lookup( RemoteCacheRepository.class, hint ); - } - - public RemoteCacheRepository get() - { - return repository; - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RestoreStatus.java b/maven-caching/src/main/java/org/apache/maven/caching/RestoreStatus.java deleted file mode 100644 index 6bf8fefc2832..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/RestoreStatus.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * RestoreStatus - */ -public enum RestoreStatus -{ - EMPTY, - FAILURE, - PARTIAL, - SUCCESS -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/RestoredArtifactHandler.java b/maven-caching/src/main/java/org/apache/maven/caching/RestoredArtifactHandler.java deleted file mode 100644 index 039b44b465ce..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/RestoredArtifactHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.project.MavenProject; - -import java.io.IOException; -import java.nio.file.Path; - -public interface RestoredArtifactHandler -{ - //we might store in cache artifact which was build with previous version - //1.0-SNAPSHOT is kept in cache but real version of project is 2.0 - //for pom packaging this is done automatically by maven but for jar and other there might be - //sensitive metadata with previous version. Versions mismatch could lead errors - Path adjustArchiveArtifactVersion( MavenProject project, String originalArtifactVersion, Path artifactFile ) - throws IOException; -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/ScanConfigProperties.java b/maven-caching/src/main/java/org/apache/maven/caching/ScanConfigProperties.java deleted file mode 100644 index bc9622a59fa8..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/ScanConfigProperties.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * ScanConfigProperties - */ -public class ScanConfigProperties -{ - private final boolean recursive; - private final String glob; - - public ScanConfigProperties( boolean recursive, String glob ) - { - this.recursive = recursive; - this.glob = glob; - } - - public boolean isRecursive() - { - return recursive; - } - - public String getGlob() - { - return glob; - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/WagonConfigurator.java b/maven-caching/src/main/java/org/apache/maven/caching/WagonConfigurator.java deleted file mode 100644 index 6a24d5e23cce..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/WagonConfigurator.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.apache.maven.wagon.Wagon; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.codehaus.plexus.component.configurator.AbstractComponentConfigurator; -import org.codehaus.plexus.component.configurator.ComponentConfigurationException; -import org.codehaus.plexus.component.configurator.ConfigurationListener; -import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -import static java.util.Objects.requireNonNull; - -/** - * A wagon configurator based on the Plexus component configuration framework. - */ -@Singleton -public class WagonConfigurator -{ - private final PlexusContainer container; - - /** - * Creates a wagon configurator using the specified Plexus container. - * - * @param container The Plexus container instance to use, must not be {@code null}. - */ - @Inject - public WagonConfigurator( final PlexusContainer container ) - { - this.container = requireNonNull( container, "plexus container cannot be null" ); - } - - public void configure( Wagon wagon, Object configuration ) - throws Exception - { - requireNonNull( wagon, "wagon cannot be null" ); - requireNonNull( configuration, "configuration cannot be null" ); - - PlexusConfiguration config; - if ( configuration instanceof PlexusConfiguration ) - { - config = (PlexusConfiguration) configuration; - } - else if ( configuration instanceof Xpp3Dom ) - { - config = new XmlPlexusConfiguration( (Xpp3Dom) configuration ); - } - else - { - throw new IllegalArgumentException( "unexpected configuration type: " - + configuration.getClass().getName() ); - } - - WagonComponentConfigurator configurator = new WagonComponentConfigurator(); - - configurator.configureComponent( wagon, config, container.getContainerRealm() ); - } - - static class WagonComponentConfigurator - extends AbstractComponentConfigurator - { - - @Override - public void configureComponent( Object component, PlexusConfiguration configuration, - ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm, - ConfigurationListener listener ) - throws ComponentConfigurationException - { - ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter(); - - converter.processConfiguration( converterLookup, component, containerRealm, configuration, - expressionEvaluator, listener ); - } - - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/WagonProvider.java b/maven-caching/src/main/java/org/apache/maven/caching/WagonProvider.java deleted file mode 100644 index b0fdc99aa246..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/WagonProvider.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.apache.maven.wagon.Wagon; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; - -import static java.util.Objects.requireNonNull; - -/** - * A wagon provider backed by a Plexus container and the wagons registered with this container. - */ -@Singleton -public class WagonProvider -{ - private final PlexusContainer container; - - /** - * Creates a wagon provider using the specified Plexus container. - * - * @param container The Plexus container instance to use, must not be {@code null}. - */ - @Inject - public WagonProvider( final PlexusContainer container ) - { - this.container = requireNonNull( container, "plexus container cannot be null" ); - } - - public Wagon lookup( String roleHint ) - throws ComponentLookupException - { - return container.lookup( Wagon.class, roleHint ); - } - - public void release( Wagon wagon ) - throws ComponentLifecycleException - { - if ( wagon != null ) - { - container.release( wagon ); - } - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/WagonRemoteCacheRepository.java b/maven-caching/src/main/java/org/apache/maven/caching/WagonRemoteCacheRepository.java deleted file mode 100644 index 946ee246dd6d..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/WagonRemoteCacheRepository.java +++ /dev/null @@ -1,701 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Optional; -import java.util.Properties; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; - -import javax.annotation.Nonnull; -import javax.annotation.PreDestroy; -import javax.inject.Inject; -import javax.inject.Named; - -import org.apache.maven.SessionScoped; -import org.apache.maven.caching.checksum.MavenProjectInput; -import org.apache.maven.caching.xml.Build; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.CacheSource; -import org.apache.maven.caching.xml.XmlService; -import org.apache.maven.caching.xml.build.Artifact; -import org.apache.maven.caching.xml.report.CacheReport; -import org.apache.maven.caching.xml.report.ProjectReport; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; -import org.apache.maven.repository.RepositorySystem; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import org.apache.maven.wagon.StreamingWagon; -import org.apache.maven.wagon.Wagon; -import org.apache.maven.wagon.WagonException; -import org.apache.maven.wagon.authentication.AuthenticationInfo; -import org.apache.maven.wagon.proxy.ProxyInfo; -import org.apache.maven.wagon.proxy.ProxyInfoProvider; -import org.apache.maven.wagon.repository.Repository; -import org.apache.maven.wagon.repository.RepositoryPermissions; -import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.eclipse.aether.ConfigurationProperties; -import org.eclipse.aether.RepositoryException; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.repository.Authentication; -import org.eclipse.aether.repository.AuthenticationContext; -import org.eclipse.aether.repository.Proxy; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.transfer.NoTransporterException; -import org.eclipse.aether.util.ConfigUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@SessionScoped -@Named( "wagon" ) -@SuppressWarnings( "unused" ) -public class WagonRemoteCacheRepository implements RemoteCacheRepository -{ - public static final String BUILDINFO_XML = "buildinfo.xml"; - public static final String CACHE_REPORT_XML = "cache-report.xml"; - - private static final String CONFIG_PROP_CONFIG = "remote.caching.wagon.config"; - private static final String CONFIG_PROP_FILE_MODE = "remote.caching.wagon.perms.fileMode"; - private static final String CONFIG_PROP_DIR_MODE = "remote.caching.wagon.perms.dirMode"; - private static final String CONFIG_PROP_GROUP = "remote.caching.wagon.perms.group"; - - - private static final Logger LOGGER = LoggerFactory.getLogger( HttpCacheRepositoryImpl.class ); - - private final MavenSession mavenSession; - private final XmlService xmlService; - private final CacheConfig cacheConfig; - private final WagonConfigurator wagonConfigurator; - private final WagonProvider wagonProvider; - - private final RemoteRepository repository; - private final AuthenticationContext repoAuthContext; - private final AuthenticationContext proxyAuthContext; - private final String wagonHint; - private final Repository wagonRepo; - private final AuthenticationInfo wagonAuth; - private final ProxyInfoProvider wagonProxy; - private final Properties headers; - private final AtomicBoolean closed = new AtomicBoolean(); - private final Queue wagons = new ConcurrentLinkedQueue<>(); - private final AtomicReference> cacheReportSupplier = new AtomicReference<>(); - - @Inject - public WagonRemoteCacheRepository( MavenSession mavenSession, - XmlService xmlService, - CacheConfig cacheConfig, - WagonProvider wagonProvider, - WagonConfigurator wagonConfigurator, - RepositorySystem repositorySystem ) - throws RepositoryException - { - this.xmlService = xmlService; - this.cacheConfig = cacheConfig; - this.mavenSession = mavenSession; - this.wagonProvider = wagonProvider; - this.wagonConfigurator = wagonConfigurator; - - MavenExecutionRequest request = mavenSession.getRequest(); - RepositorySystemSession session = mavenSession.getRepositorySession(); - - cacheConfig.initialize(); - - RemoteRepository repo = new RemoteRepository.Builder( - cacheConfig.getId(), "cache", cacheConfig.getUrl() ).build(); - RemoteRepository mirror = session.getMirrorSelector().getMirror( repo ); - RemoteRepository repoOrMirror = mirror != null ? mirror : repo; - Proxy proxy = session.getProxySelector().getProxy( repoOrMirror ); - Authentication auth = session.getAuthenticationSelector().getAuthentication( repoOrMirror ); - repository = new RemoteRepository.Builder( repoOrMirror ) - .setProxy( proxy ) - .setAuthentication( auth ) - .build(); - - - wagonRepo = new Repository( repository.getId(), repository.getUrl() ); - wagonRepo.setPermissions( getPermissions( repository.getId(), session ) ); - - wagonHint = wagonRepo.getProtocol().toLowerCase( Locale.ENGLISH ); - if ( wagonHint.isEmpty() ) - { - throw new IllegalArgumentException( "Could not find a wagon provider for " + wagonRepo ); - } - - try - { - wagons.add( lookupWagon() ); - } - catch ( Exception e ) - { - LOGGER.debug( "No transport {}", e, e ); - throw new NoTransporterException( repository, e ); - } - - repoAuthContext = AuthenticationContext.forRepository( session, repository ); - proxyAuthContext = AuthenticationContext.forProxy( session, repository ); - - wagonAuth = getAuthenticationInfo( repoAuthContext ); - wagonProxy = getProxy( repository, proxyAuthContext ); - - this.headers = new Properties(); - this.headers.put( "User-Agent", ConfigUtils.getString( session, ConfigurationProperties.DEFAULT_USER_AGENT, - ConfigurationProperties.USER_AGENT ) ); - Map headers = - ConfigUtils.getMap( session, null, ConfigurationProperties.HTTP_HEADERS + "." + repository.getId(), - ConfigurationProperties.HTTP_HEADERS ); - if ( headers != null ) - { - this.headers.putAll( headers ); - } - } - - @PreDestroy - void destroy() - { - if ( closed.compareAndSet( false, true ) ) - { - AuthenticationContext.close( repoAuthContext ); - AuthenticationContext.close( proxyAuthContext ); - - for ( Wagon wagon = wagons.poll(); wagon != null; wagon = wagons.poll() ) - { - disconnectWagon( wagon ); - releaseWagon( wagon ); - } - } - } - - - private static RepositoryPermissions getPermissions( String repoId, RepositorySystemSession session ) - { - RepositoryPermissions result = null; - RepositoryPermissions perms = new RepositoryPermissions(); - String suffix = '.' + repoId; - String fileMode = ConfigUtils.getString( session, null, CONFIG_PROP_FILE_MODE + suffix ); - if ( fileMode != null ) - { - perms.setFileMode( fileMode ); - result = perms; - } - String dirMode = ConfigUtils.getString( session, null, CONFIG_PROP_DIR_MODE + suffix ); - if ( dirMode != null ) - { - perms.setDirectoryMode( dirMode ); - result = perms; - } - String group = ConfigUtils.getString( session, null, CONFIG_PROP_GROUP + suffix ); - if ( group != null ) - { - perms.setGroup( group ); - result = perms; - } - return result; - } - - private AuthenticationInfo getAuthenticationInfo( final AuthenticationContext authContext ) - { - AuthenticationInfo auth = null; - - if ( authContext != null ) - { - auth = new AuthenticationInfo() - { - @Override - public String getUserName() - { - return authContext.get( AuthenticationContext.USERNAME ); - } - - @Override - public String getPassword() - { - return authContext.get( AuthenticationContext.PASSWORD ); - } - - @Override - public String getPrivateKey() - { - return authContext.get( AuthenticationContext.PRIVATE_KEY_PATH ); - } - - @Override - public String getPassphrase() - { - return authContext.get( AuthenticationContext.PRIVATE_KEY_PASSPHRASE ); - } - }; - } - - return auth; - } - - private ProxyInfoProvider getProxy( RemoteRepository repository, final AuthenticationContext authContext ) - { - ProxyInfoProvider proxy = null; - - Proxy p = repository.getProxy(); - if ( p != null ) - { - final ProxyInfo prox; - if ( authContext != null ) - { - prox = new ProxyInfo() - { - @Override - public String getUserName() - { - return authContext.get( AuthenticationContext.USERNAME ); - } - - @Override - public String getPassword() - { - return authContext.get( AuthenticationContext.PASSWORD ); - } - - @Override - public String getNtlmDomain() - { - return authContext.get( AuthenticationContext.NTLM_DOMAIN ); - } - - @Override - public String getNtlmHost() - { - return authContext.get( AuthenticationContext.NTLM_WORKSTATION ); - } - }; - } - else - { - prox = new ProxyInfo(); - } - prox.setType( p.getType() ); - prox.setHost( p.getHost() ); - prox.setPort( p.getPort() ); - - proxy = protocol -> prox; - } - - return proxy; - } - - @Override - @Nonnull - public Optional findBuild( CacheContext context ) throws IOException - { - final String resourceUrl = doGetResourceUrl( context, BUILDINFO_XML ); - return doGet( resourceUrl ) - .map( content -> new Build( xmlService.loadBuild( content ), CacheSource.REMOTE ) ); - } - - @Override - public boolean getArtifactContent( CacheContext context, Artifact artifact, Path target ) - throws IOException - { - return doGet( doGetResourceUrl( context, artifact.getFileName() ), target ); - } - - @Override - public void saveBuildInfo( CacheResult cacheResult, Build build ) - throws IOException - { - final String resourceUrl = doGetResourceUrl( cacheResult.getContext(), BUILDINFO_XML ); - doPut( resourceUrl, xmlService.toBytes( build.getDto() ) ); - } - - - @Override - public void saveCacheReport( String buildId, MavenSession session, CacheReport cacheReport ) throws IOException - { - MavenProject rootProject = session.getTopLevelProject(); - final String resourceUrl = doGetResourceUrl( CACHE_REPORT_XML, rootProject, buildId ); - doPut( resourceUrl, xmlService.toBytes( cacheReport ) ); - } - - @Override - public void saveArtifactFile( CacheResult cacheResult, - org.apache.maven.artifact.Artifact artifact ) throws IOException - { - final String resourceUrl = doGetResourceUrl( cacheResult.getContext(), CacheUtils.normalizedName( artifact ) ); - doPut( resourceUrl, artifact.getFile().toPath() ); - } - - @Override - public String getResourceUrl( CacheContext context, String filename ) - { - String base = cacheConfig.getUrl(); - return base.endsWith( "/" ) - ? base + doGetResourceUrl( context, filename ) - : base + "/" + doGetResourceUrl( context, filename ); - } - - public String doGetResourceUrl( CacheContext context, String filename ) - { - return doGetResourceUrl( filename, context.getProject(), context.getInputInfo().getChecksum() ); - } - - private String doGetResourceUrl( String filename, MavenProject project, String checksum ) - { - return doGetResourceUrl( filename, project.getGroupId(), project.getArtifactId(), checksum ); - } - - private String doGetResourceUrl( String filename, String groupId, String artifactId, String checksum ) - { - return MavenProjectInput.CACHE_IMPLEMENTATION_VERSION + "/" + groupId + "/" - + artifactId + "/" + checksum + "/" + filename; - } - - @Override - public Optional findBaselineBuild( MavenProject project ) - { - Optional> cachedProjectsHolder = findCacheInfo() - .map( CacheReport::getProjects ); - - if ( !cachedProjectsHolder.isPresent() ) - { - return Optional.empty(); - } - - final List projects = cachedProjectsHolder.get(); - final Optional projectReportHolder = projects.stream().filter( p -> - project.getArtifactId().equals( p.getArtifactId() ) - && project.getGroupId().equals( p.getGroupId() ) ).findFirst(); - - if ( !projectReportHolder.isPresent() ) - { - return Optional.empty(); - } - - final ProjectReport projectReport = projectReportHolder.get(); - - String url; - if ( projectReport.getUrl() != null ) - { - url = projectReport.getUrl(); - LOGGER.info( "Retrieving baseline buildinfo: {}", url ); - } - else - { - url = doGetResourceUrl( BUILDINFO_XML, project, projectReport.getChecksum() ); - LOGGER.info( "Baseline project record doesn't have url, trying default location {}", url ); - } - - try - { - return doGet( url ) - .map( content -> new Build( xmlService.loadBuild( content ), CacheSource.REMOTE ) ); - } - catch ( Exception e ) - { - LOGGER.warn( "Error restoring baseline build at url: {}, skipping diff", url, e ); - return Optional.empty(); - } - } - - private Optional findCacheInfo() - { - Optional report = cacheReportSupplier.get(); - if ( !report.isPresent() ) - { - try - { - LOGGER.info( "Downloading baseline cache report from: {}", cacheConfig.getBaselineCacheUrl() ); - return doGet( cacheConfig.getBaselineCacheUrl() ).map( xmlService::loadCacheReport ); - } - catch ( Exception e ) - { - LOGGER.error( "Error downloading baseline report from: {}, skipping diff.", - cacheConfig.getBaselineCacheUrl(), e ); - report = Optional.empty(); - } - cacheReportSupplier.compareAndSet( null, report ); - } - return report; - } - - private void doPut( String url, Path path ) throws IOException - { - try - { - Wagon wagon = pollWagon(); - try - { - wagon.put( path.toFile(), url ); - } - finally - { - wagons.add( wagon ); - } - } - catch ( Exception e ) - { - throw new IOException( "Unable to upload resource " + url, e ); - } - } - - private void doPut( String url, byte[] data ) throws IOException - { - try - { - Wagon wagon = pollWagon(); - try - { - if ( wagon instanceof StreamingWagon ) - { - ( ( StreamingWagon ) wagon ).putFromStream( - new ByteArrayInputStream( data ), url, data.length, 0 ); - } - else - { - File temp = createTempFile(); - try - { - Files.write( temp.toPath(), data ); - wagon.put( temp, url ); - } - finally - { - delete( temp ); - } - } - } - finally - { - wagons.add( wagon ); - } - } - catch ( Exception e ) - { - throw new IOException( "Unable to upload resource " + url, e ); - } - } - - private Optional doGet( String url ) throws IOException - { - try - { - Wagon wagon = pollWagon(); - try - { - if ( wagon instanceof StreamingWagon ) - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ( ( StreamingWagon ) wagon ).getToStream( url, baos ); - return Optional.of( baos.toByteArray() ); - } - else - { - File temp = createTempFile(); - try - { - wagon.get( url, temp ); - return Optional.of( Files.readAllBytes( temp.toPath() ) ); - } - finally - { - delete( temp ); - } - } - } - finally - { - wagons.add( wagon ); - } - } - catch ( ResourceDoesNotExistException e ) - { - return Optional.empty(); - } - catch ( Exception e ) - { - throw new IOException( "Unable to download resource " + url, e ); - } - } - - private boolean doGet( String url, Path target ) throws IOException - { - try - { - Wagon wagon = pollWagon(); - try - { - wagon.get( url, target.toFile() ); - return true; - } - finally - { - wagons.add( wagon ); - } - } - catch ( ResourceDoesNotExistException e ) - { - return false; - } - catch ( Exception e ) - { - throw new IOException( "Unable to download resource " + url, e ); - } - } - - private File createTempFile() throws IOException - { - return File.createTempFile( "maven-caching-", ".temp" ); - } - - @SuppressWarnings( "ResultOfMethodCallIgnored" ) - private void delete( File temp ) - { - temp.delete(); - } - - private Wagon lookupWagon() throws ComponentLookupException - { - return wagonProvider.lookup( wagonHint ); - } - - private void releaseWagon( Wagon wagon ) - { - try - { - wagonProvider.release( wagon ); - } - catch ( ComponentLifecycleException e ) - { - // ignore - } - } - - private void connectWagon( Wagon wagon ) - throws WagonException - { - if ( !headers.isEmpty() ) - { - try - { - Method setHttpHeaders = wagon.getClass().getMethod( "setHttpHeaders", Properties.class ); - setHttpHeaders.invoke( wagon, headers ); - } - catch ( NoSuchMethodException e ) - { - // normal for non-http wagons - } - catch ( InvocationTargetException | IllegalAccessException | RuntimeException e ) - { - LOGGER.debug( "Could not set user agent for Wagon {}", wagon.getClass().getName(), e ); - } - } - - RepositorySystemSession session = mavenSession.getRepositorySession(); - int connectTimeout = - ConfigUtils.getInteger( session, ConfigurationProperties.DEFAULT_CONNECT_TIMEOUT, - ConfigurationProperties.CONNECT_TIMEOUT ); - int requestTimeout = - ConfigUtils.getInteger( session, ConfigurationProperties.DEFAULT_REQUEST_TIMEOUT, - ConfigurationProperties.REQUEST_TIMEOUT ); - - wagon.setTimeout( Math.max( Math.max( connectTimeout, requestTimeout ), 0 ) ); - - wagon.setInteractive( ConfigUtils.getBoolean( session, ConfigurationProperties.DEFAULT_INTERACTIVE, - ConfigurationProperties.INTERACTIVE ) ); - - Object configuration = ConfigUtils.getObject( session, null, - CONFIG_PROP_CONFIG + "." + repository.getId() ); - if ( configuration != null && wagonConfigurator != null ) - { - try - { - wagonConfigurator.configure( wagon, configuration ); - } - catch ( Exception e ) - { - LOGGER.warn( "Could not apply configuration for {} to Wagon {}", - repository.getId(), wagon.getClass().getName(), e ); - } - } - - wagon.connect( wagonRepo, wagonAuth, wagonProxy ); - } - - private void disconnectWagon( Wagon wagon ) - { - try - { - if ( wagon != null ) - { - wagon.disconnect(); - } - } - catch ( WagonException e ) - { - LOGGER.debug( "Could not disconnect Wagon {}", wagon, e ); - } - } - - private Wagon pollWagon() - throws Exception - { - Wagon wagon = wagons.poll(); - - if ( wagon == null ) - { - try - { - wagon = lookupWagon(); - connectWagon( wagon ); - } - catch ( Exception e ) - { - releaseWagon( wagon ); - throw e; - } - } - else if ( wagon.getRepository() == null ) - { - try - { - connectWagon( wagon ); - } - catch ( WagonException e ) - { - wagons.add( wagon ); - throw e; - } - } - - return wagon; - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/artifact/RestoredArtifact.java b/maven-caching/src/main/java/org/apache/maven/caching/artifact/RestoredArtifact.java deleted file mode 100644 index 436372afd56b..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/artifact/RestoredArtifact.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.apache.maven.caching.artifact; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.InvalidArtifactRTException; -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.RunnableFuture; - -import static java.util.Objects.requireNonNull; - -/** - * Overrides default file behavior with async file holder to restore files from cache lazy. Similar to {@link - * org.apache.maven.project.artifact.AttachedArtifact} - */ -public class RestoredArtifact extends DefaultArtifact -{ - - private static final Logger LOGGER = LoggerFactory.getLogger( RestoredArtifact.class ); - - private volatile Future fileFuture; - - public RestoredArtifact( Artifact parent, Future fileFuture, String type, String classifier, - ArtifactHandler handler ) - { - super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type, - classifier, handler, parent.isOptional() ); - this.fileFuture = requireNonNull( fileFuture, "fileFuture == null" ); - } - - /** - * Returns file using caller thread to download it if necessary - */ - @Override - public File getFile() - { - - if ( !fileFuture.isDone() ) - { - if ( fileFuture instanceof RunnableFuture ) - { - try - { - LOGGER.trace( "Artifact file {} is not yet retrieved, downloading directly", - getDependencyConflictId() ); - ( (RunnableFuture) fileFuture ).run(); - } - catch ( RuntimeException e ) - { - throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), - getVersion(), getType(), - "Error retrieving artifact file", e ); - } - } - else - { - LOGGER.trace( "Artifact file {} is not yet retrieved, waiting for download to complete", - getDependencyConflictId() ); - } - } - - try - { - return fileFuture.get(); - } - catch ( InterruptedException e ) - { - Thread.currentThread().interrupt(); - throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), - getVersion(), getType(), "Interrupted while retrieving artifact file", e ); - } - catch ( ExecutionException e ) - { - throw new InvalidArtifactRTException( getGroupId(), getArtifactId(), - getVersion(), getType(), "Error retrieving artifact file", - e.getCause() ); - } - } - - - @Override - public void setFile( File destination ) - { - this.fileFuture = CompletableFuture.completedFuture( destination ); - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java deleted file mode 100644 index bcc017b8caab..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/DependencyNotResolvedException.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apache.maven.caching.checksum; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * DependencyNotResolvedException - */ -public class DependencyNotResolvedException extends RuntimeException -{ - public DependencyNotResolvedException( String message ) - { - super( message ); - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java deleted file mode 100644 index 81e9c5bb703f..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/DigestUtils.java +++ /dev/null @@ -1,188 +0,0 @@ -package org.apache.maven.caching.checksum; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.hash.HashChecksum; -import org.apache.maven.caching.xml.build.DigestItem; -import org.mozilla.universalchardet.UniversalDetector; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.apache.commons.lang3.StringUtils.containsAny; -import static org.apache.commons.lang3.StringUtils.equalsAny; -import static org.apache.commons.lang3.StringUtils.startsWith; -import static org.apache.commons.lang3.StringUtils.startsWithAny; - -/** - * DigestUtils - */ -public class DigestUtils -{ - - private static final Logger LOGGER = LoggerFactory.getLogger( DigestUtils.class ); - - private static final ThreadLocal ENCODING_DETECTOR = - ThreadLocal.withInitial( () -> new UniversalDetector( null ) ); - - - public static DigestItem pom( HashChecksum checksum, String effectivePom ) - { - return item( "pom", effectivePom, checksum.update( effectivePom.getBytes( UTF_8 ) ) ); - } - - public static DigestItem file( HashChecksum checksum, Path basedir, Path file ) throws IOException - { - byte[] content = Files.readAllBytes( file ); - String normalized = normalize( basedir, file ); - DigestItem item = item( "file", normalized, checksum.update( content ) ); - try - { - populateContentDetails( file, content, item ); - } - catch ( IOException ignore ) - { - LOGGER.debug( "Failed to compute digest for file {}", normalized, ignore ); - } - return item; - } - - private static void populateContentDetails( Path file, byte[] content, DigestItem item ) throws IOException - { - String contentType = Files.probeContentType( file ); - if ( contentType != null ) - { - item.setContent( contentType ); - } - final boolean binary = isBinary( contentType ); - item.setIsText( isText( contentType ) ? "yes" : binary ? "no" : "unknown" ); - if ( !binary ) - { // probing application/ files as well though might be binary - UniversalDetector detector = ENCODING_DETECTOR.get(); - detector.reset(); - detector.handleData( content, 0, Math.min( content.length, 16 * 1024 ) ); - detector.dataEnd(); - String detectedCharset = detector.getDetectedCharset(); - Charset charset = UTF_8; - if ( detectedCharset != null ) - { - item.setCharset( detectedCharset ); - charset = Charset.forName( detectedCharset ); - } - CharBuffer charBuffer = charset.decode( ByteBuffer.wrap( content ) ); - String lineSeparator = detectLineSeparator( charBuffer ); - item.setEol( StringUtils.defaultString( lineSeparator, "unknown" ) ); - } - } - - // TODO add support for .gitattributes to statically configure file type before falling back to probe based content checks - private static boolean isText( String contentType ) - { - return startsWith( contentType, "text/" ) - || containsAny( contentType, "+json", "+xml" ) // common mime type suffixes - || equalsAny( contentType, // some common text types - "application/json", - "application/rtf", - "application/x-sh", - "application/xml", - "application/javascript", - "application/sql" - ); - } - - private static boolean isBinary( String contentType ) - { - return startsWithAny( contentType, "image/", "audio/", "video/", "font/" ) - || containsAny( contentType, "+zip", "+gzip" ) - || equalsAny( contentType, - "application/octet-stream", - "application/java-archive", - "application/x-bzip", - "application/x-bzip2", - "application/zip", - "application/gzip", - "application/x-tar", - "application/msword", - "application/vnd.ms-excel", - "application/vnd.ms-powerpoint", - "application/pdf" - ); - } - - public static DigestItem dependency( HashChecksum checksum, String key, String hash ) - { - return item( "dependency", key, checksum.update( hash ) ); - } - - private static String normalize( Path basedirPath, Path file ) - { - return FilenameUtils.separatorsToUnix( relativize( basedirPath, file ).toString() ); - } - - private static Path relativize( Path basedirPath, Path file ) - { - try - { - return basedirPath.relativize( file ); - } - catch ( Exception ignore ) - { - return file; - } - } - - private static DigestItem item( String type, String reference, String hash ) - { - final DigestItem item = new DigestItem(); - item.setType( type ); - item.setValue( reference ); - item.setHash( hash ); - return item; - } - - private DigestUtils() - { - } - - public static String detectLineSeparator( CharSequence text ) - { - // first line break only - int index = StringUtils.indexOfAny( text, "\n\r" ); - if ( index == -1 || index >= text.length() ) - { - return null; - } - char ch = text.charAt( index ); - if ( ch == '\r' ) - { - return index + 1 < text.length() && text.charAt( index + 1 ) == '\n' ? "CRLF" : "CR"; - } - return ch == '\n' ? "LF" : null; - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java deleted file mode 100644 index 1be6743f433a..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/KeyUtils.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.apache.maven.caching.checksum; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.xml.build.Artifact; -import org.apache.maven.project.MavenProject; - -/** - * KeyUtils - */ -public class KeyUtils -{ - - private static final String SEPARATOR = ":"; - - public static String getProjectKey( MavenProject project ) - { - return getProjectKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ); - } - - public static String getProjectKey( String groupId, String artifactId, String version ) - { - return StringUtils.joinWith( SEPARATOR, groupId, artifactId, version ); - } - - public static String getVersionlessProjectKey( MavenProject project ) - { - return StringUtils.joinWith( SEPARATOR, project.getGroupId(), project.getArtifactId() ); - } - - public static String getArtifactKey( Artifact artifact ) - { - return getArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), - artifact.getClassifier(), artifact.getVersion() ); - } - - public static String getVersionlessArtifactKey( org.apache.maven.artifact.Artifact artifact ) - { - return getVersionlessArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), - artifact.getClassifier() ); - } - - - /** - * Computes the key for the given artifact, using the given type instead of the one defined in the artifact. - */ - public static String getArtifactKey( Artifact artifact, String type ) - { - return getArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), type, - artifact.getClassifier(), artifact.getVersion() ); - } - - public static String getArtifactKey( org.apache.maven.artifact.Artifact artifact ) - { - return getArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), - artifact.getClassifier(), artifact.getVersion() ); - } - - public static String getArtifactKey( String groupId, String artifactId, String type, - String classifier, String version ) - { - if ( classifier != null ) - { - return StringUtils.joinWith( SEPARATOR, groupId, artifactId, type, classifier, version ); - } - else - { - return StringUtils.joinWith( SEPARATOR, groupId, artifactId, type, version ); - } - } - - public static String getVersionlessArtifactKey( String groupId, String artifactId, String type, - String classifier ) - { - if ( classifier != null ) - { - return StringUtils.joinWith( SEPARATOR, groupId, artifactId, type, classifier ); - } - else - { - return StringUtils.joinWith( SEPARATOR, groupId, artifactId, type ); - } - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java deleted file mode 100644 index 7edffbedf6dc..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/MavenProjectInput.java +++ /dev/null @@ -1,792 +0,0 @@ -package org.apache.maven.caching.checksum; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.nio.file.DirectoryStream; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Properties; -import java.util.Set; -import java.util.SortedMap; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.function.Predicate; - -import javax.annotation.Nonnull; - -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; -import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.caching.MultiModuleSupport; -import org.apache.maven.caching.NormalizedModelProvider; -import org.apache.maven.caching.PluginScanConfig; -import org.apache.maven.caching.CacheUtils; -import org.apache.maven.caching.ProjectInputCalculator; -import org.apache.maven.caching.RemoteCacheRepository; -import org.apache.maven.caching.ScanConfigProperties; -import org.apache.maven.caching.hash.HashAlgorithm; -import org.apache.maven.caching.hash.HashChecksum; -import org.apache.maven.caching.xml.CacheConfig; -import org.apache.maven.caching.xml.DtoUtils; -import org.apache.maven.caching.xml.build.DigestItem; -import org.apache.maven.caching.xml.build.ProjectsInputInfo; -import org.apache.maven.caching.xml.config.Exclude; -import org.apache.maven.caching.xml.config.Include; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Model; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginExecution; -import org.apache.maven.model.Resource; -import org.apache.maven.model.io.xpp3.MavenXpp3Writer; -import org.apache.maven.project.MavenProject; -import org.apache.maven.repository.RepositorySystem; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.WriterFactory; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.apache.commons.lang3.StringUtils.contains; -import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; -import static org.apache.commons.lang3.StringUtils.equalsAnyIgnoreCase; -import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.apache.commons.lang3.StringUtils.replaceEachRepeatedly; -import static org.apache.commons.lang3.StringUtils.startsWithAny; -import static org.apache.commons.lang3.StringUtils.stripToEmpty; -import static org.apache.maven.caching.CacheUtils.isPom; -import static org.apache.maven.caching.CacheUtils.isSnapshot; - -/** - * MavenProjectInput - */ -public class MavenProjectInput -{ - - /** - * Version of hashing algorithm implementation. It is recommended to change to simplify remote cache maintenance - */ - public static final String CACHE_IMPLEMENTATION_VERSION = "v1"; - - /** - * property name to pass glob value. The glob to be used to list directory files in plugins scanning - */ - private static final String CACHE_INPUT_GLOB_NAME = "remote.cache.input.glob"; - /** - * default glob, bbsdk/abfx specific - */ - public static final String DEFAULT_GLOB = "{*.java,*.groovy,*.yaml,*.svcd,*.proto,*assembly.xml,assembly" - + "*.xml,*logback.xml,*.vm,*.ini,*.jks,*.properties,*.sh,*.bat}"; - /** - * property name prefix to pass input files with project properties. smth like remote.cache.input.1 will be - * accepted - */ - private static final String CACHE_INPUT_NAME = "remote.cache.input"; - /** - * property name prefix to exclude files from input. smth like remote.cache.exclude.1 should be set in project - * props - */ - private static final String CACHE_EXCLUDE_NAME = "remote.cache.exclude"; - /** - * Flag to control if we should check values from plugin configs as file system objects - */ - private static final String CACHE_PROCESS_PLUGINS = "remote.cache.processPlugins"; - - private static final Logger LOGGER = LoggerFactory.getLogger( MavenProjectInput.class ); - - private final MavenProject project; - private final MavenSession session; - private final RemoteCacheRepository remoteCache; - private final RepositorySystem repoSystem; - private final CacheConfig config; - private final PathIgnoringCaseComparator fileComparator; - private final List filteredOutPaths; - private final NormalizedModelProvider normalizedModelProvider; - private final MultiModuleSupport multiModuleSupport; - private final ProjectInputCalculator projectInputCalculator; - private final Path baseDirPath; - private final String dirGlob; - private final boolean processPlugins; - - @SuppressWarnings( "checkstyle:parameternumber" ) - public MavenProjectInput( MavenProject project, - NormalizedModelProvider normalizedModelProvider, - MultiModuleSupport multiModuleSupport, - ProjectInputCalculator projectInputCalculator, - MavenSession session, - CacheConfig config, - RepositorySystem repoSystem, - RemoteCacheRepository remoteCache ) - { - this.project = project; - this.normalizedModelProvider = normalizedModelProvider; - this.multiModuleSupport = multiModuleSupport; - this.projectInputCalculator = projectInputCalculator; - this.session = session; - this.config = config; - this.baseDirPath = project.getBasedir().toPath().toAbsolutePath(); - this.repoSystem = repoSystem; - this.remoteCache = remoteCache; - Properties properties = project.getProperties(); - this.dirGlob = properties.getProperty( CACHE_INPUT_GLOB_NAME, config.getDefaultGlob() ); - this.processPlugins = Boolean.parseBoolean( - properties.getProperty( CACHE_PROCESS_PLUGINS, config.isProcessPlugins() ) ); - - org.apache.maven.model.Build build = project.getBuild(); - filteredOutPaths = new ArrayList<>( Arrays.asList( normalizedPath( build.getDirectory() ), // target by default - normalizedPath( build.getOutputDirectory() ), normalizedPath( build.getTestOutputDirectory() ) ) ); - - List excludes = config.getGlobalExcludePaths(); - for ( Exclude excludePath : excludes ) - { - filteredOutPaths.add( Paths.get( excludePath.getValue() ) ); - } - - for ( String propertyName : properties.stringPropertyNames() ) - { - if ( propertyName.startsWith( CACHE_EXCLUDE_NAME ) ) - { - filteredOutPaths.add( Paths.get( properties.getProperty( propertyName ) ) ); - } - } - - this.fileComparator = new PathIgnoringCaseComparator(); - } - - public ProjectsInputInfo calculateChecksum() throws IOException - { - final long t0 = System.currentTimeMillis(); - - final String effectivePom = getEffectivePom( normalizedModelProvider.normalizedModel( project ) ); - final SortedSet inputFiles = isPom( project ) ? Collections.emptySortedSet() : getInputFiles(); - final SortedMap dependenciesChecksum = getMutableDependencies(); - - final long t1 = System.currentTimeMillis(); - - // hash items: effective pom + input files + dependencies - final int count = 1 + inputFiles.size() + dependenciesChecksum.size(); - final List items = new ArrayList<>( count ); - final HashChecksum checksum = config.getHashFactory().createChecksum( count ); - - Optional baselineHolder = Optional.empty(); - if ( config.isBaselineDiffEnabled() ) - { - baselineHolder = - remoteCache.findBaselineBuild( project ).map( b -> b.getDto().getProjectsInputInfo() ); - } - - DigestItem effectivePomChecksum = DigestUtils.pom( checksum, effectivePom ); - items.add( effectivePomChecksum ); - final boolean compareWithBaseline = config.isBaselineDiffEnabled() && baselineHolder.isPresent(); - if ( compareWithBaseline ) - { - checkEffectivePomMatch( baselineHolder.get(), effectivePomChecksum ); - } - - boolean sourcesMatched = true; - for ( Path file : inputFiles ) - { - DigestItem fileDigest = DigestUtils.file( checksum, baseDirPath, file ); - items.add( fileDigest ); - if ( compareWithBaseline ) - { - sourcesMatched &= checkItemMatchesBaseline( baselineHolder.get(), fileDigest ); - } - } - if ( compareWithBaseline ) - { - LOGGER.info( "Source code: {}", sourcesMatched ? "MATCHED" : "OUT OF DATE" ); - } - - boolean dependenciesMatched = true; - for ( Map.Entry entry : dependenciesChecksum.entrySet() ) - { - DigestItem dependencyDigest = - DigestUtils.dependency( checksum, entry.getKey(), entry.getValue() ); - items.add( dependencyDigest ); - if ( compareWithBaseline ) - { - dependenciesMatched &= checkItemMatchesBaseline( baselineHolder.get(), dependencyDigest ); - } - } - - if ( compareWithBaseline ) - { - LOGGER.info( "Dependencies: {}", dependenciesMatched ? "MATCHED" : "OUT OF DATE" ); - } - - final ProjectsInputInfo projectsInputInfoType = new ProjectsInputInfo(); - projectsInputInfoType.setChecksum( checksum.digest() ); - projectsInputInfoType.getItems().addAll( items ); - - final long t2 = System.currentTimeMillis(); - - for ( DigestItem item : projectsInputInfoType.getItems() ) - { - LOGGER.debug( "Hash calculated, item: {}, hash: {}", item.getType(), item.getHash() ); - } - LOGGER.info( "Project inputs calculated in {} ms. {} checksum [{}] calculated in {} ms.", - t1 - t0, config.getHashFactory().getAlgorithm(), projectsInputInfoType.getChecksum(), t2 - t1 ); - return projectsInputInfoType; - } - - private void checkEffectivePomMatch( ProjectsInputInfo baselineBuild, DigestItem effectivePomChecksum ) - { - Optional pomHolder = Optional.empty(); - for ( DigestItem it : baselineBuild.getItems() ) - { - if ( it.getType().equals( "pom" ) ) - { - pomHolder = Optional.of( it ); - break; - } - } - - if ( pomHolder.isPresent() ) - { - DigestItem pomItem = pomHolder.get(); - final boolean matches = StringUtils.equals( pomItem.getHash(), effectivePomChecksum.getHash() ); - if ( !matches ) - { - LOGGER.info( "Mismatch in effective poms. Current: {}, remote: {}", - effectivePomChecksum.getHash(), pomItem.getHash() ); - } - LOGGER.info( "Effective pom: {}", matches ? "MATCHED" : "OUT OF DATE" ); - } - } - - private boolean checkItemMatchesBaseline( ProjectsInputInfo baselineBuild, DigestItem fileDigest ) - { - Optional baselineFileDigest = Optional.empty(); - for ( DigestItem it : baselineBuild.getItems() ) - { - if ( it.getType().equals( fileDigest.getType() ) - && fileDigest.getValue().equals( it.getValue().trim() ) ) - { - baselineFileDigest = Optional.of( it ); - break; - } - } - - boolean matched = false; - if ( baselineFileDigest.isPresent() ) - { - String hash = baselineFileDigest.get().getHash(); - matched = StringUtils.equals( hash, fileDigest.getHash() ); - if ( !matched ) - { - LOGGER.info( "Mismatch in {}: {}. Local hash: {}, remote: {}", - fileDigest.getType(), fileDigest.getValue(), fileDigest.getHash(), hash ); - } - } - else - { - LOGGER.info( "Mismatch in {}: {}. Not found in remote cache", - fileDigest.getType(), fileDigest.getValue() ); - } - return matched; - } - - /** - * @param prototype effective model fully resolved by maven build. Do not pass here just parsed Model. - */ - private String getEffectivePom( Model prototype ) throws IOException - { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - - Writer writer = null; - try - { - writer = WriterFactory.newXmlWriter( output ); - new MavenXpp3Writer().write( writer, prototype ); - - //normalize env specifics - final String[] searchList = {baseDirPath.toString(), "\\", "windows", "linux"}; - final String[] replacementList = {"", "/", "os.classifier", "os.classifier"}; - - return replaceEachRepeatedly( output.toString(), searchList, replacementList ); - - } - finally - { - IOUtil.close( writer ); - } - } - - private SortedSet getInputFiles() - { - long start = System.currentTimeMillis(); - HashSet visitedDirs = new HashSet<>(); - ArrayList collectedFiles = new ArrayList<>(); - - org.apache.maven.model.Build build = project.getBuild(); - - final boolean recursive = true; - startWalk( Paths.get( build.getSourceDirectory() ), dirGlob, recursive, collectedFiles, visitedDirs ); - for ( Resource resource : build.getResources() ) - { - startWalk( Paths.get( resource.getDirectory() ), dirGlob, recursive, collectedFiles, visitedDirs ); - } - - startWalk( Paths.get( build.getTestSourceDirectory() ), dirGlob, recursive, collectedFiles, visitedDirs ); - for ( Resource testResource : build.getTestResources() ) - { - startWalk( Paths.get( testResource.getDirectory() ), dirGlob, recursive, collectedFiles, visitedDirs ); - } - - Properties properties = project.getProperties(); - for ( String name : properties.stringPropertyNames() ) - { - if ( name.startsWith( CACHE_INPUT_NAME ) ) - { - String path = properties.getProperty( name ); - startWalk( Paths.get( path ), dirGlob, recursive, collectedFiles, visitedDirs ); - } - } - - List includes = config.getGlobalIncludePaths(); - for ( Include include : includes ) - { - final String path = include.getValue(); - final String glob = defaultIfEmpty( include.getGlob(), dirGlob ); - startWalk( Paths.get( path ), glob, include.isRecursive(), collectedFiles, visitedDirs ); - } - - long walkKnownPathsFinished = System.currentTimeMillis() - start; - - LOGGER.info( "Scanning plugins configurations to find input files. Probing is {}", processPlugins - ? "enabled, values will be checked for presence in file system" - : "disabled, only tags with attribute " + CACHE_INPUT_NAME + "=\"true\" will be added" ); - - if ( processPlugins ) - { - collectFromPlugins( collectedFiles, visitedDirs ); - } - else - { - LOGGER.info( "Skipping check plugins scan (probing is disabled by config)" ); - } - - long pluginsFinished = System.currentTimeMillis() - start - walkKnownPathsFinished; - - TreeSet sorted = new TreeSet<>( fileComparator ); - for ( Path collectedFile : collectedFiles ) - { - sorted.add( collectedFile.normalize().toAbsolutePath() ); - } - - LOGGER.info( "Found {} input files. Project dir processing: {}, plugins: {} millis", - sorted.size(), walkKnownPathsFinished, pluginsFinished ); - LOGGER.debug( "Src input: {}", sorted ); - - return sorted; - } - - /** - * entry point for directory walk - */ - private void startWalk( Path candidate, - String glob, - boolean recursive, - List collectedFiles, - Set visitedDirs ) - { - Path normalized = candidate.isAbsolute() ? candidate : baseDirPath.resolve( candidate ); - normalized = normalized.toAbsolutePath().normalize(); - WalkKey key = new WalkKey( normalized, glob, recursive ); - if ( visitedDirs.contains( key ) || !Files.exists( normalized ) ) - { - return; - } - - if ( Files.isDirectory( normalized ) ) - { - if ( baseDirPath.startsWith( normalized ) ) - { // requested to walk parent, can do only non recursive - key = new WalkKey( normalized, glob, false ); - } - try - { - walkDir( key, collectedFiles, visitedDirs ); - visitedDirs.add( key ); - } - catch ( IOException e ) - { - throw new RuntimeException( e ); - } - } - else - { - if ( !isFilteredOutSubpath( normalized ) ) - { - LOGGER.debug( "Adding: {}", normalized ); - collectedFiles.add( normalized ); - } - } - } - - private Path normalizedPath( String directory ) - { - return Paths.get( directory ).normalize(); - } - - private void collectFromPlugins( List files, HashSet visitedDirs ) - { - List plugins = project.getBuild().getPlugins(); - for ( Plugin plugin : plugins ) - { - PluginScanConfig scanConfig = config.getPluginDirScanConfig( plugin ); - - if ( scanConfig.isSkip() ) - { - LOGGER.debug( "Skipping plugin config scan (skip by config): {}", plugin.getArtifactId() ); - continue; - } - - Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); - LOGGER.debug( "Processing plugin config: {}", plugin.getArtifactId() ); - if ( configuration != null ) - { - addInputsFromPluginConfigs( configuration.getChildren(), scanConfig, files, visitedDirs ); - } - - for ( PluginExecution exec : plugin.getExecutions() ) - { - final PluginScanConfig executionScanConfig = config.getExecutionDirScanConfig( plugin, exec ); - PluginScanConfig mergedConfig = scanConfig.mergeWith( executionScanConfig ); - - if ( mergedConfig.isSkip() ) - { - LOGGER.debug( "Skipping plugin execution config scan (skip by config): {}, execId: {}", - plugin.getArtifactId(), exec.getId() ); - continue; - } - - Xpp3Dom execConfiguration = (Xpp3Dom) exec.getConfiguration(); - LOGGER.debug( "Processing plugin: {}, execution: {}", plugin.getArtifactId(), exec.getId() ); - - if ( execConfiguration != null ) - { - addInputsFromPluginConfigs( execConfiguration.getChildren(), mergedConfig, files, visitedDirs ); - } - } - } - } - - private Path walkDir( final WalkKey key, - final List collectedFiles, - final Set visitedDirs ) throws IOException - { - return Files.walkFileTree( key.getPath(), new SimpleFileVisitor() - { - @Override - public FileVisitResult preVisitDirectory( Path path, - BasicFileAttributes basicFileAttributes ) throws IOException - { - WalkKey currentDirKey = new WalkKey( path.toAbsolutePath().normalize(), key.getGlob(), - key.isRecursive() ); - if ( isHidden( path ) ) - { - LOGGER.debug( "Skipping subtree (hidden): {}", path ); - return FileVisitResult.SKIP_SUBTREE; - } - else if ( isFilteredOutSubpath( path ) ) - { - LOGGER.debug( "Skipping subtree (blacklisted): {}", path ); - return FileVisitResult.SKIP_SUBTREE; - } - else if ( visitedDirs.contains( currentDirKey ) ) - { - LOGGER.debug( "Skipping subtree (visited): {}", path ); - return FileVisitResult.SKIP_SUBTREE; - } - - walkDirectoryFiles( - path, - collectedFiles, - key.getGlob(), - entry -> filteredOutPaths.stream() - .anyMatch( it -> it.getFileName().equals( entry.getFileName() ) ) ); - - if ( !key.isRecursive() ) - { - LOGGER.debug( "Skipping subtree (non recursive): {}", path ); - return FileVisitResult.SKIP_SUBTREE; - } - - LOGGER.debug( "Visiting subtree: {}", path ); - return FileVisitResult.CONTINUE; - } - } ); - } - - private void addInputsFromPluginConfigs( Xpp3Dom[] configurationChildren, - PluginScanConfig scanConfig, - List files, HashSet visitedDirs ) - { - if ( configurationChildren == null ) - { - return; - } - - for ( Xpp3Dom configChild : configurationChildren ) - { - String tagName = configChild.getName(); - String tagValue = configChild.getValue(); - - if ( !scanConfig.accept( tagName ) ) - { - LOGGER.debug( "Skipping property (scan config)): {}, value: {}", - tagName, stripToEmpty( tagValue ) ); - continue; - } - - LOGGER.debug( "Checking xml tag. Tag: {}, value: {}", tagName, stripToEmpty( tagValue ) ); - - addInputsFromPluginConfigs( configChild.getChildren(), scanConfig, files, visitedDirs ); - - final ScanConfigProperties propertyConfig = scanConfig.getTagScanProperties( tagName ); - final String glob = defaultIfEmpty( propertyConfig.getGlob(), dirGlob ); - if ( "true".equals( configChild.getAttribute( CACHE_INPUT_NAME ) ) ) - { - LOGGER.info( "Found tag marked with {} attribute. Tag: {}, value: {}", - CACHE_INPUT_NAME, tagName, tagValue ); - startWalk( Paths.get( tagValue ), glob, propertyConfig.isRecursive(), files, visitedDirs ); - } - else - { - final Path candidate = getPathOrNull( tagValue ); - if ( candidate != null ) - { - startWalk( candidate, glob, propertyConfig.isRecursive(), files, visitedDirs ); - if ( "descriptorRef".equals( tagName ) ) - { // hardcoded logic for assembly plugin which could reference files omitting .xml suffix - startWalk( Paths.get( tagValue + ".xml" ), glob, propertyConfig.isRecursive(), files, - visitedDirs ); - } - } - } - } - } - - private Path getPathOrNull( String text ) - { - // small optimization to not probe not-paths - boolean blacklisted = isBlank( text ) - || equalsAnyIgnoreCase( text, "true", "false", "utf-8", "null", "\\" ) // common values - || contains( text, "*" ) // tag value is a glob or regex - unclear how to process - || ( contains( text, ":" ) && !contains( text, ":\\" ) )// artifactId - || startsWithAny( text, "com.", "org.", "io.", "java.", "javax." ) // java packages - || startsWithAny( text, "${env." ) // env variables in maven notation - || startsWithAny( text, "http:", "https:", "scm:", "ssh:", "git:", "svn:", "cp:", - "classpath:" ); // urls identified by common protocols - if ( !blacklisted ) - { - try - { - return Paths.get( text ); - } - catch ( Exception ignore ) - { - } - } - LOGGER.debug( "{}: {}", text, blacklisted ? "skipped(blacklisted literal)" : "invalid path" ); - return null; - } - - static void walkDirectoryFiles( Path dir, List collectedFiles, String glob, Predicate mustBeSkipped ) - { - if ( !Files.isDirectory( dir ) ) - { - return; - } - - try - { - try ( DirectoryStream stream = Files.newDirectoryStream( dir, glob ) ) - { - for ( Path entry : stream ) - { - if ( mustBeSkipped.test( entry ) ) - { - continue; - } - File file = entry.toFile(); - if ( file.isFile() && !isHidden( entry ) ) - { - collectedFiles.add( entry ); - } - } - } - } - catch ( IOException e ) - { - throw new RuntimeException( "Cannot process directory: " + dir, e ); - } - } - - private static boolean isHidden( Path entry ) throws IOException - { - return Files.isHidden( entry ) || entry.toFile().getName().startsWith( "." ); - } - - private boolean isFilteredOutSubpath( Path path ) - { - Path normalized = path.normalize(); - for ( Path filteredOutDir : filteredOutPaths ) - { - if ( normalized.startsWith( filteredOutDir ) ) - { - return true; - } - } - return false; - } - - private SortedMap getMutableDependencies() throws IOException - { - SortedMap result = new TreeMap<>(); - - for ( Dependency dependency : project.getDependencies() ) - { - - if ( CacheUtils.isPom( dependency ) ) - { - // POM dependency will be resolved by maven system to actual dependencies - // and will contribute to effective pom. - // Effective result will be recorded by #getNormalizedPom - // so pom dependencies must be skipped as meaningless by themselves - continue; - } - - // saved to index by the end of dependency build - MavenProject dependencyProject = multiModuleSupport.tryToResolveProject( - dependency.getGroupId(), - dependency.getArtifactId(), - dependency.getVersion() ) - .orElse( null ); - boolean isSnapshot = isSnapshot( dependency.getVersion() ); - if ( dependencyProject == null && !isSnapshot ) - { - // external immutable dependency, should skip - continue; - } - String projectHash; - if ( dependencyProject != null ) //part of multi module - { - projectHash = projectInputCalculator.calculateInput( dependencyProject ).getChecksum(); - } - else //this is a snapshot dependency - { - DigestItem resolved = resolveArtifact( - repoSystem.createDependencyArtifact( dependency ), - false - ); - projectHash = resolved.getHash(); - } - result.put( - KeyUtils.getVersionlessArtifactKey( repoSystem.createDependencyArtifact( dependency ) ), - projectHash - ); - } - return result; - } - - @Nonnull - private DigestItem resolveArtifact( final Artifact dependencyArtifact, - boolean isOffline ) throws IOException - { - ArtifactResolutionRequest request = new ArtifactResolutionRequest() - .setArtifact( dependencyArtifact ) - .setResolveRoot( true ) - .setResolveTransitively( false ) - .setLocalRepository( session.getLocalRepository() ) - .setRemoteRepositories( project.getRemoteArtifactRepositories() ) - .setOffline( session.isOffline() || isOffline ) - .setForceUpdate( session.getRequest().isUpdateSnapshots() ) - .setServers( session.getRequest().getServers() ) - .setMirrors( session.getRequest().getMirrors() ) - .setProxies( session.getRequest().getProxies() ); - - final ArtifactResolutionResult result = repoSystem.resolve( request ); - - if ( !result.isSuccess() ) - { - throw new DependencyNotResolvedException( "Cannot resolve in-project dependency: " + dependencyArtifact ); - } - - if ( !result.getMissingArtifacts().isEmpty() ) - { - throw new DependencyNotResolvedException( - "Cannot resolve artifact: " + dependencyArtifact + ", missing: " + result.getMissingArtifacts() ); - } - - if ( result.getArtifacts().size() != 1 ) - { - throw new IllegalStateException( - "Unexpected number of artifacts returned. Requested: " + dependencyArtifact - + ", expected: 1, actual: " + result.getArtifacts() ); - } - - final Artifact resolved = result.getArtifacts().iterator().next(); - - final HashAlgorithm algorithm = config.getHashFactory().createAlgorithm(); - final String hash = algorithm.hash( resolved.getFile().toPath() ); - return DtoUtils.createDigestedFile( resolved, hash ); - } - - /** - * PathIgnoringCaseComparator - */ - public static class PathIgnoringCaseComparator implements Comparator - { - @Override - public int compare( Path f1, Path f2 ) - { - String s1 = f1.toAbsolutePath().toString(); - String s2 = f2.toAbsolutePath().toString(); - if ( File.separator.equals( "\\" ) ) - { - s1 = s1.replaceAll( "\\\\", "/" ); - s2 = s2.replaceAll( "\\\\", "/" ); - } - return s1.compareToIgnoreCase( s2 ); - } - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/checksum/WalkKey.java b/maven-caching/src/main/java/org/apache/maven/caching/checksum/WalkKey.java deleted file mode 100644 index 31a23ded054d..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/checksum/WalkKey.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.apache.maven.caching.checksum; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.nio.file.Path; - -/** - * WalkKey - */ -public class WalkKey -{ - private final Path normalized; - private final String glob; - private final boolean recursive; - - public WalkKey( Path normalized, String glob, boolean recursive ) - { - this.normalized = normalized; - this.glob = glob; - this.recursive = recursive; - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( o == null || getClass() != o.getClass() ) - { - return false; - } - - WalkKey key = (WalkKey) o; - - if ( recursive != key.recursive ) - { - return false; - } - if ( !normalized.equals( key.normalized ) ) - { - return false; - } - return glob.equals( key.glob ); - } - - @Override - public int hashCode() - { - int result = normalized.hashCode(); - result = 31 * result + glob.hashCode(); - result = 31 * result + ( recursive ? 1 : 0 ); - return result; - } - - public Path getPath() - { - return normalized; - } - - public String getGlob() - { - return glob; - } - - public boolean isRecursive() - { - return recursive; - } - - @Override - public String toString() - { - return "WalkKey{" + "normalized=" + normalized + ", glob='" + glob + '\'' + ", recursive=" + recursive + '}'; - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java deleted file mode 100644 index 91acdf27b6d3..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/CloseableBuffer.java +++ /dev/null @@ -1,184 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; -import java.lang.reflect.Method; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.channels.FileChannel.MapMode; -import java.security.PrivilegedAction; - -import static java.security.AccessController.doPrivileged; -import static org.apache.maven.caching.hash.ReflectionUtils.getField; -import static org.apache.maven.caching.hash.ReflectionUtils.getMethod; - -/** - * CloseableBuffer https://stackoverflow.com/a/54046774 - */ -public class CloseableBuffer implements AutoCloseable -{ - - private static final Cleaner CLEANER = doPrivileged( new PrivilegedAction() - { - @Override - public Cleaner run() - { - final String jsv = System.getProperty( "java.specification.version", "9" ); - if ( jsv.startsWith( "1." ) ) - { - return DirectCleaner.isSupported() ? new DirectCleaner() : new NoopCleaner(); - } - else - { - return UnsafeCleaner.isSupported() ? new UnsafeCleaner() : new NoopCleaner(); - } - } - } ); - - public static CloseableBuffer directBuffer( int capacity ) - { - return new CloseableBuffer( ByteBuffer.allocateDirect( capacity ) ); - } - - public static CloseableBuffer mappedBuffer( FileChannel channel, MapMode mode ) throws IOException - { - return new CloseableBuffer( channel.map( mode, 0, channel.size() ) ); - } - - private ByteBuffer buffer; - - /** - * Unmap only DirectByteBuffer and MappedByteBuffer - */ - private CloseableBuffer( ByteBuffer buffer ) - { - // Java 8: buffer.isDirect() - this.buffer = buffer; - } - - /** - * Do not use buffer after close - */ - public ByteBuffer getBuffer() - { - return buffer; - } - - @Override - public void close() - { - // Java 8: () -> CLEANER.clean(buffer) - boolean done = doPrivileged( new PrivilegedAction() - { - @Override - public Boolean run() - { - return CLEANER.clean( buffer ); - } - } ); - if ( done ) - { - buffer = null; - } - } - - // Java 8: @FunctionalInterface - private interface Cleaner - { - boolean clean( ByteBuffer buffer ); - } - - private static class NoopCleaner implements Cleaner - { - @Override - public boolean clean( ByteBuffer buffer ) - { - return false; - } - } - - private static class DirectCleaner implements Cleaner - { - private static final Method ATTACHMENT = getMethod( "sun.nio.ch.DirectBuffer", - "attachment" ); - private static final Method CLEANER = getMethod( "sun.nio.ch.DirectBuffer", "cleaner" ); - private static final Method CLEAN = getMethod( "sun.misc.Cleaner", "clean" ); - - public static boolean isSupported() - { - return ATTACHMENT != null && CLEAN != null && CLEANER != null; - } - - /** - * Make sure duplicates and slices are not cleaned, since this can result in duplicate attempts to clean the - * same buffer, which trigger a crash with: "A fatal error has been detected by the Java Runtime Environment: - * EXCEPTION_ACCESS_VIOLATION" See: https://stackoverflow.com/a/31592947/3950982 - */ - @Override - public boolean clean( ByteBuffer buffer ) - { - try - { - if ( ATTACHMENT.invoke( buffer ) == null ) - { - CLEAN.invoke( CLEANER.invoke( buffer ) ); - return true; - } - } - catch ( Exception ignore ) - { - } - return false; - } - } - - private static class UnsafeCleaner implements Cleaner - { - // Java 9: getMethod("jdk.internal.misc.Unsafe", "invokeCleaner", ByteBuffer.class); - private static final Method INVOKE_CLEANER = getMethod( "sun.misc.Unsafe", "invokeCleaner", ByteBuffer.class ); - private static final Object UNSAFE = getField( "sun.misc.Unsafe", "theUnsafe" ); - - public static boolean isSupported() - { - return UNSAFE != null && INVOKE_CLEANER != null; - } - - /** - * Calling the above code in JDK9+ gives a reflection warning on stderr, - * Unsafe.theUnsafe.invokeCleaner(byteBuffer) - * makes the same call, but does not print the reflection warning - */ - @Override - public boolean clean( ByteBuffer buffer ) - { - try - { - // throws IllegalArgumentException if buffer is a duplicate or slice - INVOKE_CLEANER.invoke( UNSAFE, buffer ); - return true; - } - catch ( Exception ignore ) - { - } - return false; - } - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/Hash.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/Hash.java deleted file mode 100644 index 82220634cc6b..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/Hash.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; -import java.nio.file.Path; - -/** - * Hash - */ -public class Hash -{ - /** - * Algorithm - */ - public interface Algorithm - { - byte[] hash( byte[] array ); - - byte[] hash( Path path ) throws IOException; - } - - /** - * accumulates states and should be completed by {@link #digest()} - */ - public interface Checksum - { - void update( byte[] hash ); - - byte[] digest(); - } - - /** - * Factory - */ - public interface Factory - { - String getAlgorithm(); - - Algorithm algorithm(); - - Checksum checksum( int count ); - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java deleted file mode 100644 index ec6ad68a053d..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/HashAlgorithm.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; -import java.nio.file.Path; - -/** - * HashAlgorithm - */ -public class HashAlgorithm -{ - private final Hash.Algorithm algorithm; - - HashAlgorithm( Hash.Algorithm algorithm ) - { - this.algorithm = algorithm; - } - - public String hash( Path path ) throws IOException - { - return HexUtils.encode( algorithm.hash( path ) ); - } - - public String hash( byte[] bytes ) - { - return HexUtils.encode( algorithm.hash( bytes ) ); - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/HashChecksum.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/HashChecksum.java deleted file mode 100644 index 904077a6abae..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/HashChecksum.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; -import java.nio.file.Path; - -/** - * HashChecksum - */ -public class HashChecksum -{ - private final Hash.Algorithm algorithm; - private final Hash.Checksum checksum; - - HashChecksum( Hash.Algorithm algorithm, Hash.Checksum checksum ) - { - this.algorithm = algorithm; - this.checksum = checksum; - } - - public String update( Path path ) throws IOException - { - return updateAndEncode( algorithm.hash( path ) ); - } - - public String update( byte[] bytes ) - { - return updateAndEncode( algorithm.hash( bytes ) ); - } - - /** - * @param hexHash hash value in hex format. This method doesn't accept generic text - could result in error - */ - public String update( String hexHash ) - { - return updateAndEncode( HexUtils.decode( hexHash ) ); - } - - private String updateAndEncode( byte[] hash ) - { - checksum.update( hash ); - return HexUtils.encode( hash ); - } - - public String digest() - { - return HexUtils.encode( checksum.digest() ); - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/HashFactory.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/HashFactory.java deleted file mode 100644 index d610fceab924..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/HashFactory.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.security.NoSuchAlgorithmException; -import java.util.HashMap; -import java.util.Map; - -/** - * HashFactory - */ -public enum HashFactory -{ - SHA1( new SHA( "SHA-1" ) ), - SHA256( new SHA( "SHA-256" ) ), - SHA384( new SHA( "SHA-384" ) ), - SHA512( new SHA( "SHA-512" ) ), - XX( new XX() ), - XXMM( new XXMM() ); - - private static final Map LOOKUP = new HashMap<>(); - - static - { - for ( HashFactory factory : HashFactory.values() ) - { - LOOKUP.put( factory.getAlgorithm(), factory ); - } - } - - public static HashFactory of( String algorithm ) throws NoSuchAlgorithmException - { - final HashFactory factory = LOOKUP.get( algorithm ); - if ( factory == null ) - { - throw new NoSuchAlgorithmException( algorithm ); - } - return factory; - } - - private final Hash.Factory factory; - - HashFactory( Hash.Factory factory ) - { - this.factory = factory; - } - - public String getAlgorithm() - { - return factory.getAlgorithm(); - } - - public HashAlgorithm createAlgorithm() - { - return new HashAlgorithm( factory.algorithm() ); - } - - public HashChecksum createChecksum( int count ) - { - return new HashChecksum( factory.algorithm(), factory.checksum( count ) ); - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/HexUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/HexUtils.java deleted file mode 100644 index bff46df7cdf0..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/HexUtils.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.nio.charset.StandardCharsets; - -/** - * HexUtils - */ -@SuppressWarnings( "checkstyle:MagicNumber" ) -public class HexUtils -{ - - private static final byte[] ENC_ARRAY; - private static final byte[] DEC_ARRAY; - - static - { - ENC_ARRAY = new byte[16]; - DEC_ARRAY = new byte[256]; - for ( byte i = 0; i < 10; i++ ) - { - ENC_ARRAY[i] = ( byte ) ( '0' + i ); - DEC_ARRAY['0' + i] = i; - } - for ( byte i = 10; i < 16; i++ ) - { - ENC_ARRAY[i] = ( byte ) ( 'a' + i - 10 ); - DEC_ARRAY['a' + i - 10] = i; - DEC_ARRAY['A' + i - 10] = i; - } - } - - public static String encode( byte[] hash ) - { - byte[] hexChars = new byte[hash.length * 2]; - for ( int j = 0; j < hash.length; j++ ) - { - int v = hash[j] & 0xFF; - hexChars[j * 2] = ENC_ARRAY[v >>> 4]; - hexChars[j * 2 + 1] = ENC_ARRAY[v & 0x0F]; - } - return new String( hexChars, StandardCharsets.US_ASCII ); - } - - public static byte[] decode( String hex ) - { - int size = hex.length(); - if ( size % 2 != 0 ) - { - throw new IllegalArgumentException( "String length should be even" ); - } - byte[] bytes = new byte[ size / 2 ]; - int idx = 0; - for ( int i = 0; i < size; i += 2 ) - { - bytes[idx++] = ( byte ) ( DEC_ARRAY[hex.charAt( i )] << 4 | DEC_ARRAY[hex.charAt( i + 1 )] ); - } - return bytes; - } - - public static byte[] toByteArray( long value ) - { - byte[] result = new byte[8]; - for ( int i = 7; i >= 0; i-- ) - { - result[i] = ( byte ) ( value & 0xFF ); - value >>= 8; - } - return result; - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java deleted file mode 100644 index 259e6f0b7feb..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/ReflectionUtils.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -/** - * ReflectionUtils - */ -class ReflectionUtils -{ - static Method getMethod( String className, String methodName, Class... parameterTypes ) - { - try - { - final Method method = Class.forName( className ).getMethod( methodName, parameterTypes ); - method.setAccessible( true ); - return method; - } - catch ( Exception ignore ) - { - return null; - } - } - - static Object getField( String className, String fieldName ) - { - try - { - final Field field = Class.forName( className ).getDeclaredField( fieldName ); - field.setAccessible( true ); - return field.get( null ); - } - catch ( Exception ignore ) - { - return null; - } - } - - private ReflectionUtils() - { - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/SHA.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/SHA.java deleted file mode 100644 index e02dfe2f25e2..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/SHA.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.security.MessageDigest; - -/** - * SHA - */ -public class SHA implements Hash.Factory -{ - private static final ThreadLocal ALGORITHM = new ThreadLocal<>(); - private static final ThreadLocal CHECKSUM = new ThreadLocal<>(); - - private final String algorithm; - - SHA( String algorithm ) - { - this.algorithm = algorithm; - } - - @Override - public String getAlgorithm() - { - return algorithm; - } - - @Override - public Hash.Algorithm algorithm() - { - return new SHA.Algorithm( ThreadLocalDigest.get( ALGORITHM, algorithm ) ); - } - - @Override - public Hash.Checksum checksum( int count ) - { - return new SHA.Checksum( ThreadLocalDigest.get( CHECKSUM, algorithm ) ); - } - - private static class Algorithm implements Hash.Algorithm - { - private final MessageDigest digest; - - private Algorithm( MessageDigest digest ) - { - this.digest = digest; - } - - @Override - public byte[] hash( byte[] array ) - { - return digest.digest( array ); - } - - @Override - public byte[] hash( Path path ) throws IOException - { - return hash( Files.readAllBytes( path ) ); - } - } - - private static class Checksum implements Hash.Checksum - { - private final MessageDigest digest; - - private Checksum( MessageDigest digest ) - { - this.digest = digest; - } - - @Override - public void update( byte[] hash ) - { - digest.update( hash ); - } - - @Override - public byte[] digest() - { - return digest.digest(); - } - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java deleted file mode 100644 index 6d9f9d6269b7..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/ThreadLocalBuffer.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.nio.ByteBuffer; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -/** - * ThreadLocalBuffer - */ -public class ThreadLocalBuffer -{ - private static final ConcurrentMap LOCALS = new ConcurrentHashMap<>(); - - public static ByteBuffer get( ThreadLocal local, int capacity ) - { - final CloseableBuffer buffer = local.get(); - if ( buffer == null ) - { - return create( local, capacity ); - } - - if ( capacity( buffer ) < capacity ) - { - close( buffer ); - return create( local, capacity * 2 ); - } - - return clear( buffer ); - } - - @Override - public void finalize() - { - for ( CloseableBuffer buffer : LOCALS.keySet() ) - { - buffer.close(); - } - } - - private static ByteBuffer create( ThreadLocal local, int capacity ) - { - final CloseableBuffer buffer = CloseableBuffer.directBuffer( capacity ); - local.set( buffer ); - LOCALS.put( buffer, false ); - return buffer.getBuffer(); - } - - private static int capacity( CloseableBuffer buffer ) - { - return buffer.getBuffer().capacity(); - } - - private static ByteBuffer clear( CloseableBuffer buffer ) - { - return (ByteBuffer) buffer.getBuffer().clear(); - } - - private static void close( CloseableBuffer buffer ) - { - LOCALS.remove( buffer ); - buffer.close(); - } - - private ThreadLocalBuffer() - { - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java deleted file mode 100644 index 2df800e26f7a..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/ThreadLocalDigest.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Objects; - -/** - * ThreadLocalDigest - */ -public class ThreadLocalDigest -{ - public static MessageDigest get( ThreadLocal local, String algorithm ) - { - final MessageDigest digest = local.get(); - if ( digest == null ) - { - return create( local, algorithm ); - } - - if ( Objects.equals( digest.getAlgorithm(), algorithm ) ) - { - return reset( digest ); - } - - reset( digest ); - return create( local, algorithm ); - } - - private static MessageDigest create( ThreadLocal local, String algorithm ) - { - try - { - final MessageDigest digest = MessageDigest.getInstance( algorithm ); - local.set( digest ); - return digest; - } - catch ( NoSuchAlgorithmException e ) - { - throw new RuntimeException( "Cannot create message digest with algorithm: " + algorithm, e ); - } - } - - private static MessageDigest reset( MessageDigest digest ) - { - digest.reset(); - return digest; - } - - private ThreadLocalDigest() - { - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/XX.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/XX.java deleted file mode 100644 index 8ee08ce443d5..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/XX.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import net.openhft.hashing.LongHashFunction; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.file.Files; -import java.nio.file.Path; - -/** - * XX - */ -public class XX implements Hash.Factory -{ - static final LongHashFunction INSTANCE = LongHashFunction.xx(); - - @Override - public String getAlgorithm() - { - return "XX"; - } - - @Override - public Hash.Algorithm algorithm() - { - return new XX.Algorithm(); - } - - @Override - public Hash.Checksum checksum( int count ) - { - return new XX.Checksum( ByteBuffer.allocate( capacity( count ) ) ); - } - - static int capacity( int count ) - { - // Java 8: Long.BYTES - return count * Long.SIZE / Byte.SIZE; - } - - static class Algorithm implements Hash.Algorithm - { - @Override - public byte[] hash( byte[] array ) - { - return HexUtils.toByteArray( INSTANCE.hashBytes( array ) ); - } - - @Override - public byte[] hash( Path path ) throws IOException - { - return hash( Files.readAllBytes( path ) ); - } - } - - static class Checksum implements Hash.Checksum - { - private final ByteBuffer buffer; - - Checksum( ByteBuffer buffer ) - { - this.buffer = buffer; - } - - @Override - public void update( byte[] hash ) - { - buffer.put( hash ); - } - - @Override - public byte[] digest() - { - return HexUtils.toByteArray( INSTANCE.hashBytes( buffer, 0, buffer.position() ) ); - } - } - -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/hash/XXMM.java b/maven-caching/src/main/java/org/apache/maven/caching/hash/XXMM.java deleted file mode 100644 index 1ca8bac95f63..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/hash/XXMM.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; -import java.nio.channels.FileChannel; -import java.nio.file.Path; - -import static java.nio.channels.FileChannel.MapMode.READ_ONLY; -import static java.nio.file.StandardOpenOption.READ; - -/** - * XXMM - */ -public class XXMM implements Hash.Factory -{ - private static final ThreadLocal BUFFER = new ThreadLocal<>(); - - @Override - public String getAlgorithm() - { - return "XXMM"; - } - - @Override - public Hash.Algorithm algorithm() - { - return new Algorithm(); - } - - @Override - public Hash.Checksum checksum( int count ) - { - return new XX.Checksum( ThreadLocalBuffer.get( BUFFER, XX.capacity( count ) ) ); - } - - private static class Algorithm extends XX.Algorithm - { - @Override - public byte[] hash( Path path ) throws IOException - { - try ( FileChannel channel = FileChannel.open( path, READ ); - CloseableBuffer buffer = CloseableBuffer.mappedBuffer( channel, READ_ONLY ) ) - { - return HexUtils.toByteArray( XX.INSTANCE.hashBytes( buffer.getBuffer() ) ); - } - } - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java deleted file mode 100644 index 6339c547c390..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/Build.java +++ /dev/null @@ -1,203 +0,0 @@ -package org.apache.maven.caching.xml; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.caching.CacheUtils; -import org.apache.maven.caching.checksum.MavenProjectInput; -import org.apache.maven.caching.hash.HashAlgorithm; -import org.apache.maven.caching.xml.build.Artifact; -import org.apache.maven.caching.xml.build.CompletedExecution; -import org.apache.maven.caching.xml.build.DigestItem; -import org.apache.maven.caching.xml.build.ProjectsInputInfo; -import org.apache.maven.model.Dependency; -import org.apache.maven.plugin.MojoExecution; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; - -import static org.apache.maven.caching.CacheUtils.mojoExecutionKey; - -/** - * Build - */ -public class Build -{ - - final org.apache.maven.caching.xml.build.Build dto; - CacheSource source; - volatile Map execMap; - - public Build( List goals, - Artifact artifact, - List attachedArtifacts, - ProjectsInputInfo projectsInputInfo, - List completedExecutions, - String hashAlgorithm ) - { - this.dto = new org.apache.maven.caching.xml.build.Build(); - this.dto.setCacheImplementationVersion( MavenProjectInput.CACHE_IMPLEMENTATION_VERSION ); - this.dto.setBuildTime( new Date() ); - try - { - this.dto.setBuildServer( InetAddress.getLocalHost().getCanonicalHostName() ); - } - catch ( UnknownHostException ignore ) - { - this.dto.setBuildServer( "unknown" ); - } - this.dto.setHashFunction( hashAlgorithm ); - this.dto.setArtifact( artifact ); - this.dto.setGoals( goals ); - this.dto.setAttachedArtifacts( attachedArtifacts ); - this.dto.setExecutions( completedExecutions ); - this.dto.setProjectsInputInfo( projectsInputInfo ); - this.source = CacheSource.BUILD; - } - - public CacheSource getSource() - { - return source; - } - - public Build( org.apache.maven.caching.xml.build.Build dto, CacheSource source ) - { - this.dto = dto; - this.source = source; - } - - public static List createAttachedArtifacts( List artifacts, - HashAlgorithm algorithm ) throws IOException - { - List attachedArtifacts = new ArrayList<>(); - for ( org.apache.maven.artifact.Artifact artifact : artifacts ) - { - final Artifact dto = DtoUtils.createDto( artifact ); - if ( artifact.getFile() != null ) - { - dto.setFileHash( algorithm.hash( artifact.getFile().toPath() ) ); - } - attachedArtifacts.add( dto ); - } - return attachedArtifacts; - } - - public List getMissingExecutions( List mojos ) - { - return mojos.stream() - .filter( mojo -> !hasCompletedExecution( mojoExecutionKey( mojo ) ) ) - .collect( Collectors.toList() ); - } - - private boolean hasCompletedExecution( String mojoExecutionKey ) - { - return getExecutionMap().containsKey( mojoExecutionKey ); - } - - @Override - public String toString() - { - return "Build{" + "dto=" + dto + '}'; - } - - public CompletedExecution findMojoExecutionInfo( MojoExecution mojoExecution ) - { - return getExecutionMap().get( mojoExecutionKey( mojoExecution ) ); - } - - public String getCacheImplementationVersion() - { - return dto.getCacheImplementationVersion(); - } - - public Artifact getArtifact() - { - return dto.getArtifact(); - } - - public List getAttachedArtifacts() - { - if ( dto.getAttachedArtifacts() != null ) - { - return dto.getAttachedArtifacts(); - } - return Collections.emptyList(); - } - - public org.apache.maven.caching.xml.build.Build getDto() - { - return dto; - } - - public String getHighestCompletedGoal() - { - return CacheUtils.getLast( dto.getGoals() ); - } - - public DigestItem findArtifact( Dependency dependency ) - { - if ( CacheUtils.isPom( dependency ) ) - { - throw new IllegalArgumentException( "Pom dependencies should not be treated as artifacts: " + dependency ); - } - List artifacts = new ArrayList<>( getAttachedArtifacts() ); - artifacts.add( getArtifact() ); - for ( Artifact artifact : artifacts ) - { - if ( isEquals( dependency, artifact ) ) - { - return DtoUtils.createdDigestedByProjectChecksum( artifact, dto.getProjectsInputInfo().getChecksum() ); - } - } - return null; - } - - private boolean isEquals( Dependency dependency, Artifact artifact ) - { - return Objects.equals( dependency.getGroupId(), artifact.getGroupId() ) - && Objects.equals( dependency.getArtifactId(), artifact.getArtifactId() ) - && Objects.equals( dependency.getType(), artifact.getType() ) - && Objects.equals( dependency.getClassifier(), artifact.getClassifier() ); - } - - private Map getExecutionMap() - { - if ( execMap != null ) - { - return execMap; - } - List executionsList = dto.getExecutions(); - if ( executionsList == null || executionsList.isEmpty() ) - { - execMap = Collections.emptyMap(); - return execMap; - } - execMap = executionsList.stream() - .collect( Collectors.toMap( CompletedExecution::getExecutionKey, v -> v ) ); - return execMap; - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java deleted file mode 100644 index 373bc8836364..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfig.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.apache.maven.caching.xml; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.caching.PluginScanConfig; -import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.xml.config.Exclude; -import org.apache.maven.caching.xml.config.Include; -import org.apache.maven.caching.xml.config.MultiModule; -import org.apache.maven.caching.xml.config.PropertyName; -import org.apache.maven.caching.xml.config.TrackedProperty; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginExecution; -import org.apache.maven.plugin.MojoExecution; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.List; -import java.util.regex.Pattern; - -/** - * CacheConfig - */ -public interface CacheConfig -{ - - @Nonnull - CacheState initialize(); - - @Nonnull - List getTrackedProperties( MojoExecution mojoExecution ); - - boolean isLogAllProperties( MojoExecution mojoExecution ); - - @Nonnull - List getLoggedProperties( MojoExecution mojoExecution ); - - @Nonnull - List getNologProperties( MojoExecution mojoExecution ); - - @Nonnull - List getEffectivePomExcludeProperties( Plugin plugin ); - - @Nullable - MultiModule getMultiModule(); - - String isProcessPlugins(); - - String getDefaultGlob(); - - @Nonnull - List getGlobalIncludePaths(); - - @Nonnull - List getGlobalExcludePaths(); - - @Nonnull - PluginScanConfig getPluginDirScanConfig( Plugin plugin ); - - @Nonnull - PluginScanConfig getExecutionDirScanConfig( Plugin plugin, PluginExecution exec ); - - @Nonnull - HashFactory getHashFactory(); - - boolean isForcedExecution( MojoExecution execution ); - - String getId(); - - String getUrl(); - - String getTransport(); - - boolean isEnabled(); - - boolean isRemoteCacheEnabled(); - - boolean isSaveToRemote(); - - boolean isSaveFinal(); - - boolean isFailFast(); - - int getMaxLocalBuildsCached(); - - List getAttachedOutputs(); - - boolean adjustMetaInfVersion(); - - boolean canIgnore( MojoExecution mojoExecution ); - - @Nonnull - List getExcludePatterns(); - - boolean isBaselineDiffEnabled(); - - String getBaselineCacheUrl(); - - /** - * Artifacts restore policy. Eager policy (default) resolves all cached artifacts before restoring project and - * allows safe to fallback ro normal execution in case of restore failure. Lazy policy restores artifacts on demand - * minimizing need for downloading any artifacts from cache - *

    - * Use: -Dremote.cache.lazyRestore=(true|false) - */ - boolean isLazyRestore(); - - /** - * Flag to restore (default) or not generated sources as it might be desired to disable it in continuous integration - * scenarios - */ - boolean isRestoreGeneratedSources(); -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java deleted file mode 100644 index 58aaaa52854c..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheConfigImpl.java +++ /dev/null @@ -1,650 +0,0 @@ -package org.apache.maven.caching.xml; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.regex.Pattern; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.inject.Inject; -import javax.inject.Named; - -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.SessionScoped; -import org.apache.maven.caching.DefaultPluginScanConfig; -import org.apache.maven.caching.PluginScanConfig; -import org.apache.maven.caching.PluginScanConfigImpl; -import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.xml.config.AttachedOutputs; -import org.apache.maven.caching.xml.config.CacheConfig; -import org.apache.maven.caching.xml.config.Configuration; -import org.apache.maven.caching.xml.config.CoordinatesBase; -import org.apache.maven.caching.xml.config.Exclude; -import org.apache.maven.caching.xml.config.Executables; -import org.apache.maven.caching.xml.config.ExecutionConfigurationScan; -import org.apache.maven.caching.xml.config.ExecutionControl; -import org.apache.maven.caching.xml.config.ExecutionIdsList; -import org.apache.maven.caching.xml.config.GoalReconciliation; -import org.apache.maven.caching.xml.config.GoalsList; -import org.apache.maven.caching.xml.config.Include; -import org.apache.maven.caching.xml.config.Input; -import org.apache.maven.caching.xml.config.Local; -import org.apache.maven.caching.xml.config.MultiModule; -import org.apache.maven.caching.xml.config.PathSet; -import org.apache.maven.caching.xml.config.PluginConfigurationScan; -import org.apache.maven.caching.xml.config.PluginSet; -import org.apache.maven.caching.xml.config.ProjectVersioning; -import org.apache.maven.caching.xml.config.PropertyName; -import org.apache.maven.caching.xml.config.Remote; -import org.apache.maven.caching.xml.config.TrackedProperty; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginExecution; -import org.apache.maven.plugin.MojoExecution; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static java.lang.Boolean.TRUE; -import static org.apache.maven.caching.CacheUtils.getMultimoduleRoot; - -/** - * CacheConfigImpl - */ -@SessionScoped -@Named -@SuppressWarnings( "unused" ) -public class CacheConfigImpl implements org.apache.maven.caching.xml.CacheConfig -{ - - public static final String CONFIG_PATH_PROPERTY_NAME = "remote.cache.configPath"; - public static final String CACHE_ENABLED_PROPERTY_NAME = "remote.cache.enabled"; - public static final String SAVE_TO_REMOTE_PROPERTY_NAME = "remote.cache.save.enabled"; - public static final String SAVE_NON_OVERRIDEABLE_NAME = "remote.cache.save.final"; - public static final String FAIL_FAST_PROPERTY_NAME = "remote.cache.failFast"; - public static final String BASELINE_BUILD_URL_PROPERTY_NAME = "remote.cache.baselineUrl"; - public static final String LAZY_RESTORE_PROPERTY_NAME = "remote.cache.lazyRestore"; - public static final String RESTORE_GENERATED_SOURCES_PROPERTY_NAME = "remote.cache.restoreGeneratedSources"; - - private static final Logger LOGGER = LoggerFactory.getLogger( CacheConfigImpl.class ); - - private final XmlService xmlService; - private final MavenSession session; - - private CacheState state; - private CacheConfig cacheConfig; - private HashFactory hashFactory; - private List excludePatterns; - - @Inject - public CacheConfigImpl( XmlService xmlService, MavenSession session ) - { - this.xmlService = xmlService; - this.session = session; - } - - @Nonnull - @Override - public CacheState initialize() - { - if ( state == null ) - { - final String enabled = getProperty( CACHE_ENABLED_PROPERTY_NAME, "true" ); - if ( !Boolean.parseBoolean( enabled ) ) - { - LOGGER.info( "Cache disabled by command line flag, project will be built fully and not cached" ); - state = CacheState.DISABLED; - } - else - { - Path configPath; - - String configPathText = getProperty( CONFIG_PATH_PROPERTY_NAME, null ); - if ( StringUtils.isNotBlank( configPathText ) ) - { - configPath = Paths.get( configPathText ); - } - else - { - configPath = getMultimoduleRoot( session ).resolve( ".mvn" ).resolve( "maven-cache-config.xml" ); - } - - if ( !Files.exists( configPath ) ) - { - LOGGER.info( "Cache configuration is not available at configured path {}, " - + "cache is enabled with defaults", configPath ); - cacheConfig = new CacheConfig(); - } - else - { - try - { - LOGGER.info( "Loading cache configuration from {}", configPath ); - cacheConfig = xmlService.loadCacheConfig( configPath.toFile() ); - fillWithDefaults( cacheConfig ); - } - catch ( Exception e ) - { - throw new IllegalArgumentException( - "Cannot initialize cache because xml config is not valid or not available", e ); - } - } - fillWithDefaults( cacheConfig ); - - if ( !cacheConfig.getConfiguration().isEnabled() ) - { - state = CacheState.DISABLED; - } - else - { - String hashAlgorithm = null; - try - { - hashAlgorithm = getConfiguration().getHashAlgorithm(); - hashFactory = HashFactory.of( hashAlgorithm ); - LOGGER.info( "Using {} hash algorithm for cache", hashAlgorithm ); - } - catch ( Exception e ) - { - throw new IllegalArgumentException( "Unsupported hashing algorithm: " + hashAlgorithm, e ); - } - - excludePatterns = compileExcludePatterns(); - state = CacheState.INITIALIZED; - } - } - } - return state; - } - - private void fillWithDefaults( CacheConfig cacheConfig ) - { - if ( cacheConfig.getConfiguration() == null ) - { - cacheConfig.setConfiguration( new Configuration() ); - } - Configuration configuration = cacheConfig.getConfiguration(); - if ( configuration.getLocal() == null ) - { - configuration.setLocal( new Local() ); - } - if ( configuration.getRemote() == null ) - { - configuration.setRemote( new Remote() ); - } - if ( cacheConfig.getInput() == null ) - { - cacheConfig.setInput( new Input() ); - } - Input input = cacheConfig.getInput(); - if ( input.getGlobal() == null ) - { - input.setGlobal( new PathSet() ); - } - } - - @Nonnull - @Override - public List getTrackedProperties( MojoExecution mojoExecution ) - { - checkInitializedState(); - final GoalReconciliation reconciliationConfig = findReconciliationConfig( mojoExecution ); - if ( reconciliationConfig != null ) - { - return reconciliationConfig.getReconciles(); - } - else - { - return Collections.emptyList(); - } - } - - @Override - public boolean isLogAllProperties( MojoExecution mojoExecution ) - { - final GoalReconciliation reconciliationConfig = findReconciliationConfig( mojoExecution ); - if ( reconciliationConfig != null && reconciliationConfig.isLogAll() ) - { - return true; - } - return cacheConfig.getExecutionControl() != null && cacheConfig.getExecutionControl().getReconcile() != null - && cacheConfig.getExecutionControl().getReconcile().isLogAllProperties(); - } - - private GoalReconciliation findReconciliationConfig( MojoExecution mojoExecution ) - { - if ( cacheConfig.getExecutionControl() == null ) - { - return null; - } - - final ExecutionControl executionControl = cacheConfig.getExecutionControl(); - if ( executionControl.getReconcile() == null ) - { - return null; - } - - final List reconciliation = executionControl.getReconcile().getPlugins(); - - for ( GoalReconciliation goalReconciliationConfig : reconciliation ) - { - final String goal = mojoExecution.getGoal(); - - if ( isPluginMatch( mojoExecution.getPlugin(), goalReconciliationConfig ) && StringUtils.equals( goal, - goalReconciliationConfig.getGoal() ) ) - { - return goalReconciliationConfig; - } - } - return null; - } - - @Nonnull - @Override - public List getLoggedProperties( MojoExecution mojoExecution ) - { - checkInitializedState(); - - final GoalReconciliation reconciliationConfig = findReconciliationConfig( mojoExecution ); - if ( reconciliationConfig != null ) - { - return reconciliationConfig.getLogs(); - } - else - { - return Collections.emptyList(); - } - } - - @Nonnull - @Override - public List getNologProperties( MojoExecution mojoExecution ) - { - checkInitializedState(); - final GoalReconciliation reconciliationConfig = findReconciliationConfig( mojoExecution ); - if ( reconciliationConfig != null ) - { - return reconciliationConfig.getNologs(); - } - else - { - return Collections.emptyList(); - } - } - - @Nonnull - @Override - public List getEffectivePomExcludeProperties( Plugin plugin ) - { - checkInitializedState(); - final PluginConfigurationScan pluginConfig = findPluginScanConfig( plugin ); - - if ( pluginConfig != null && pluginConfig.getEffectivePom() != null ) - { - return pluginConfig.getEffectivePom().getExcludeProperties(); - } - return Collections.emptyList(); - } - - @Nullable - @Override - public MultiModule getMultiModule() - { - checkInitializedState(); - return cacheConfig.getConfiguration().getMultiModule(); - } - - private PluginConfigurationScan findPluginScanConfig( Plugin plugin ) - { - if ( cacheConfig.getInput() == null ) - { - return null; - } - - final List pluginConfigs = cacheConfig.getInput().getPlugins(); - for ( PluginConfigurationScan pluginConfig : pluginConfigs ) - { - if ( isPluginMatch( plugin, pluginConfig ) ) - { - return pluginConfig; - } - } - return null; - } - - private boolean isPluginMatch( Plugin plugin, CoordinatesBase pluginConfig ) - { - return StringUtils.equals( pluginConfig.getArtifactId(), - plugin.getArtifactId() ) && ( pluginConfig.getGroupId() == null || StringUtils.equals( - pluginConfig.getGroupId(), plugin.getGroupId() ) ); - } - - - @Nonnull - @Override - public PluginScanConfig getPluginDirScanConfig( Plugin plugin ) - { - checkInitializedState(); - final PluginConfigurationScan pluginConfig = findPluginScanConfig( plugin ); - if ( pluginConfig == null || pluginConfig.getDirScan() == null ) - { - return new DefaultPluginScanConfig(); - } - - return new PluginScanConfigImpl( pluginConfig.getDirScan() ); - } - - @Nonnull - @Override - public PluginScanConfig getExecutionDirScanConfig( Plugin plugin, PluginExecution exec ) - { - checkInitializedState(); - final PluginConfigurationScan pluginScanConfig = findPluginScanConfig( plugin ); - - if ( pluginScanConfig != null ) - { - final ExecutionConfigurationScan executionScanConfig = findExecutionScanConfig( exec, - pluginScanConfig.getExecutions() ); - if ( executionScanConfig != null && executionScanConfig.getDirScan() != null ) - { - return new PluginScanConfigImpl( executionScanConfig.getDirScan() ); - } - } - - return new DefaultPluginScanConfig(); - } - - private ExecutionConfigurationScan findExecutionScanConfig( PluginExecution execution, - List scanConfigs ) - { - for ( ExecutionConfigurationScan executionScanConfig : scanConfigs ) - { - if ( executionScanConfig.getExecIds().contains( execution.getId() ) ) - { - return executionScanConfig; - } - } - return null; - } - - @Override - public String isProcessPlugins() - { - checkInitializedState(); - return TRUE.toString(); - } - - @Override - public String getDefaultGlob() - { - checkInitializedState(); - return StringUtils.trim( cacheConfig.getInput().getGlobal().getGlob() ); - } - - @Nonnull - @Override - public List getGlobalIncludePaths() - { - checkInitializedState(); - return cacheConfig.getInput().getGlobal().getIncludes(); - } - - @Nonnull - @Override - public List getGlobalExcludePaths() - { - checkInitializedState(); - return cacheConfig.getInput().getGlobal().getExcludes(); - } - - @Nonnull - @Override - public HashFactory getHashFactory() - { - checkInitializedState(); - return hashFactory; - } - - @Override - public boolean canIgnore( MojoExecution mojoExecution ) - { - checkInitializedState(); - if ( cacheConfig.getExecutionControl() == null || cacheConfig.getExecutionControl().getIgnoreMissing() == null ) - { - return false; - } - - return executionMatches( mojoExecution, cacheConfig.getExecutionControl().getIgnoreMissing() ); - } - - @Override - public boolean isForcedExecution( MojoExecution execution ) - { - checkInitializedState(); - if ( cacheConfig.getExecutionControl() == null || cacheConfig.getExecutionControl().getRunAlways() == null ) - { - return false; - } - - return executionMatches( execution, cacheConfig.getExecutionControl().getRunAlways() ); - } - - private boolean executionMatches( MojoExecution execution, Executables executablesType ) - { - final List pluginConfigs = executablesType.getPlugins(); - for ( PluginSet pluginConfig : pluginConfigs ) - { - if ( isPluginMatch( execution.getPlugin(), pluginConfig ) ) - { - return true; - } - } - - final List executionIds = executablesType.getExecutions(); - for ( ExecutionIdsList executionConfig : executionIds ) - { - if ( isPluginMatch( execution.getPlugin(), executionConfig ) && executionConfig.getExecIds().contains( - execution.getExecutionId() ) ) - { - return true; - } - } - - final List pluginsGoalsList = executablesType.getGoalsLists(); - for ( GoalsList pluginGoals : pluginsGoalsList ) - { - if ( isPluginMatch( execution.getPlugin(), pluginGoals ) && pluginGoals.getGoals().contains( - execution.getGoal() ) ) - { - return true; - } - } - - return false; - } - - @Override - public boolean isEnabled() - { - return state == CacheState.INITIALIZED; - } - - - @Override - public boolean isRemoteCacheEnabled() - { - checkInitializedState(); - return getRemote().getUrl() != null && getRemote().isEnabled(); - } - - @Override - public boolean isSaveToRemote() - { - checkInitializedState(); - return Boolean.getBoolean( SAVE_TO_REMOTE_PROPERTY_NAME ) || getRemote().isSaveToRemote(); - } - - @Override - public boolean isSaveFinal() - { - return Boolean.getBoolean( SAVE_NON_OVERRIDEABLE_NAME ); - } - - @Override - public boolean isFailFast() - { - return Boolean.getBoolean( FAIL_FAST_PROPERTY_NAME ); - } - - @Override - public boolean isBaselineDiffEnabled() - { - return getProperty( BASELINE_BUILD_URL_PROPERTY_NAME, null ) != null; - } - - @Override - public String getBaselineCacheUrl() - { - return getProperty( BASELINE_BUILD_URL_PROPERTY_NAME, null ); - } - - @Override - public boolean isLazyRestore() - { - final String lazyRestore = getProperty( LAZY_RESTORE_PROPERTY_NAME, "false" ); - return Boolean.parseBoolean( lazyRestore ); - } - - @Override - public boolean isRestoreGeneratedSources() - { - final String restoreGeneratedSources = getProperty( RESTORE_GENERATED_SOURCES_PROPERTY_NAME, "true" ); - return Boolean.parseBoolean( restoreGeneratedSources ); - } - - @Override - public String getId() - { - checkInitializedState(); - return getRemote().getId(); - } - - @Override - public String getUrl() - { - checkInitializedState(); - return getRemote().getUrl(); - } - - @Override - public String getTransport() - { - checkInitializedState(); - return getRemote().getTransport(); - } - - @Override - public int getMaxLocalBuildsCached() - { - checkInitializedState(); - return getLocal().getMaxBuildsCached(); - } - - @Override - public List getAttachedOutputs() - { - checkInitializedState(); - final AttachedOutputs attachedOutputs = getConfiguration().getAttachedOutputs(); - return attachedOutputs == null ? Collections.emptyList() : attachedOutputs.getDirNames(); - } - - @Override - public boolean adjustMetaInfVersion() - { - return Optional.ofNullable( getConfiguration().getProjectVersioning() ) - .map( ProjectVersioning::isAdjustMetaInf ) - .orElse( false ); - } - - @Nonnull - @Override - public List getExcludePatterns() - { - checkInitializedState(); - return excludePatterns; - } - - private List compileExcludePatterns() - { - if ( cacheConfig.getOutput() != null && cacheConfig.getOutput().getExclude() != null ) - { - List patterns = new ArrayList<>(); - for ( String pattern : cacheConfig.getOutput().getExclude().getPatterns() ) - { - patterns.add( Pattern.compile( pattern ) ); - } - return patterns; - } - return Collections.emptyList(); - } - - private Remote getRemote() - { - return getConfiguration().getRemote(); - } - - private Local getLocal() - { - return getConfiguration().getLocal(); - } - - private Configuration getConfiguration() - { - return cacheConfig.getConfiguration(); - } - - private void checkInitializedState() - { - if ( state != CacheState.INITIALIZED ) - { - throw new IllegalStateException( "Cache is not initialized. Actual state: " + state ); - } - } - - private String getProperty( String key, String defaultValue ) - { - String value = session.getUserProperties().getProperty( key ); - if ( value == null ) - { - value = session.getSystemProperties().getProperty( key ); - if ( value == null ) - { - value = defaultValue; - } - } - return value; - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheSource.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheSource.java deleted file mode 100644 index b21944463632..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheSource.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apache.maven.caching.xml; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * CacheSource - */ -public enum CacheSource -{ - LOCAL, - REMOTE, - BUILD -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheState.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheState.java deleted file mode 100644 index 99267ed01e89..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/CacheState.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apache.maven.caching.xml; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * CacheState - */ -public enum CacheState -{ - NOT_INITIALIZED, - DISABLED, - INITIALIZED -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java deleted file mode 100644 index 88f5b1179cf0..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/DtoUtils.java +++ /dev/null @@ -1,186 +0,0 @@ -package org.apache.maven.caching.xml; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.caching.CacheUtils; -import org.apache.maven.caching.xml.build.Artifact; -import org.apache.maven.caching.xml.build.CompletedExecution; -import org.apache.maven.caching.xml.build.DigestItem; -import org.apache.maven.caching.xml.build.PropertyValue; -import org.apache.maven.caching.xml.config.TrackedProperty; -import org.apache.maven.model.Dependency; - -import javax.annotation.Nonnull; - -import java.util.List; - -import static org.apache.maven.caching.checksum.KeyUtils.getArtifactKey; - -/** - * DtoUtils - */ -public class DtoUtils -{ - - public static String findPropertyValue( String propertyName, CompletedExecution completedExecution ) - { - final List properties = completedExecution.getProperties(); - if ( properties == null ) - { - return null; - } - for ( PropertyValue property : properties ) - { - if ( StringUtils.equals( propertyName, property.getName() ) ) - { - return property.getValue(); - } - } - return null; - } - - public static Artifact createDto( org.apache.maven.artifact.Artifact artifact ) - { - Artifact dto = new Artifact(); - dto.setArtifactId( artifact.getArtifactId() ); - dto.setGroupId( artifact.getGroupId() ); - dto.setVersion( artifact.getVersion() ); - dto.setClassifier( artifact.getClassifier() ); - dto.setType( artifact.getType() ); - dto.setScope( artifact.getScope() ); - dto.setFileName( CacheUtils.normalizedName( artifact ) ); - return dto; - } - - public static DigestItem createdDigestedByProjectChecksum( Artifact artifact, String projectChecksum ) - { - DigestItem dit = new DigestItem(); - dit.setType( "module" ); - dit.setHash( projectChecksum ); - dit.setFileChecksum( artifact.getFileHash() ); - dit.setValue( getArtifactKey( artifact ) ); - return dit; - } - - public static DigestItem createDigestedFile( org.apache.maven.artifact.Artifact artifact, String fileHash ) - { - DigestItem dit = new DigestItem(); - dit.setType( "artifact" ); - dit.setHash( fileHash ); - dit.setFileChecksum( fileHash ); - dit.setValue( getArtifactKey( artifact ) ); - return dit; - } - - public static Dependency createDependency( org.apache.maven.artifact.Artifact artifact ) - { - final Dependency dependency = new Dependency(); - dependency.setArtifactId( artifact.getArtifactId() ); - dependency.setGroupId( artifact.getGroupId() ); - dependency.setVersion( artifact.getVersion() ); - dependency.setClassifier( artifact.getClassifier() ); - dependency.setType( artifact.getType() ); - dependency.setScope( artifact.getScope() ); - return dependency; - } - - public static Dependency createDependency( Artifact artifact ) - { - final Dependency dependency = new Dependency(); - dependency.setArtifactId( artifact.getArtifactId() ); - dependency.setGroupId( artifact.getGroupId() ); - dependency.setVersion( artifact.getVersion() ); - dependency.setType( artifact.getType() ); - dependency.setScope( artifact.getScope() ); - dependency.setClassifier( artifact.getClassifier() ); - return dependency; - } - - public static void addProperty( CompletedExecution execution, - String propertyName, - Object value, - String baseDirPath, - boolean tracked ) - { - final PropertyValue valueType = new PropertyValue(); - valueType.setName( propertyName ); - if ( value != null && value.getClass().isArray() ) - { - value = ArrayUtils.toString( value ); - } - final String valueText = String.valueOf( value ); - valueType.setValue( StringUtils.remove( valueText, baseDirPath ) ); - valueType.setTracked( tracked ); - execution.addProperty( valueType ); - } - - public static boolean containsAllProperties( - @Nonnull CompletedExecution cachedExecution, List trackedProperties ) - { - if ( trackedProperties == null || trackedProperties.isEmpty() ) - { - return true; - } - - if ( cachedExecution.getProperties() == null ) - { - return false; - } - - final List executionProperties = cachedExecution.getProperties(); - for ( TrackedProperty trackedProperty : trackedProperties ) - { - if ( !contains( executionProperties, trackedProperty.getPropertyName() ) ) - { - return false; - } - } - return true; - } - - public static boolean contains( List executionProperties, String propertyName ) - { - for ( PropertyValue executionProperty : executionProperties ) - { - if ( StringUtils.equals( executionProperty.getName(), propertyName ) ) - { - return true; - } - } - return false; - } - - public static Artifact copy( Artifact artifact ) - { - Artifact copy = new Artifact(); - copy.setArtifactId( artifact.getArtifactId() ); - copy.setGroupId( artifact.getGroupId() ); - copy.setVersion( artifact.getVersion() ); - copy.setType( artifact.getType() ); - copy.setClassifier( artifact.getClassifier() ); - copy.setScope( artifact.getScope() ); - copy.setFileName( artifact.getFileName() ); - copy.setFileHash( artifact.getFileHash() ); - copy.setFileSize( artifact.getFileSize() ); - return copy; - } -} diff --git a/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java b/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java deleted file mode 100644 index cde63c1a49ec..000000000000 --- a/maven-caching/src/main/java/org/apache/maven/caching/xml/XmlService.java +++ /dev/null @@ -1,190 +0,0 @@ -package org.apache.maven.caching.xml; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; - -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.caching.xml.build.Build; -import org.apache.maven.caching.xml.build.io.xpp3.CacheBuildXpp3Reader; -import org.apache.maven.caching.xml.build.io.xpp3.CacheBuildXpp3Writer; -import org.apache.maven.caching.xml.diff.Diff; -import org.apache.maven.caching.xml.diff.io.xpp3.CacheDiffXpp3Reader; -import org.apache.maven.caching.xml.diff.io.xpp3.CacheDiffXpp3Writer; -import org.apache.maven.caching.xml.config.CacheConfig; -import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Reader; -import org.apache.maven.caching.xml.config.io.xpp3.CacheConfigXpp3Writer; -import org.apache.maven.caching.xml.report.CacheReport; -import org.apache.maven.caching.xml.report.io.xpp3.CacheReportXpp3Reader; -import org.apache.maven.caching.xml.report.io.xpp3.CacheReportXpp3Writer; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -/** - * XmlService - */ -@Singleton -@Named -public class XmlService -{ - - public byte[] toBytes( CacheConfig cache ) throws IOException - { - try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) - { - new CacheConfigXpp3Writer().write( baos, cache ); - return baos.toByteArray(); - } - } - - public byte[] toBytes( Build build ) throws IOException - { - try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) - { - new CacheBuildXpp3Writer().write( baos, build ); - return baos.toByteArray(); - } - } - - public byte[] toBytes( Diff diff ) throws IOException - { - try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) - { - new CacheDiffXpp3Writer().write( baos, diff ); - return baos.toByteArray(); - } - } - - public byte[] toBytes( CacheReport cacheReportType ) throws IOException - { - try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) - { - new CacheReportXpp3Writer().write( baos, cacheReportType ); - return baos.toByteArray(); - } - } - - public Build loadBuild( File file ) throws IOException - { - return fromFile( Build.class, file ); - } - - public Build loadBuild( byte[] bytes ) - { - return fromBytes( Build.class, bytes ); - } - - public Build loadBuild( InputStream inputStream ) - { - return fromInputStream( Build.class, inputStream ); - } - - public CacheConfig loadCacheConfig( File file ) throws IOException - { - return fromFile( CacheConfig.class, file ); - } - - public CacheConfig loadCacheConfig( byte[] bytes ) - { - return fromBytes( CacheConfig.class, bytes ); - } - - public CacheConfig loadCacheConfig( InputStream inputStream ) - { - return fromInputStream( CacheConfig.class, inputStream ); - } - - public CacheReport loadCacheReport( File file ) throws IOException - { - return fromFile( CacheReport.class, file ); - } - - public CacheReport loadCacheReport( byte[] bytes ) - { - return fromBytes( CacheReport.class, bytes ); - } - - public CacheReport loadCacheReport( InputStream inputStream ) - { - return fromInputStream( CacheReport.class, inputStream ); - } - - public Diff loadDiff( File file ) throws IOException - { - return fromFile( Diff.class, file ); - } - - public Diff loadDiff( byte[] bytes ) - { - return fromBytes( Diff.class, bytes ); - } - - public Diff loadDiff( InputStream inputStream ) - { - return fromInputStream( Diff.class, inputStream ); - } - - private T fromFile( Class clazz, File file ) throws IOException - { - return fromInputStream( clazz, Files.newInputStream( file.toPath() ) ); - } - - private T fromBytes( Class clazz, byte[] bytes ) - { - return fromInputStream( clazz, new ByteArrayInputStream( bytes ) ); - } - - private T fromInputStream( Class clazz, InputStream inputStream ) - { - try - { - if ( clazz == Build.class ) - { - return clazz.cast( new CacheBuildXpp3Reader().read( inputStream ) ); - } - else if ( clazz == CacheConfig.class ) - { - return clazz.cast( new CacheConfigXpp3Reader().read( inputStream ) ); - } - else if ( clazz == Diff.class ) - { - return clazz.cast( new CacheDiffXpp3Reader().read( inputStream ) ); - } - else if ( clazz == CacheReport.class ) - { - return clazz.cast( new CacheReportXpp3Reader().read( inputStream ) ); - } - else - { - throw new IllegalArgumentException( "Unsupported type " + clazz ); - } - } - catch ( IOException | XmlPullParserException e ) - { - throw new RuntimeException( "Unable to parse cache xml element", e ); - } - } -} diff --git a/maven-caching/src/main/mdo/cache-build.mdo b/maven-caching/src/main/mdo/cache-build.mdo deleted file mode 100644 index 01c28a64df41..000000000000 --- a/maven-caching/src/main/mdo/cache-build.mdo +++ /dev/null @@ -1,386 +0,0 @@ - - - - cache-build - CacheBuild - lookupinfo.xml or remote buildinfo.xml - ]]> - - - package - org.apache.maven.caching.xml.build - - - - - - Build - 1.0.0+ - - - - - - cacheImplementationVersion - 1.0.0+ - String - - - - _final - 1.0.0+ - Boolean - final - - - - hashFunction - 1.0.0+ - String - - - - buildTime - 1.0.0+ - Date - - - - buildServer - 1.0.0+ - String - - - - scm - 1.0.0+ - - Scm - - - - - goals - 1.0.0+ - - String - * - - - - - - artifact - 1.0.0+ - - Artifact - - - - - - attachedArtifacts - - Artifact - * - - - - - - executions - - CompletedExecution - * - - - - - projectsInputInfo - - ProjectsInputInfo - - - - - - - - Scm - - - sourceBranch - String - - - revision - String - - - - - - - Artifact - - - - - groupId - String - - - - artifactId - String - - - - version - String - - - - classifier - String - - - - type - String - - - - scope - String - - - - fileName - String - - - - fileHash - String - - - - - fileSize - long - - - - - - - - - CompletedExecution - - - executionKey - String - - - mojoClassName - String - - - properties - - PropertyValue - * - - - - - - - - - PropertyValue - - - value - String - - - name - String - - - tracked - Boolean - - - - - - - - ProjectsInputInfo - - - checksum - String - - - items - - DigestItem - * - - - - - - - - - DigestItem - - - value - String - - - type - String - - - hash - String - - - fileChecksum - String - - - content - String - - - isText - String - - - charset - String - - - eol - String - - - - - - diff --git a/maven-caching/src/main/mdo/cache-config.mdo b/maven-caching/src/main/mdo/cache-config.mdo deleted file mode 100644 index c92c50ad694d..000000000000 --- a/maven-caching/src/main/mdo/cache-config.mdo +++ /dev/null @@ -1,1381 +0,0 @@ - - - - cache-config - CacheConfig - .mvn/maven-cache-config.xml - ]]> - - - - package - org.apache.maven.caching.xml.config - - - - - - - CacheConfig - - - configuration - - Configuration - - Configuration of main cache properties - - - input - - Input - - Configuration for source code input files participating in checksum calculation - - - output - - Output - - Configuration for output artifacts, it's needed if you want to explicitly include/exclude something from caching - - - executionControl - - ExecutionControl - - Execution rules for plugins in cached mode. Defines which plugins should run always - - - Cache build metadata - - - - Remote - - - url - String - Address of remote cache - - - enabled - boolean - true - - - saveToRemote - boolean - false - Save output to remote cache. Recommended to enable on CI agents only. - - - transport - String - http - The transport to use, either 'http' or 'wagon'. - - - id - String - cache - The repository id used to find authentication / mirror information in maven settings, default to 'cache'. - - - - - - - Configuration - - - enabled - boolean - true - - - hashAlgorithm - String - XX - One of XX, XXMM, SHA-1, SHA-256, SHA-384, SHA-512 - - - validateXml - boolean - false - Validate cache config and builds metadata against xsd. - TODO: not implemented - - - - multiModule - - MultiModule - - Specifies related to multi module projects configuration. - - - projectVersioning - - ProjectVersioning - - Specifies parameters to handle project version changes. - - - remote - - Remote - - - - attachedOutputs - - AttachedOutputs - - - - local - - Local - - - - debugs - - String - * - - FileHash (causes file hash is saved in build metadata) or - EffectivePom (causes effective pom info is saved in build metadata) - - - - - - - - MultiModule - - - discovery - - Discovery - - Section to specify how to discover multi module projects. - - - - - - - - Discovery - - - scanProfiles - - String - * - - Profiles to discover multi module project - - - - - - - - ProjectVersioning - - - adjustMetaInf - boolean - Determines whether version in metadata must be changed according to building project version. - - - - - - - - - AttachedOutputs - - - dirNames - - String - * - - Directory name in build output directory to attach to cached artifacts - - - - - - - Local - - - maxBuildsCached - int - 3 - Maximum number of cached build per artifact in local cache. First created cache (the - oldest) is evicted if breached. - - - - - - - Input - - - global - - PathSet - - Global input calculation rules applicable to all projects and plugins in the build - - - plugins - - PluginConfigurationScan - * - - Plugin specific input calculation rules - - - - - - - PluginConfigurationScan - CoordinatesBase - - - effectivePom - - EffectivePom - - Effective pom calculation rules - - - dirScan - - DirScanConfig - - Specifies plugin level rules of configuration processing in search of referenced source files - - - executions - - ExecutionConfigurationScan - * - - Specifies execution specific configuration processing in search of referenced source files - - - - - - - EffectivePom - - - excludeProperties - - String - * - - Plugin configuration property should be excluded from effective pom calculation - - - - - - - ExecutionConfigurationScan - - - execIds - - String - * - - - - dirScan - - DirScanConfig - - Specifies rules of configuration processing in search of referenced source files - - - ignoreParentConfig - boolean - ignore parent config or inherit/merge - - - - - - - TagScanConfig - TagExclude - - - recursive - boolean - true - - - glob - String - * - - - - - - - DirScanConfig - - - includes - - TagScanConfig - * - - Forces cache to treat property value as input and include in calculation. If set, only included - properties will be takein in calculation (whitelist) - - - excludes - - TagExclude - * - - Tag to exclude when scanning plugin configuration for input files (blacklist) - - - tagScanConfigs - - TagScanConfig - * - - Additional processing rules for non-blacklisted tags - - - ignoreParent - boolean - false - Ignore parent settings or inherit and merge - - - mode - String - - Either 'auto' (scan directory accordingly to cache implementation) or 'skip' (skip directory). - - - - - - - - Output - - - exclude - - OutputExclude - - Patterns to exclude output artifacts applicable to all projects in the build - - - - - - OutputExclude - - - patterns - - String - * - - - - - - - - PathSet - - - glob - String - * - - - includes - - Include - * - - - - excludes - - Exclude - * - - - - - - Exclude - - - value - String - - - - - Include - - - value - String - - - recursive - boolean - true - - - glob - String - - - - - - - - - - GoalReconciliation - GoalId - - - reconciles - - TrackedProperty - * - - - - logs - - PropertyName - * - - Specify property which should be logged to build metadata for exploration - - - nologs - - PropertyName - * - - Specify property which should not be logged - - - logAll - boolean - true - - - - - - - - - - ExecutionControl - - - runAlways - - Executables - - Specify which plugin should run always if present in build regardless of cached status - - - ignoreMissing - - Executables - - - Specify which executions/plugins/goals do not affect generated artifacts and do not affect build correctness. - If cached build lacks of ignorable executions only, it still could be reused. - Typically case is then cached build is produced with 'verify' and you locally you run 'install'. - Strictly speaking these are different builds but in most of cases you want this difference to be ignored - - - - reconcile - - Reconcile - - Specify which plugin should run always if present in build regardless of cached status - - - - - - - - Reconcile - - - plugins - - GoalReconciliation - * - - Reconciliation rules for plugin properties which might be affected by command line flags, etc - - - logAllProperties - boolean - true - - - - - - - - - - Executables - - - plugins - - PluginSet - * - - Specify which executions should run always if present in build regardless of cached status - - - executions - - ExecutionIdsList - * - - Specify which executions should run always if present in build regardless of cached status - - - goalsLists - - GoalsList - * - - Specify which goals should run always if present in build regardless of cached status - - - - - - - - GoalsList - CoordinatesBase - - - goals - - String - * - - Goals identification - - - - - - - - GoalId - CoordinatesBase - - - goal - String - true - - - - - - - - ExecutionIdsList - CoordinatesBase - - - execIds - - String - * - - Executions ids list with plugin identifier - - - - - - - - PluginSet - CoordinatesBase - - - - - - CoordinatesBase - - - groupId - String - - - artifactId - String - - - - - - - - TagExclude - - - tagName - String - true - - - - - - - - PropertyName - - - value - String - - - propertyName - String - - - - - - - - TrackedProperty - - - value - String - - - propertyName - String - - - skipValue - String - - - defaultValue - String - - - - - - - - diff --git a/maven-caching/src/main/mdo/cache-diff.mdo b/maven-caching/src/main/mdo/cache-diff.mdo deleted file mode 100644 index 9d837362b663..000000000000 --- a/maven-caching/src/main/mdo/cache-diff.mdo +++ /dev/null @@ -1,110 +0,0 @@ - - - - cache-diff - CacheDiff - diff-${checksum}.xml - ]]> - - - package - org.apache.maven.caching.xml.diff - - - - - - - - Diff - - - mismatches - - Mismatch - * - - - - - - - - - Mismatch - - - detail - - MismatchDetail - * - - - - item - String - - - current - String - - - baseline - String - - - reason - String - - - resolution - String - - - context - String - - - - - - - MismatchDetail - - - - diff --git a/maven-caching/src/main/mdo/cache-report.mdo b/maven-caching/src/main/mdo/cache-report.mdo deleted file mode 100644 index d77ba5655cdd..000000000000 --- a/maven-caching/src/main/mdo/cache-report.mdo +++ /dev/null @@ -1,109 +0,0 @@ - - - - cache-report - CacheReport - cache-report.xml - ]]> - - - package - org.apache.maven.caching.xml.report - - - - - - CacheReport - - - projects - - ProjectReport - * - - - - - - - - - - - - - - ProjectReport - - - groupId - String - - - artifactId - String - - - checksum - String - - - checksumMatched - Boolean - - - lifecycleMatched - Boolean - - - pluginsMatched - Boolean - - - source - String - - - sharedToRemote - Boolean - - - url - String - - - - - - diff --git a/maven-caching/src/site/apt/index.apt b/maven-caching/src/site/apt/index.apt deleted file mode 100644 index db29a8d8eeae..000000000000 --- a/maven-caching/src/site/apt/index.apt +++ /dev/null @@ -1,30 +0,0 @@ -~~ Licensed to the Apache Software Foundation (ASF) under one -~~ or more contributor license agreements. See the NOTICE file -~~ distributed with this work for additional information -~~ regarding copyright ownership. The ASF licenses this file -~~ to you under the Apache License, Version 2.0 (the -~~ "License"); you may not use this file except in compliance -~~ with the License. You may obtain a copy of the License at -~~ -~~ http://www.apache.org/licenses/LICENSE-2.0 -~~ -~~ Unless required by applicable law or agreed to in writing, -~~ software distributed under the License is distributed on an -~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -~~ KIND, either express or implied. See the License for the -~~ specific language governing permissions and limitations -~~ under the License. - - ----- - Introduction - ----- - Hervé Boutemy - ----- - 2021-11-11 - ----- - -Maven Caching - - Maven Incremental Build and Cache (local and remote). - - Read {{{./CACHE.html} more documentation}}. diff --git a/maven-caching/src/site/markdown/CACHE-HOWTO.md b/maven-caching/src/site/markdown/CACHE-HOWTO.md deleted file mode 100644 index c0877acfba08..000000000000 --- a/maven-caching/src/site/markdown/CACHE-HOWTO.md +++ /dev/null @@ -1,220 +0,0 @@ - - -### Overview - -Cache configuration provides you additional control over incremental Maven behavior. Follow it step by step to -understand how it works and figure out your optimal config - -### Minimal config - -Absolutely minimal config which enables incremental Maven with local cache - -```xml - - - - - true - XX - - - - - {*.java,*.xml,*.properties} - - - -``` - -### Enabling remote cache - -Just add `` section under `` - -```xml - - true - XX - - https://yourserver:port - - -``` - -### Adding more file types to input - -Add all the project specific source code files in ``. Scala in this case: - -```xml - - - {*.java,*.xml,*.properties,*.scala} - - -``` - -### Adding source directory for bespoke project layouts - -In most of the cases incremental Maven will recognize directories automatically by build introspection. If not, you can -add additional directories with ``. Also you can filter out undesirable dirs and files by using exclude tag - -```xml - - - {*.java,*.xml,*.properties,*.scala} - - importantdir/ - - - tempfile.out - - - -``` - -### Plugin property is env specific (breaks checksum and caching) - -Consider to exclude env specific properties: - -```xml - - - ... - - - - - - argLine - - - - - -``` - -Implications - builds with different `argLine` will have identical checksum. Validate that is semantically valid. - -### Plugin property points to directory where only subset of files is relevant - -If plugin configuration property points to `somedir` it will be scanned with default glob. You can tweak it with custom -processing rule - -```xml - - - ... - - - - - - - - - - - - -``` - -### Local repository is not updated because `install` is cached - -Add `executionControl/runAlways` section - -```xml - - - - - - - - - unpack-autoupdate - - - - - - - install - - - - - -``` - -### I occasionally cached build with `-DskipTests=true` and tests do not run now - -If you add command line flags to your build, they do not participate in effective pom - Maven defers final value -resolution to plugin runtime. To invalidate build if filed value is different in runtime, add reconciliation section -to `executionControl`: - -```xml - - - - ... - - - - ... - - - - - - - - - - - - - - - -``` - -Please notice `skipValue` attribute. It denotes value which forces skipped execution. -Read `propertyName="skipTests" skipValue="true"` as if property skipTests has value true, plugin will skip execution If -you declare such value incremental Maven will reuse appropriate full-build though technically they are different, but -because full-build is better it is safe to reuse - -### How to renormalize line endings in working copy after committing .gitattributes (git 2.16+) - -Ensure you've committed (and ideally pushed everything) - no changes in working copy. After that: - -```shell -# Rewrite objects and update index -git add --renormalize . -# Commit changes -git commit -m "Normalizing line endings" -# Remove working copy paths from git cache -git rm --cached -r . -# Refresh with new line endings -git reset --hard -``` - -### I want to cache interim build and override it later with final version - -Solution: set `-Dremote.cache.save.final=true` to nodes which produce final builds. Such builds will not be overridden -and eventually will replace all interim builds diff --git a/maven-caching/src/site/markdown/CACHE-PARAMETERS.md b/maven-caching/src/site/markdown/CACHE-PARAMETERS.md deleted file mode 100644 index 12042c634076..000000000000 --- a/maven-caching/src/site/markdown/CACHE-PARAMETERS.md +++ /dev/null @@ -1,52 +0,0 @@ - - -# Overview - -This documents contains various configuration parameters supported by cache engine - -## Command line flags - -| Parameter | Description | Usage Scenario | -| ----------- | ----------- | ----------- | -| `-Dremote.cache.configPath=true/false` | Location of cache configuration file | Cache config is not in default location | -| `-Dremote.cache.enabled=true/false` | Remote cache and associated features disabled/enabled | To remove noise from logs then remote cache is not available | -| `-Dremote.cache.save.enabled=true/false` | Remote cache save allowed or not | To designate nodes which allowed to push in remote shared cache | -| `-Dremote.cache.save.final=true/false` | Is it allowed or not to override produced cache | To ensure that reference build is not overridden by interim build | -| `-Dremote.cache.failFast=true/false` | Fail on the first module which cannot be restored from cache | Remote cache setup/tuning/troubleshooting | -| `-Dremote.cache.baselineUrl=` | Location of baseline build for comparison | Remote cache setup/tuning/troubleshooting | - -## Project level properties - -Project level parameters allow overriding global parameters on project level Must be specified as project properties: - -```xml - - - ... - - {*.css} - - -``` - -| Parameter | Description | -| ----------------------------- | ----------- | -| `remote.cache.input.glob` | Project specific glob to select sources. Overrides global glob. | -| `remote.cache.input` | Property prefix to mark paths which must be additionally scanned for source code. Value of property starting with this prefix will be treated as path relatively to current project/module | -| `remote.cache.exclude` | Property prefix to mark paths which must be excluded from source code search. Value of property starting with this prefix will be treated as path to current project/module | -| `remote.cache.processPlugins` | Introspect plugins to find inputs or not. Default is true. | diff --git a/maven-caching/src/site/markdown/CACHE-REMOTE.md b/maven-caching/src/site/markdown/CACHE-REMOTE.md deleted file mode 100644 index c89e5de19818..000000000000 --- a/maven-caching/src/site/markdown/CACHE-REMOTE.md +++ /dev/null @@ -1,249 +0,0 @@ - - -# Overview - -This document describes generic approach to cache setup. The process require expertise in Maven equivalent to expertise -required to author and Maven your project build, it implies good knowledge of both Maven and the project. Due to Maven -model limitation the process is manual, but allows you to achieve sufficient control and transparency over caching -logic. - -# Step-By-Step - -## Fork branch for cache setup purposes - -It is recommended to fork branch for cache setup purposes as you might need to do changes to project build as long as -you go. - -## Setup http server to store artifacts - -In order to share build results you need shared storage. Basically any http server which supports http PUT/GET/HEAD -operations will work. In our case it is a Nginx OSS with file system module. Add the url to config and -change `remote@enabled` to true: - -```xml - - - http://your-buildcache-url - -``` - -Known limitations: auth is not supported yet - -## Build selection - -In order to share build results, you need a golden source of builds. Build stored in cache ideally should be a build -assembled in the most correct, comprehensive and complete way. In such a case you can make sure that whoever reuses such -build doesn't compromise quality of own build. Often per pull requests builds are the best candidates to populate cache -because they seed cache fast and provide sufficient quality safeguards. - -## CI Build setup to seed shared cache - -In order to share build results, you need to store builds in the shared storage. Default scheme is to configure -designated CI nodes only to push in cache and prohibit elsewhere. In order to allow writes in remote cache add jvm -property to designated CI builds. - -``` --Dremote.cache.save.enabled=true -``` - -Run your branch, review log and ensure that artifacts are uploaded to remote cache. Now, rerun build and ensure that it -completes almost instantly because it is fully cached. Hint: consider limiting first attempts to single agent/node to -simplify troubleshooting. - -## Normalize local builds to reuse CI build cache - -As practice shows, developers often don't realize that builds they run in local and CI environments are different. So -straightforward attempt to reuse remote cache in local build usually results in cache misses because of difference in -plugins, parameters, profiles, environment, etc. In order to reuse results you might need to change poms, cache config, -CI jobs and the project itself. This part is usually most challenging and time-consuming. Follow steps below to -iteratively achieve working configuration. - -### Before you start - -Before you start, please keep in mind basic principles: - -* Cache is checksum based, it is a complex hash function essentially. In order to to produce the same hash the source - code, effective poms and dependencies should match. -* There is no built-in normalization of line endings in this implementation, file checksum calculation is raw bytes - based. The most obvious implication could be illustrated by a simple Git checkout. By default git will check out - source code with CRLF line endings on win and LF on Linux. Because of that builds over same commit on a Linux agent - and local build on Windows workstation will yield different checksums. -* Parameters of plugins are manually tracked ony. For example to avoid of accidentally reusing builds which never run - tests ensure that critical surfire parameters are tracked (`skipTests` and similar) in config. The same applies for - all over plugins. - -### Configure local build in debug mode - -To minimize distractions and simplify understanding of discrepancies following is recommended: - -* Run build with single threaded builder to make sure logs from different modules do not interfere -* Enable cache fail fast mode to focus on the blocking failure -* Provide reference to the CI build as a baseline for comparison between your local and remote builds. Go to the - reference CI build and one of the final lines of the build should be - -``` -[INFO] [CACHE][artifactId] Saved to remote cache https://your-cache-url/<...>/915296a3-4596-4eb5-bf37-f6e13ebe087e/cache-report.xml. -``` - -followed by a link to a `cache-report.xml` file. The `cache-report.xml` contains aggregated information about the -produced cache and could be used as a baseline for comparison. - -* Run local build. Command line should look similar to this: - -```bash -mvnw verify -Dremote.cache.failFast=true -Dremote.cache.baselineUrl=https://url-from-ci-build-to-cache-report.xml -``` - -Once discrepancy between remote and local builds detected cache will fail with diagnostic info -in `target/incremental-maven` directory: - -``` -* buildinfo-baseline-3c64673e23259e6f.xml - build specification from baseline build -* buildinfo-db43936e0666ce7.xml - build specification of local build -* buildsdiff.xml - comparison report with list of discrepancies -``` - -Review `buildsdiff.xml` file and eliminate detected discrepancies.You can also diff build-info files directly to get low -level insights. See techniques to configure cache in [How-To](CACHE-HOWTO.md) and troubleshooting of typical issues in -the section below. - -# Common issues - -## Issue 1: Local checkout is with different line endings - -Solution: normalise line endings. Current implementation doesn't have built-in line endings normalization, it has to be -done externally. In git it is recommended to use `.gitattributes` file to establish consistent line endings across all -envs for file types specific to this project - -## Issue 2: Effective poms mismatch because of plugins filtering by profiles - -Different profiles between remote and local builds results in different text of effective poms and break checksums. -Solution: instead of adding/removing specific plugins from build altogether with profiles use profile specific `skip` -or `disabled` flags instead. Instead of: - - ``` - - - run-plugin-in-ci-only - - - - surefire-report-maven-plugin - - - - - - - - - ``` - -Use: - - ```xml - - - - true - - - - - maven-surefire-plugin - - - ${skip.plugin.property} - - - - - - - run-plugin-in-ci-only - - - false - - - - ``` - -Hint: effective poms could be found in `buildinfo` files under `/build/projectsInputInfo/item[@type='pom']` -xpath (`item type="pom"`). - -## Issue 3: Effective pom mismatch because of environment specific properties - -Potential reason: Sometimes it is not possible to avoid discrepancies in different environments - for example if you -need to invoke command line command, it will be likely different on win and linux. Such commands will appear in -effective pom as a different literal values and will result in checksum mismatch Solution: filter out such properties -from cache effective pom: - -```xml - - - - ... - - - - argLine - - - -``` - -## Issue 4: Unexpected or transient files in checksum calculation - -Potential reasons: plugins or tests emit temporary files (logs and similar) in non-standard locations Solution: adjust -global exclusions list to filter out unexpected files: - -``` - - tempfile.out - -``` - -see sample config for exact syntax - -## Issue 5: Difference in tracked plugin properties - -Tracked property in config means it is critical for determining is build up to date or not. Discrepancies could happen -for any plugin for a number of reasons. Example: local build is using java target 1.6, remote: 1.8. `buildsdiff.xml` -will produce something like - -``` - -``` - -Solution is at your discretion. If the property is tracked, out-of-date status is fair and expected. If you want to -relax consistency rules in favor of compatibility, remove property from tracked list - -## Issue 5: Version changes invalidate effective pom checksum - -Current implementation doesn't support version changes between cache entries. It will result in cache invalidation for -each new version. -To mitigate the issue please consider migrating off traditional Maven release approach - try to use single version id in -project (eg `MY-PROJECT-LOCAL`). Such approach simplifies git branching workflow significantly. - -Deployment of artifacts with specific version from builds with cache is not supported yet. - diff --git a/maven-caching/src/site/markdown/CACHE.md b/maven-caching/src/site/markdown/CACHE.md deleted file mode 100644 index 7449ef5cc7ec..000000000000 --- a/maven-caching/src/site/markdown/CACHE.md +++ /dev/null @@ -1,170 +0,0 @@ - - -## Overview - -Idea of Incremental Maven is to specify module inputs and outputs and make them known to standard Maven core. This -allows accurate analysis and determination of out-of-date build artifacts in the build dependencies graph. Making the -dependency graph analysis deterministic leads to improvements in build times by avoiding re-building unnecessary -modules. -Cache does not make any low-level interventions to build process and delegates actual build work to Maven core. This -guarantees that build results are identical to results produced by standard Maven and are fully reproducible. -To achieve accurate input and outputs calculation incremental Maven combines automatic introspection -of [project object model](https://maven.apache.org/pom.html#What_is_the_POM) in conjunction with configuration-driven -rules for fine-grained content and execution control. For content analysis it digests based approach which is more -reliable over widely used file timestamps in tools like Make or Apache Ant. Deterministic build state allows reliably -cache even intermediate outputs of build and share them between teams using remote cache. Deterministic inputs -calculation allows distributed and parallel builds running in heterogeneous environments (like cloud of build agents) -could efficiently reuse cached build artifacts. Therefore incremental Maven is particularly well-suited for large Maven -projects that have significant number of small modules. Remote cache in conjunction with precise input identification -effectively enables "change once - build once" approach. - -### Maven insights - -The challenge of implementing build cache in Maven is that domain model is overly generic and doesn't support well -reproducible builds. You might have never thought of that, but it is a reality that 2 different Maven builds from the -same source code normally produce 2 different results. The question here is tolerance level - can you accept particular -discrepancies or not. For most of teams artifacts produced in the same build environment from the same source code will -be considered equivalent and technical differences between them (like different timestamps in jar manifests) could be -ignored. Now consider scenario when artifact is first produced with compiler X and cached but later without touching a -update compiler changes to Y and yields significantly different outcomes of compilation. Ask yourself a question \- am I -consider artifacts of such builds equivalent? Both Yes and No outcomes are pretty possible and could be even desirable -in different scenarios. When productivity and performance are the primary concerns it could be desirable to tolerate -insignificant discrepancies and maximise reuse of cached builds. As long as correctness in focus there could be demand -to comply with the exact release process. In the same way as with classic Maven, decision stays with you - what is -acceptable difference between builds. In the same way as with classic Maven the previous build is just an approximation -of today build with some tolerance (implementation, configuration and environment driven). - -### Implementation insights - -At very simple form, the incremental Maven is essentially a hash function which takes Maven project and produces hash -code (checksum). Then hash value is used to fetch and restore build result. -As with any hash, there could be collisions and instabilities. Collision could happen if the same hash produced from the -different build states and will result in unintended reuse. Instability means that same input yields different hash sums -in different runs - resulting in cache miss. The ultimate target is to achieve desired balance between collisions ( -sufficient correctness) and stability (sufficient reuse). In current implementation this is achieved by configuring -project specific processing rules in static configuration file. To avoid unintentional collisions and achieve better -correctness need to ensure that every critical file and plugin parameter accounted in build inputs. In order to achieve -better reuse need to ensure that non-critical files (test logs, readme and similar) and non-critical plugin parameters ( -like number of threads in build) are filtered out from build inputs. Essentially cache configuration is a process of -inspecting build, taking these decision and reflect them in the cache configuration. - -Please notice though idea of perfectly matching builds might be tempting, but it is not practical with regard to -caching. Perfect correctness means that not a single build could be reused and renders whole idea of builds caching -useless. Whatever build tool you use, there will be always a tradeoff which might be acceptable or not in particular -situation. Incremental Maven provides flexible and transparent control over caching policy and allows achieving desired -outcomes - maximize reusability or maximize equivalence between pre-cached candidates and requested builds. - -## Usage - -Cornerstone principle of using this tool is that it is delivered as is. Though the tool went through thorough -verification it's still consumer's responsibility to verify final product quality. - -### Recommended Scenarios - -Given all the information above, the Incremental Maven is recommended to use in scenarios when productivity and -performance are in priority. Typical cases are: - -* Speedup CI. In conjunction with remote cache incremental Maven could drastically reduce build times, validate pull - requests faster and reduce load on CI nodes -* Speedup developer builds. By reusing cached builds developers could verify changes much faster and be more productive. - No more `-DskipTests` and similar. -* Assemble artifacts faster. In some development models it might be critical to have as fast build/deploy cycle as - possible. Caching helps to cut down time drastically in such scenarios because it doesn't require to build cached - dependencies. - -For cases there correctness must be ensured (eg prod builds), it is recommended to disable cache and do clean builds. -This also allows you to validate cache correctness and reconcile cache outcomes on CI process. - -## Getting Started - -To on-board incremental Maven you need to complete several steps: - -* Get incremental Maven distribution -* Add cache config in `.mvn` -* Validate build results and iteratively adjust config to project specifics -* Migrate CI to incremental Maven with remote cache (to get full benefit) - optional - -### Get incremental Maven distribution - -The recommended way is to add [Takari Maven Wrapper](https://github.com/takari/maven-wrapper) to your project. In that -case `maven-wrapper.properties` should reference the latest incremental Maven distribution: - -```properties -distributionUrl=https://your-server/maven-incremental.zip -wrapperUrl=https://your-server/maven-wrapper-0.5.5.jar -``` - -Benefits of using Maven wrapper are following: - -* simple distribution across workstations and CI envs -* Maven stays compatible to your branch -* further upgrades are simplified significantly - If you refuse wrapper - then download, unzip and install it just as usual Maven. Further it will be assumed you use - Maven wrapper (`mvnw`) - -### Adding cache config - -Copy [default config `maven-cache-config.xml`](maven-cache-config.xml) -to [`.mvn/`](https://maven.apache.org/configure.html) dir of your project. -To get overall understanding of cache machinery it is recommended to review the config and read comments. In typical -scenario you need to adjust: - -* remote cache location -* source code files glob -* plugins reconciliation rules - add critical plugin parameters to reconciliation -* add non-standard source code locations (most of locations discovered automatically from project and plugins config, - but still there might be edge cases) - -See also: - -* [Remote cache setup](CACHE-REMOTE.md) - instruction how to setup shared cache -* [Cache How-To](CACHE-HOWTO.md) - cookbook for frequently encountered questions -* [Cache Parameters](CACHE-PARAMETERS.md) - description of supported parameters -* Attached [sample `maven-cache-config.xml` config file](maven-cache-config.xml) and elements annotations in xsd schema. (Ctrl+Q in idea should - show annotations in popup) - -### Adjusting cache config - -Having incremental Maven and the config in place you're all set. To run first cacheable build just -execute: `mvnw clean install` - -* Ensure that the config is picked up and incremental Maven is picked up. Just check log output - you will notice cache - related output or initialization error message. -* Navigate to your local repo directory - there should be sibling next to your local repo named `cache` -* Find `buildinfo.xml` for typical module and review it. Ensure that - * expected source code files are present in build info - * all critical plugins and their critical parameters are covered by config - -Notice - in configuration you should find best working trade-off between fairness and cache efficiency. Adding -unnecessary rules and checks could reduce both performance and cache efficiency (hit rate). - -### Adding caching CI and remote cache - -To leverage remote cache feature you need web server which supports get/put operations -like [Nginx OSS](http://nginx.org/en/) (with fs module) or binary repo in Artifactory. It is recommended to populate -remote cache from CI build. Benefits are: - -* such scheme provides predictable and consistent artifacts in remote cache -* usually CI builds project fast enough to populate cache for team members See [Remote cache setup](CACHE-REMOTE.md) for - detailed description of cache setup - -## Credits -CacheConfigImpl -* Maximilian Novikov - Project lead. Idea, design, coordination and verification. -* Alexander Ashitkin - Co-design and implementation of the majority of functionality -* Alexander Novoselov - Hashing module implementation \ No newline at end of file diff --git a/maven-caching/src/site/markdown/maven-cache-config.xml b/maven-caching/src/site/markdown/maven-cache-config.xml deleted file mode 100644 index 61193496de28..000000000000 --- a/maven-caching/src/site/markdown/maven-cache-config.xml +++ /dev/null @@ -1,145 +0,0 @@ - - - - - - true - SHA-256 - true - - PROJECT-LOCAL - - - http://host:port - - - 3 - - - - - - - {*.java,*.groovy,*.yaml,*.svcd,*.proto,*assembly.xml,assembly*.xml,*logback.xml,*.vm,*.ini,*.jks,*.properties,*.sh,*.bat} - - - src/ - - - pom.xml - - - - - - - 111 - - - - - - - - - - - - - - - 1 - 2 - - - - - - - - - - - - - - - - - - - - my-execution-id - - - - - - - install - - - - - deploy - - - - - deploy-local - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/maven-caching/src/site/site.xml b/maven-caching/src/site/site.xml deleted file mode 100644 index aa24fb501585..000000000000 --- a/maven-caching/src/site/site.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - ${project.scm.url} - - -

    - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java b/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java deleted file mode 100644 index 4d75e80c4624..000000000000 --- a/maven-caching/src/test/java/org/apache/maven/caching/BuildInfoTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.apache.maven.caching; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import java.io.File; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.handler.DefaultArtifactHandler; -import org.apache.maven.caching.hash.HashFactory; -import org.apache.maven.caching.xml.Build; -import org.apache.maven.caching.xml.build.Artifact; -import org.apache.maven.caching.xml.build.CompletedExecution; -import org.apache.maven.caching.xml.build.DigestItem; -import org.apache.maven.caching.xml.build.ProjectsInputInfo; -import org.apache.maven.caching.xml.build.PropertyValue; -import org.apache.maven.caching.xml.XmlService; -import org.junit.jupiter.api.Test; - -public class BuildInfoTest { - - @Test - public void name() throws Exception { - - XmlService xmlService = new XmlService(); - - ProjectsInputInfo main = new ProjectsInputInfo(); - main.setChecksum("dependencyChecksum"); - main.addItem(createItem("pom", "4.0.0", "hash1")); - main.addItem(createItem("file", Paths.get(".").toString(), "hash2")); - - Artifact artifact = new Artifact(); - artifact.setGroupId("g"); - artifact.setArtifactId("a"); - artifact.setType("t"); - artifact.setClassifier("c"); - artifact.setScope("s"); - artifact.setFileName("f"); - artifact.setFileSize(123456); - artifact.setFileHash("456L"); - - org.apache.maven.caching.xml.build.Build buildInfo = new org.apache.maven.caching.xml.build.Build(); - buildInfo.setCacheImplementationVersion("cacheImplementationVersion"); - buildInfo.setBuildServer("server"); - buildInfo.setBuildTime(new Date()); - buildInfo.setArtifact(artifact); - buildInfo.setHashFunction("SHA-256"); - buildInfo.setGoals(Collections.singletonList("install")); - final org.apache.maven.artifact.Artifact attachedArtifact = new DefaultArtifact("ag", "aa", "av", "as", "at", "ac", new DefaultArtifactHandler()); - buildInfo.setAttachedArtifacts(Build.createAttachedArtifacts(Collections.singletonList(attachedArtifact), HashFactory.XX.createAlgorithm())); - buildInfo.setProjectsInputInfo(main); - buildInfo.setExecutions(createExecutions()); - - byte[] bytes = xmlService.toBytes(buildInfo); - System.out.println(new String(bytes, StandardCharsets.UTF_8)); - Path tempFilePath = Files.createTempFile("test", "test"); - File file = tempFilePath.toFile(); - file.deleteOnExit(); - Files.write(tempFilePath, bytes); - - org.apache.maven.caching.xml.build.Build buildInfo1 = xmlService.loadBuild(file); - System.out.println(buildInfo1); - } - - private List createExecutions() { - CompletedExecution execution = new CompletedExecution(); - execution.setExecutionKey("execkey"); - PropertyValue property = new PropertyValue(); - property.setValue("value"); - property.setName("key"); - execution.addProperty(property); - return new ArrayList<>(Arrays.asList(execution)); - } - - private DigestItem createItem(String pom, String s, String hash1) { - final DigestItem d1 = new DigestItem(); - d1.setType(pom); - d1.setHash(s); - d1.setValue(hash1); - return d1; - } -} \ No newline at end of file diff --git a/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java b/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java deleted file mode 100644 index a7da1aecf68f..000000000000 --- a/maven-caching/src/test/java/org/apache/maven/caching/checksum/MavenProjectInputTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.apache.maven.caching.checksum; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - - -public class MavenProjectInputTest -{ - - private static final String GLOB = "{*-pom.xml}"; - - @Test - public void testAddInputsRelativePath() - { - // MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), Paths.get("src\\test\\resources\\org"), GLOB); - // ArrayList files = new ArrayList<>(); - // inputs.listDirOrFile("../../resources", inputs.dirGlob, files, new HashSet()); - // assertEquals(4, files.size()); - } - - @Test - public void testAddInputsAbsolutePath() - { - // Path baseDirPath = Paths.get("src\\test\\resources\\org"); - // MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), baseDirPath, GLOB); - // ArrayList files = new ArrayList<>(); - // Path candidatePath = baseDirPath.resolve("../../resources").normalize().toAbsolutePath(); - // inputs.listDirOrFile(candidatePath.toString(), inputs.dirGlob, files, new HashSet()); - // assertEquals(4, files.size()); // pom is filtered out by hardcoded if - } - - @Test - public void testGlobInput() - { - // Path baseDirPath = Paths.get("src\\test\\resources"); - // MavenProjectInput inputs = new MavenProjectInput(config, new ArrayList(), baseDirPath, GLOB); - // ArrayList files = new ArrayList<>(); - // inputs.tryAddInputs("*.java", files, new HashSet()); - // assertEquals(0, files.size()); // pom is filtered out by hardcoded if - } - - @Test - public void testGetDirectoryFiles() - { - List directoryFiles = new ArrayList<>(); - MavenProjectInput.walkDirectoryFiles( - Paths.get( "src/test/resources/test-folder" ), - directoryFiles, - MavenProjectInput.DEFAULT_GLOB, - it -> false ); - assertEquals( 0, directoryFiles.size() ); // pom is filtered out by hardcoded if - } - - @Test - public void testGetDirectoryFiles2() - { - List directoryFiles = new ArrayList<>(); - MavenProjectInput.walkDirectoryFiles( - Paths.get( "src/test/resources/test-folder" ), - directoryFiles, - GLOB, - it -> false ); - assertEquals( 1, directoryFiles.size() ); // pom is filtered out by hardcoded if - } -} diff --git a/maven-caching/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java b/maven-caching/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java deleted file mode 100644 index 175e5ea2384d..000000000000 --- a/maven-caching/src/test/java/org/apache/maven/caching/checksum/SHAHashTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.apache.maven.caching.checksum; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.nio.charset.StandardCharsets; - -import org.apache.maven.caching.hash.HashAlgorithm; -import org.apache.maven.caching.hash.HashChecksum; -import org.junit.jupiter.api.Test; - -import static org.apache.maven.caching.hash.HashFactory.SHA256; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class SHAHashTest { - private static final byte[] HELLO_ARRAY = "hello".getBytes(StandardCharsets.UTF_8); - private static final byte[] WORLD_ARRAY = "world".getBytes(StandardCharsets.UTF_8); - private static final String EMPTY_HASH = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; - private static final String HELLO_HASH = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"; - private static final String WORLD_HASH = "486ea46224d1bb4fb680f34f7c9ad96a8f24ec88be73ea8e5a6c65260e9cb8a7"; - private static final String HELLO_CHECKSUM = "9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50"; - private static final String WORLD_CHECKSUM = "63e5c163c81ee9a3ed99d365ff963ecea340cc455deeac7c4b63ac75b9cf4706"; - private static final String FULL_CHECKSUM = "7305db9b2abccd706c256db3d97e5ff48d677cfe4d3a5904afb7da0e3950e1e2"; - - private static final HashAlgorithm ALGORITHM = SHA256.createAlgorithm(); - private static final HashChecksum CHECKSUM = SHA256.createChecksum(0); - - @Test - public void testEmptyArray() { - byte[] emptyArray = new byte[0]; - String hash = ALGORITHM.hash(emptyArray); - assertEquals(EMPTY_HASH, hash); - } - - @Test - public void testSimpleHash() { - String helloHash = ALGORITHM.hash(HELLO_ARRAY); - assertEquals(HELLO_HASH, helloHash); - - String worldHash = ALGORITHM.hash(WORLD_ARRAY); - assertEquals(WORLD_HASH, worldHash); - } - - @Test - public void testSimpleChecksum() { - assertEquals(HELLO_HASH, CHECKSUM.update(HELLO_ARRAY)); - assertEquals(HELLO_CHECKSUM, CHECKSUM.digest()); - - assertEquals(WORLD_HASH, CHECKSUM.update(WORLD_ARRAY)); - assertEquals(WORLD_CHECKSUM, CHECKSUM.digest()); - - assertEquals(HELLO_HASH, CHECKSUM.update(HELLO_ARRAY)); - assertEquals(WORLD_HASH, CHECKSUM.update(WORLD_ARRAY)); - assertEquals(FULL_CHECKSUM, CHECKSUM.digest()); - } -} diff --git a/maven-caching/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java b/maven-caching/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java deleted file mode 100644 index 1024d0e31df4..000000000000 --- a/maven-caching/src/test/java/org/apache/maven/caching/checksum/XXHashTest.java +++ /dev/null @@ -1,132 +0,0 @@ -package org.apache.maven.caching.checksum; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; - -import org.apache.maven.caching.hash.HashAlgorithm; -import org.apache.maven.caching.hash.HashChecksum; -import org.junit.jupiter.api.Test; - -import static org.apache.maven.caching.hash.HashFactory.XX; -import static org.apache.maven.caching.hash.HashFactory.XXMM; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class XXHashTest { - private static final byte[] HELLO_ARRAY = "hello".getBytes(StandardCharsets.UTF_8); - private static final byte[] WORLD_ARRAY = "world".getBytes(StandardCharsets.UTF_8); - private static final long HELLO_LONG = 2794345569481354659L; - private static final long WORLD_LONG = -1767385783675760145L; - private static final String EMPTY_HASH = "ef46db3751d8e999"; - private static final String HELLO_HASH = "26c7827d889f6da3"; - private static final String WORLD_HASH = "e778fbfe66ee51ef"; - private static final String HELLO_CHECKSUM = "c07c10338a825a5d"; - private static final String WORLD_CHECKSUM = "cb21505d7a714523"; - private static final String FULL_CHECKSUM = "b8ca8fa824d335e9"; - - private static final HashAlgorithm ALGORITHM = XX.createAlgorithm(); - - @Test - public void testEmptyArray() { - byte[] emptyArray = new byte[0]; - String hash = ALGORITHM.hash(emptyArray); - assertEquals(EMPTY_HASH, hash); - } - - @Test - public void testSimpleHash() { - String helloHash = ALGORITHM.hash(HELLO_ARRAY); - assertEquals(HELLO_HASH, helloHash); - - String worldHash = ALGORITHM.hash(WORLD_ARRAY); - assertEquals(WORLD_HASH, worldHash); - } - - @Test - public void testSimpleChecksum() { - String helloChecksum = ALGORITHM.hash(longToBytes(1, HELLO_LONG)); - assertEquals(HELLO_CHECKSUM, helloChecksum); - - String worldChecksum = ALGORITHM.hash(longToBytes(1, WORLD_LONG)); - assertEquals(WORLD_CHECKSUM, worldChecksum); - - String checksum = ALGORITHM.hash(longToBytes(2, HELLO_LONG, WORLD_LONG)); - assertEquals(FULL_CHECKSUM, checksum); - } - - @Test - public void testEmptyBuffer() { - assertEmptyBuffer(XX.createChecksum(0)); - assertEmptyBuffer(XXMM.createChecksum(0)); - } - - @Test - public void testSingleHash() { - assertSingleHash(XX.createChecksum(1)); - assertSingleHash(XXMM.createChecksum(1)); - } - - @Test - public void testSingleChecksum() { - assertSingleChecksum(XX.createChecksum(1)); - assertSingleChecksum(XXMM.createChecksum(1)); - } - - @Test - public void testNotFullChecksum() { - assertSingleChecksum(XX.createChecksum(2)); - assertSingleChecksum(XXMM.createChecksum(2)); - } - - @Test - public void testFullChecksum() { - assertFullChecksum(XX.createChecksum(2)); - assertFullChecksum(XXMM.createChecksum(2)); - } - - private void assertEmptyBuffer(HashChecksum checksum) { - assertEquals(EMPTY_HASH, checksum.digest()); - } - - private void assertSingleHash(HashChecksum checksum) { - assertEquals(HELLO_HASH, checksum.update(HELLO_ARRAY)); - assertEquals(HELLO_CHECKSUM, checksum.digest()); - } - - private void assertSingleChecksum(HashChecksum checksum) { - assertEquals(HELLO_HASH, checksum.update(HELLO_HASH)); - assertEquals(HELLO_CHECKSUM, checksum.digest()); - } - - private void assertFullChecksum(HashChecksum checksum) { - assertEquals(HELLO_HASH, checksum.update(HELLO_HASH)); - assertEquals(WORLD_HASH, checksum.update(WORLD_HASH)); - assertEquals(FULL_CHECKSUM, checksum.digest()); - } - - private byte[] longToBytes(int size, long... values) { - final ByteBuffer buffer = ByteBuffer.allocate(size * Long.SIZE / Byte.SIZE); - for (long value : values) { - buffer.putLong(value); - } - return buffer.array(); - } -} diff --git a/maven-caching/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java b/maven-caching/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java deleted file mode 100644 index 8ddca35a0cde..000000000000 --- a/maven-caching/src/test/java/org/apache/maven/caching/hash/HexUtilsTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.apache.maven.caching.hash; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class HexUtilsTest { - - @Test - public void testEncodeToHex() { - //array length = 8 left padded with zeroes - assertEquals("0000000000000000", HexUtils.encode(new byte[8])); - assertEquals("00", HexUtils.encode(new byte[1])); - - assertEquals("0a", HexUtils.encode(new byte[]{10})); - assertEquals("000000000000000a", HexUtils.encode(new byte[]{0, 0, 0, 0, 0, 0, 0, 10})); - - assertEquals("0100", HexUtils.encode(new byte[]{1, 0})); - assertEquals("0000000000000101", HexUtils.encode(new byte[]{0, 0, 0, 0, 0, 0, 1, 1})); - } - - @Test - public void testDecodeHex() { - assertArrayEquals(new byte[]{0}, HexUtils.decode("00")); - assertArrayEquals(new byte[]{10}, HexUtils.decode("0a")); - assertArrayEquals(new byte[]{10}, HexUtils.decode("0A")); - assertArrayEquals(new byte[]{1, 0}, HexUtils.decode("0100")); - } - -} \ No newline at end of file diff --git a/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java b/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java deleted file mode 100644 index 389522363f4f..000000000000 --- a/maven-caching/src/test/java/org/apache/maven/caching/xml/XmlServiceTest.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.apache.maven.caching.xml; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.caching.xml.build.Build; -import org.apache.maven.caching.xml.diff.Diff; -import org.apache.maven.caching.xml.config.CacheConfig; -import org.apache.maven.caching.xml.report.CacheReport; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import java.io.InputStream; - -import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; - -import org.w3c.dom.Document; - -public class XmlServiceTest { - - @Test - @Disabled("cache-build-1.0.0.xsd not found") - public void testConfig() throws Exception { - SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - Schema schema = sf.newSchema(getClass().getResource("/cache-config-1.0.0.xsd")); - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - dbf.setSchema(schema); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse( getClass().getResource( "cache-config-instance.xml" ).toString() ); - - InputStream is = getClass().getResourceAsStream( "cache-config-instance.xml" ); - final CacheConfig cache = new XmlService().loadCacheConfig( is ); - } - - @Test - @Disabled("cache-build-1.0.0.xsd not found") - public void testReport() throws Exception { - SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - Schema schema = sf.newSchema(getClass().getResource("/cache-report-1.0.0.xsd")); - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - dbf.setSchema(schema); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse( getClass().getResource( "cache-report-instance.xml" ).toString() ); - - InputStream is = getClass().getResourceAsStream( "cache-report-instance.xml" ); - final CacheReport cacheReport = new XmlService().loadCacheReport( is ); - } - - @Test - @Disabled("cache-build-1.0.0.xsd not found") - public void testBuild() throws Exception { - SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - Schema schema = sf.newSchema(getClass().getResource("/cache-build-1.0.0.xsd")); - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - dbf.setSchema(schema); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse( getClass().getResource( "cache-build-instance.xml" ).toString() ); - - InputStream is = getClass().getResourceAsStream( "cache-build-instance.xml" ); - final Build build = new XmlService().loadBuild( is ); - } - - @Test - @Disabled("cache-build-1.0.0.xsd not found") - public void testDiff() throws Exception { - SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - Schema schema = sf.newSchema(getClass().getResource("/cache-diff-1.0.0.xsd")); - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - dbf.setSchema(schema); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse( getClass().getResource( "cache-diff-instance.xml" ).toString() ); - - InputStream is = getClass().getResourceAsStream( "cache-diff-instance.xml" ); - final Diff buildDiff = new XmlService().loadDiff( is ); - } -} \ No newline at end of file diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-build-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-build-instance.xml deleted file mode 100644 index c80e922425e9..000000000000 --- a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-build-instance.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - v3 - 1980-03-23T10:20:15.000 - my-server.com - SHA-256 - - clean - verify - - - com.my.shared - my-server - jar - my-server.jar - hashvalue - 123456 - - - - com.my.shared - my-server - java-source - sources - my-server-sources.jar - - - - - default:check:verify:duplicate-finder-maven-plugin:org.basepom.maven:1.3.0 - org.basepom.mojo.duplicatefinder.DuplicateFinderMojo - - true - false - - - - - 0136171ac2c9d9b066805bd09904a25318cfb2037189b20c48e79b20b63b81ed - - src/main/conf/my-context.xml - - - diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml deleted file mode 100644 index 8451304e6606..000000000000 --- a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-config-instance.xml +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - - - true - SHA-256 - true - - http://host:port - - - 3 - - - - - - - {*.java,*.groovy,*.yaml,*.svcd,*.proto,*assembly.xml,assembly*.xml,*logback.xml,*.vm,*.ini,*.jks,*.properties,*.sh,*.bat} - - - src/ - - - pom.xml - - - - - - - 111 - - - - - - - - - - - - - - - 1 - 2 - - - - - - - - - - - - - - - .*-processes.*\.zip - - - - - - - - - - - - aaa - - - - - - - install - - - - - deploy - - - - - deploy-local - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-diff-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-diff-instance.xml deleted file mode 100644 index e549ef940756..000000000000 --- a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-diff-instance.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - diff --git a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-report-instance.xml b/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-report-instance.xml deleted file mode 100644 index af1f64d1f63d..000000000000 --- a/maven-caching/src/test/resources/org/apache/maven/caching/xml/cache-report-instance.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - org.apache.maven - - - - diff --git a/maven-caching/src/test/resources/test-folder/test-pom.xml b/maven-caching/src/test/resources/test-folder/test-pom.xml deleted file mode 100644 index b5e89715a9cd..000000000000 --- a/maven-caching/src/test/resources/test-folder/test-pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - 4.0.0 - - org.apache.maven - maven-core - 2.0-SNAPSHOT - jar - - Maven - 2001 - - - - org.apache.maven - maven-model - 2.0-SNAPSHOT - jar - compile - - - org.apache.maven - maven-plugin - 2.0-SNAPSHOT - jar - compile - - - - - scm-connection - - diff --git a/pom.xml b/pom.xml index e4a98e69e8f2..e00aabc80e9f 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,6 @@ under the License. maven-model-builder maven-model-transform maven-core - maven-caching maven-settings maven-settings-builder maven-artifact From dc58d4b419517e64a17c93033e4808cb3b11b1b7 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 30 Nov 2021 10:39:28 +0100 Subject: [PATCH 188/188] Remove unwanted changes --- apache-maven/src/lib/jansi-native/README.txt | 8 - .../appended-resources/META-INF/LICENSE.vm | 3 - .../appended-resources/licenses/MPL-1.1.txt | 472 ------------------ .../apache/maven/wrapper/WrapperExecutor.java | 4 +- pom.xml | 1 - 5 files changed, 2 insertions(+), 486 deletions(-) delete mode 100644 apache-maven/src/lib/jansi-native/README.txt delete mode 100644 apache-maven/src/main/appended-resources/licenses/MPL-1.1.txt diff --git a/apache-maven/src/lib/jansi-native/README.txt b/apache-maven/src/lib/jansi-native/README.txt deleted file mode 100644 index 26a957e1b564..000000000000 --- a/apache-maven/src/lib/jansi-native/README.txt +++ /dev/null @@ -1,8 +0,0 @@ -This directory contains Jansi native libraries extracted from Jansi JAR. - -You can add your own build for platforms not natively supported by Jansi. -See here [1] on how to compile for your platform and and here [2] how libraries -follow Jansi's directory and filename conventions. - -[1] https://github.com/fusesource/jansi/tree/master/src/main/native -[2] https://github.com/fusesource/jansi/blob/321a8ff71c731e10f4ea05c607860180276b2215/src/main/java/org/fusesource/jansi/internal/OSInfo.java diff --git a/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm b/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm index 067b7db906fa..b589e36e0222 100644 --- a/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm +++ b/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm @@ -27,7 +27,6 @@ subject to the terms and conditions of the following licenses: #set ( $MITLicenseNames = [ "MIT License", "MIT license", "The MIT License" ] ) #foreach ( $project in $projects ) #**##foreach ( $license in $project.licenses ) -#* *##set ( $artifactId = $project.artifact.artifactId ) #* *##set ( $groupId = $project.artifact.groupId ) #* *##set ( $directory = 'lib' ) #* *##if ( !$apacheMavenGroupIds.contains( $groupId ) ) @@ -38,8 +37,6 @@ subject to the terms and conditions of the following licenses: #* *##set ( $spdx = 'MIT' ) #* *##elseif ( $license.name == "Eclipse Public License, Version 1.0" ) #* *##set ( $spdx = 'EPL-1.0' ) -#* *##elseif ( $license.name == "Mozilla Public License Version 1.1" || $artifactId == "juniversalchardet" ) -#* *##set ( $spdx = 'MPL-1.1' ) #* *##elseif ( $license.url.contains( "www.apache.org/licenses/LICENSE-2.0" ) ) #* *##set ( $spdx = 'Apache-2.0' ) #* *##else diff --git a/apache-maven/src/main/appended-resources/licenses/MPL-1.1.txt b/apache-maven/src/main/appended-resources/licenses/MPL-1.1.txt deleted file mode 100644 index 7bcf5c0e2885..000000000000 --- a/apache-maven/src/main/appended-resources/licenses/MPL-1.1.txt +++ /dev/null @@ -1,472 +0,0 @@ -http://www.mozilla.org/MPL/MPL-1.1.html - - - MOZILLA PUBLIC LICENSE - Version 1.1 - - --------------- - -1. Definitions. - - 1.0.1. "Commercial Use" means distribution or otherwise making the - Covered Code available to a third party. - - 1.1. "Contributor" means each entity that creates or contributes to - the creation of Modifications. - - 1.2. "Contributor Version" means the combination of the Original - Code, prior Modifications used by a Contributor, and the Modifications - made by that particular Contributor. - - 1.3. "Covered Code" means the Original Code or Modifications or the - combination of the Original Code and Modifications, in each case - including portions thereof. - - 1.4. "Electronic Distribution Mechanism" means a mechanism generally - accepted in the software development community for the electronic - transfer of data. - - 1.5. "Executable" means Covered Code in any form other than Source - Code. - - 1.6. "Initial Developer" means the individual or entity identified - as the Initial Developer in the Source Code notice required by Exhibit - A. - - 1.7. "Larger Work" means a work which combines Covered Code or - portions thereof with code not governed by the terms of this License. - - 1.8. "License" means this document. - - 1.8.1. "Licensable" means having the right to grant, to the maximum - extent possible, whether at the time of the initial grant or - subsequently acquired, any and all of the rights conveyed herein. - - 1.9. "Modifications" means any addition to or deletion from the - substance or structure of either the Original Code or any previous - Modifications. When Covered Code is released as a series of files, a - Modification is: - A. Any addition to or deletion from the contents of a file - containing Original Code or previous Modifications. - - B. Any new file that contains any part of the Original Code or - previous Modifications. - - 1.10. "Original Code" means Source Code of computer software code - which is described in the Source Code notice required by Exhibit A as - Original Code, and which, at the time of its release under this - License is not already Covered Code governed by this License. - - 1.10.1. "Patent Claims" means any patent claim(s), now owned or - hereafter acquired, including without limitation, method, process, - and apparatus claims, in any patent Licensable by grantor. - - 1.11. "Source Code" means the preferred form of the Covered Code for - making modifications to it, including all modules it contains, plus - any associated interface definition files, scripts used to control - compilation and installation of an Executable, or source code - differential comparisons against either the Original Code or another - well known, available Covered Code of the Contributor's choice. The - Source Code can be in a compressed or archival form, provided the - appropriate decompression or de-archiving software is widely available - for no charge. - - 1.12. "You" (or "Your") means an individual or a legal entity - exercising rights under, and complying with all of the terms of, this - License or a future version of this License issued under Section 6.1. - For legal entities, "You" includes any entity which controls, is - controlled by, or is under common control with You. For purposes of - this definition, "control" means (a) the power, direct or indirect, - to cause the direction or management of such entity, whether by - contract or otherwise, or (b) ownership of more than fifty percent - (50%) of the outstanding shares or beneficial ownership of such - entity. - -2. Source Code License. - - 2.1. The Initial Developer Grant. - The Initial Developer hereby grants You a world-wide, royalty-free, - non-exclusive license, subject to third party intellectual property - claims: - (a) under intellectual property rights (other than patent or - trademark) Licensable by Initial Developer to use, reproduce, - modify, display, perform, sublicense and distribute the Original - Code (or portions thereof) with or without Modifications, and/or - as part of a Larger Work; and - - (b) under Patents Claims infringed by the making, using or - selling of Original Code, to make, have made, use, practice, - sell, and offer for sale, and/or otherwise dispose of the - Original Code (or portions thereof). - - (c) the licenses granted in this Section 2.1(a) and (b) are - effective on the date Initial Developer first distributes - Original Code under the terms of this License. - - (d) Notwithstanding Section 2.1(b) above, no patent license is - granted: 1) for code that You delete from the Original Code; 2) - separate from the Original Code; or 3) for infringements caused - by: i) the modification of the Original Code or ii) the - combination of the Original Code with other software or devices. - - 2.2. Contributor Grant. - Subject to third party intellectual property claims, each Contributor - hereby grants You a world-wide, royalty-free, non-exclusive license - - (a) under intellectual property rights (other than patent or - trademark) Licensable by Contributor, to use, reproduce, modify, - display, perform, sublicense and distribute the Modifications - created by such Contributor (or portions thereof) either on an - unmodified basis, with other Modifications, as Covered Code - and/or as part of a Larger Work; and - - (b) under Patent Claims infringed by the making, using, or - selling of Modifications made by that Contributor either alone - and/or in combination with its Contributor Version (or portions - of such combination), to make, use, sell, offer for sale, have - made, and/or otherwise dispose of: 1) Modifications made by that - Contributor (or portions thereof); and 2) the combination of - Modifications made by that Contributor with its Contributor - Version (or portions of such combination). - - (c) the licenses granted in Sections 2.2(a) and 2.2(b) are - effective on the date Contributor first makes Commercial Use of - the Covered Code. - - (d) Notwithstanding Section 2.2(b) above, no patent license is - granted: 1) for any code that Contributor has deleted from the - Contributor Version; 2) separate from the Contributor Version; - 3) for infringements caused by: i) third party modifications of - Contributor Version or ii) the combination of Modifications made - by that Contributor with other software (except as part of the - Contributor Version) or other devices; or 4) under Patent Claims - infringed by Covered Code in the absence of Modifications made by - that Contributor. - -3. Distribution Obligations. - - 3.1. Application of License. - The Modifications which You create or to which You contribute are - governed by the terms of this License, including without limitation - Section 2.2. The Source Code version of Covered Code may be - distributed only under the terms of this License or a future version - of this License released under Section 6.1, and You must include a - copy of this License with every copy of the Source Code You - distribute. You may not offer or impose any terms on any Source Code - version that alters or restricts the applicable version of this - License or the recipients' rights hereunder. However, You may include - an additional document offering the additional rights described in - Section 3.5. - - 3.2. Availability of Source Code. - Any Modification which You create or to which You contribute must be - made available in Source Code form under the terms of this License - either on the same media as an Executable version or via an accepted - Electronic Distribution Mechanism to anyone to whom you made an - Executable version available; and if made available via Electronic - Distribution Mechanism, must remain available for at least twelve (12) - months after the date it initially became available, or at least six - (6) months after a subsequent version of that particular Modification - has been made available to such recipients. You are responsible for - ensuring that the Source Code version remains available even if the - Electronic Distribution Mechanism is maintained by a third party. - - 3.3. Description of Modifications. - You must cause all Covered Code to which You contribute to contain a - file documenting the changes You made to create that Covered Code and - the date of any change. You must include a prominent statement that - the Modification is derived, directly or indirectly, from Original - Code provided by the Initial Developer and including the name of the - Initial Developer in (a) the Source Code, and (b) in any notice in an - Executable version or related documentation in which You describe the - origin or ownership of the Covered Code. - - 3.4. Intellectual Property Matters - (a) Third Party Claims. - If Contributor has knowledge that a license under a third party's - intellectual property rights is required to exercise the rights - granted by such Contributor under Sections 2.1 or 2.2, - Contributor must include a text file with the Source Code - distribution titled "LEGAL" which describes the claim and the - party making the claim in sufficient detail that a recipient will - know whom to contact. If Contributor obtains such knowledge after - the Modification is made available as described in Section 3.2, - Contributor shall promptly modify the LEGAL file in all copies - Contributor makes available thereafter and shall take other steps - (such as notifying appropriate mailing lists or newsgroups) - reasonably calculated to inform those who received the Covered - Code that new knowledge has been obtained. - - (b) Contributor APIs. - If Contributor's Modifications include an application programming - interface and Contributor has knowledge of patent licenses which - are reasonably necessary to implement that API, Contributor must - also include this information in the LEGAL file. - - (c) Representations. - Contributor represents that, except as disclosed pursuant to - Section 3.4(a) above, Contributor believes that Contributor's - Modifications are Contributor's original creation(s) and/or - Contributor has sufficient rights to grant the rights conveyed by - this License. - - 3.5. Required Notices. - You must duplicate the notice in Exhibit A in each file of the Source - Code. If it is not possible to put such notice in a particular Source - Code file due to its structure, then You must include such notice in a - location (such as a relevant directory) where a user would be likely - to look for such a notice. If You created one or more Modification(s) - You may add your name as a Contributor to the notice described in - Exhibit A. You must also duplicate this License in any documentation - for the Source Code where You describe recipients' rights or ownership - rights relating to Covered Code. You may choose to offer, and to - charge a fee for, warranty, support, indemnity or liability - obligations to one or more recipients of Covered Code. However, You - may do so only on Your own behalf, and not on behalf of the Initial - Developer or any Contributor. You must make it absolutely clear than - any such warranty, support, indemnity or liability obligation is - offered by You alone, and You hereby agree to indemnify the Initial - Developer and every Contributor for any liability incurred by the - Initial Developer or such Contributor as a result of warranty, - support, indemnity or liability terms You offer. - - 3.6. Distribution of Executable Versions. - You may distribute Covered Code in Executable form only if the - requirements of Section 3.1-3.5 have been met for that Covered Code, - and if You include a notice stating that the Source Code version of - the Covered Code is available under the terms of this License, - including a description of how and where You have fulfilled the - obligations of Section 3.2. The notice must be conspicuously included - in any notice in an Executable version, related documentation or - collateral in which You describe recipients' rights relating to the - Covered Code. You may distribute the Executable version of Covered - Code or ownership rights under a license of Your choice, which may - contain terms different from this License, provided that You are in - compliance with the terms of this License and that the license for the - Executable version does not attempt to limit or alter the recipient's - rights in the Source Code version from the rights set forth in this - License. If You distribute the Executable version under a different - license You must make it absolutely clear that any terms which differ - from this License are offered by You alone, not by the Initial - Developer or any Contributor. You hereby agree to indemnify the - Initial Developer and every Contributor for any liability incurred by - the Initial Developer or such Contributor as a result of any such - terms You offer. - - 3.7. Larger Works. - You may create a Larger Work by combining Covered Code with other code - not governed by the terms of this License and distribute the Larger - Work as a single product. In such a case, You must make sure the - requirements of this License are fulfilled for the Covered Code. - -4. Inability to Comply Due to Statute or Regulation. - - If it is impossible for You to comply with any of the terms of this - License with respect to some or all of the Covered Code due to - statute, judicial order, or regulation then You must: (a) comply with - the terms of this License to the maximum extent possible; and (b) - describe the limitations and the code they affect. Such description - must be included in the LEGAL file described in Section 3.4 and must - be included with all distributions of the Source Code. Except to the - extent prohibited by statute or regulation, such description must be - sufficiently detailed for a recipient of ordinary skill to be able to - understand it. - -5. Application of this License. - - This License applies to code to which the Initial Developer has - attached the notice in Exhibit A and to related Covered Code. - -6. Versions of the License. - - 6.1. New Versions. - Netscape Communications Corporation ("Netscape") may publish revised - and/or new versions of the License from time to time. Each version - will be given a distinguishing version number. - - 6.2. Effect of New Versions. - Once Covered Code has been published under a particular version of the - License, You may always continue to use it under the terms of that - version. You may also choose to use such Covered Code under the terms - of any subsequent version of the License published by Netscape. No one - other than Netscape has the right to modify the terms applicable to - Covered Code created under this License. - - 6.3. Derivative Works. - If You create or use a modified version of this License (which you may - only do in order to apply it to code which is not already Covered Code - governed by this License), You must (a) rename Your license so that - the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", - "MPL", "NPL" or any confusingly similar phrase do not appear in your - license (except to note that your license differs from this License) - and (b) otherwise make it clear that Your version of the license - contains terms which differ from the Mozilla Public License and - Netscape Public License. (Filling in the name of the Initial - Developer, Original Code or Contributor in the notice described in - Exhibit A shall not of themselves be deemed to be modifications of - this License.) - -7. DISCLAIMER OF WARRANTY. - - COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, - WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF - DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. - THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE - IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, - YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE - COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER - OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF - ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. - -8. TERMINATION. - - 8.1. This License and the rights granted hereunder will terminate - automatically if You fail to comply with terms herein and fail to cure - such breach within 30 days of becoming aware of the breach. All - sublicenses to the Covered Code which are properly granted shall - survive any termination of this License. Provisions which, by their - nature, must remain in effect beyond the termination of this License - shall survive. - - 8.2. If You initiate litigation by asserting a patent infringement - claim (excluding declatory judgment actions) against Initial Developer - or a Contributor (the Initial Developer or Contributor against whom - You file such action is referred to as "Participant") alleging that: - - (a) such Participant's Contributor Version directly or indirectly - infringes any patent, then any and all rights granted by such - Participant to You under Sections 2.1 and/or 2.2 of this License - shall, upon 60 days notice from Participant terminate prospectively, - unless if within 60 days after receipt of notice You either: (i) - agree in writing to pay Participant a mutually agreeable reasonable - royalty for Your past and future use of Modifications made by such - Participant, or (ii) withdraw Your litigation claim with respect to - the Contributor Version against such Participant. If within 60 days - of notice, a reasonable royalty and payment arrangement are not - mutually agreed upon in writing by the parties or the litigation claim - is not withdrawn, the rights granted by Participant to You under - Sections 2.1 and/or 2.2 automatically terminate at the expiration of - the 60 day notice period specified above. - - (b) any software, hardware, or device, other than such Participant's - Contributor Version, directly or indirectly infringes any patent, then - any rights granted to You by such Participant under Sections 2.1(b) - and 2.2(b) are revoked effective as of the date You first made, used, - sold, distributed, or had made, Modifications made by that - Participant. - - 8.3. If You assert a patent infringement claim against Participant - alleging that such Participant's Contributor Version directly or - indirectly infringes any patent where such claim is resolved (such as - by license or settlement) prior to the initiation of patent - infringement litigation, then the reasonable value of the licenses - granted by such Participant under Sections 2.1 or 2.2 shall be taken - into account in determining the amount or value of any payment or - license. - - 8.4. In the event of termination under Sections 8.1 or 8.2 above, - all end user license agreements (excluding distributors and resellers) - which have been validly granted by You or any distributor hereunder - prior to termination shall survive termination. - -9. LIMITATION OF LIABILITY. - - UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT - (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL - DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, - OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR - ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY - CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, - WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER - COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN - INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF - LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY - RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW - PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE - EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO - THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. - -10. U.S. GOVERNMENT END USERS. - - The Covered Code is a "commercial item," as that term is defined in - 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer - software" and "commercial computer software documentation," as such - terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 - C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), - all U.S. Government End Users acquire Covered Code with only those - rights set forth herein. - -11. MISCELLANEOUS. - - This License represents the complete agreement concerning subject - matter hereof. If any provision of this License is held to be - unenforceable, such provision shall be reformed only to the extent - necessary to make it enforceable. This License shall be governed by - California law provisions (except to the extent applicable law, if - any, provides otherwise), excluding its conflict-of-law provisions. - With respect to disputes in which at least one party is a citizen of, - or an entity chartered or registered to do business in the United - States of America, any litigation relating to this License shall be - subject to the jurisdiction of the Federal Courts of the Northern - District of California, with venue lying in Santa Clara County, - California, with the losing party responsible for costs, including - without limitation, court costs and reasonable attorneys' fees and - expenses. The application of the United Nations Convention on - Contracts for the International Sale of Goods is expressly excluded. - Any law or regulation which provides that the language of a contract - shall be construed against the drafter shall not apply to this - License. - -12. RESPONSIBILITY FOR CLAIMS. - - As between Initial Developer and the Contributors, each party is - responsible for claims and damages arising, directly or indirectly, - out of its utilization of rights under this License and You agree to - work with Initial Developer and Contributors to distribute such - responsibility on an equitable basis. Nothing herein is intended or - shall be deemed to constitute any admission of liability. - -13. MULTIPLE-LICENSED CODE. - - Initial Developer may designate portions of the Covered Code as - "Multiple-Licensed". "Multiple-Licensed" means that the Initial - Developer permits you to utilize portions of the Covered Code under - Your choice of the MPL or the alternative licenses, if any, specified - by the Initial Developer in the file described in Exhibit A. - -EXHIBIT A -Mozilla Public License. - - ``The contents of this file are subject to the Mozilla Public License - Version 1.1 (the "License"); you may not use this file except in - compliance with the License. You may obtain a copy of the License at - https://www.mozilla.org/MPL/ - - Software distributed under the License is distributed on an "AS IS" - basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - License for the specific language governing rights and limitations - under the License. - - The Original Code is ______________________________________. - - The Initial Developer of the Original Code is ________________________. - Portions created by ______________________ are Copyright (C) ______ - _______________________. All Rights Reserved. - - Contributor(s): ______________________________________. - - Alternatively, the contents of this file may be used under the terms - of the _____ license (the "[___] License"), in which case the - provisions of [______] License are applicable instead of those - above. If you wish to allow use of your version of this file only - under the terms of the [____] License and not to allow others to use - your version of this file under the MPL, indicate your decision by - deleting the provisions above and replace them with the notice and - other provisions required by the [___] License. If you do not delete - the provisions above, a recipient may use your version of this file - under either the MPL or the [___] License." - - [NOTE: The text of this Exhibit A may differ slightly from the text of - the notices in the Source Code files of the Original Code. You should - use the text of this Exhibit A rather than the text found in the - Original Code Source Code for Your Modifications.] diff --git a/maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java b/maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java index 69a27b18789d..42d5677f50c7 100644 --- a/maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java +++ b/maven-wrapper/src/main/java/org/apache/maven/wrapper/WrapperExecutor.java @@ -28,8 +28,8 @@ import java.util.Properties; /** - * Wrapper executor, running {@link Installer} to get a Maven distribution ready, followed by - * {@link BootstrapMainStarter} to launch the Maven bootstrap. + * Wrapper executor, running {@link Installer} to get a Maven distribution ready, followed by {@BootstrapMainStarter} + * to launch the Maven bootstrap. * * @author Hans Dockter */ diff --git a/pom.xml b/pom.xml index e00aabc80e9f..346a805298ce 100644 --- a/pom.xml +++ b/pom.xml @@ -591,7 +591,6 @@ under the License. src/main/appended-resources/licenses/MIT-jsoup-1.12.1.txt src/main/appended-resources/licenses/EPL-1.0.txt src/main/appended-resources/licenses/unrecognized-javax.annotation-api-1.3.2.txt - src/main/appended-resources/licenses/MPL-1.1.txt