From dc0928fcc3fe02353c58104d0cd86a8e66e92564 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 01/18] [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 9dd0250754e4..b1e830e7c3c5 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -217,7 +217,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 fe5e0ffe34707703018514a23d72bd0ba32bb92d Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 4 Nov 2021 20:57:07 +0100 Subject: [PATCH 02/18] [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 b1e830e7c3c5..bdd55438708e 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -235,11 +235,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 @@ -275,6 +280,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 a20cb86dc6885ccca2ac791a117fd35d33738f17 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 5 Nov 2021 14:59:32 +0100 Subject: [PATCH 03/18] [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 bdd55438708e..5ff2215e2420 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -246,6 +246,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 896eeb9c6ae1e78e6bcc8bfdfe0c843e646e562f Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 5 Nov 2021 15:21:05 +0100 Subject: [PATCH 04/18] [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 71596914c26fa7d16d72688e3ef510785fdaf7e2 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 05/18] [MNG-7324] remove now unused JAXB dependencies --- .../appended-resources/META-INF/LICENSE.vm | 2 -- .../appended-resources/licenses/EDL-1.0.txt | 23 ------------- maven-core/pom.xml | 33 ------------------- pom.xml | 1 - 4 files changed, 59 deletions(-) delete mode 100644 apache-maven/src/main/appended-resources/licenses/EDL-1.0.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 6ac9f31124b7..d5cba211a660 100644 --- a/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm +++ b/apache-maven/src/main/appended-resources/META-INF/LICENSE.vm @@ -42,8 +42,6 @@ subject to the terms and conditions of the following licenses: #* *##set ( $spdx = 'EPL-1.0' ) #* *##elseif ( $license.url.contains( "www.apache.org/licenses/LICENSE-2.0" ) ) #* *##set ( $spdx = 'ASL-2.0' ) -#* *##elseif ( $license.url.contains( "www.eclipse.org/org/documents/edl-v10.php" ) ) -#* *##set ( $spdx = 'EDL-1.0' ) #* *##elseif ( $license.url.contains( "www.mozilla.org/en-US/MPL/1.1" ) ) #* *##set ( $spdx = 'MPL-1.1' ) #* *##elseif ( $license.url.contains( "www.gnu.org/licenses/gpl" ) ) 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 5ff2215e2420..c3c3c7cb32fc 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -156,17 +156,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 @@ -281,28 +270,6 @@ under the License. - diff --git a/pom.xml b/pom.xml index f76757ba9fc6..bfadcb6ee4a8 100644 --- a/pom.xml +++ b/pom.xml @@ -555,7 +555,6 @@ 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/EDL-1.0.txt src/main/appended-resources/licenses/MPL-1.1.txt src/main/appended-resources/licenses/LGPL-3.0.txt .editorconfig From b9985c817386f2c6bea5d68d2e84c854ed55bc52 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 06/18] [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 6047eda970c72b752c183d9dc6f303d0975fac8d 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 07/18] [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 c3c3c7cb32fc..b82ef03c9617 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -215,7 +215,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 9c57048992421eed2db3042a6165acdf012e130c 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 08/18] [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 b82ef03c9617..93aede9be0d1 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -215,9 +215,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 @@ -233,9 +233,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 cfe213c0330a4a7d0e5648dd6ad02a4c69e6261b Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 8 Nov 2021 17:32:20 +0100 Subject: [PATCH 09/18] [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 93aede9be0d1..80a90aa8ba60 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -205,43 +205,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 bfadcb6ee4a8..d6bc44db199d 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 a28f24cd095836ae382462b24f46879458049fc0 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 08:40:48 +0100 Subject: [PATCH 10/18] [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 a7294fabae56dad036c54e57f429797adf50d338 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 09:42:25 +0100 Subject: [PATCH 11/18] [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 2cc6ca31d533..276a2cac3e9e 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 d6bc44db199d..44a61b887f3f 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 58cc8ab83f61c2f6030ec5d29a77d0818c1e90ee Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 10:19:58 +0100 Subject: [PATCH 12/18] [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 9522eb759ff59fbcef3462747a51c709beae47ca Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 10:20:41 +0100 Subject: [PATCH 13/18] [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 f078a9a519de949f561d42411734ccec95277c38 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 14:51:39 +0100 Subject: [PATCH 14/18] [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 d86ac76497f45ef4d1bf4b1a8cfef80f51426a84 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 16:26:38 +0100 Subject: [PATCH 15/18] [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 41e799309bad489f252accd6006475eadd39f8b3 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 16:54:06 +0100 Subject: [PATCH 16/18] [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 cdc3b31e867fc2b6370cf3c61abdd26b72884ce2 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 17:03:28 +0100 Subject: [PATCH 17/18] [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 2c4e9985b31b1b2c1baa818c964336c990918c19 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 9 Nov 2021 17:57:40 +0100 Subject: [PATCH 18/18] [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"> - +