From 17e99ad93c502b0027d66367c245f648ce8c81fb 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 1/6] 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 7c7f9afb8862f5399383f875a7952a6994c56d79 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 3 Nov 2021 13:50:55 +0100 Subject: [PATCH 2/6] Make sure forked mojo executions have a correct phase set --- .../internal/DefaultLifecycleExecutionPlanCalculator.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java index ef60c4eb36b0..9992cf368c85 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java @@ -554,6 +554,8 @@ private List calculateForkedGoal( MojoExecution mojoExecution, Ma MojoExecution forkedExecution = new MojoExecution( forkedMojoDescriptor, forkedGoal ); + forkedExecution.setLifecyclePhase( mojoExecution.getLifecyclePhase() ); + mojoExecutionConfigurator( forkedExecution ).configure( project, forkedExecution, true ); finalizeMojoConfiguration( forkedExecution ); From 8bc5c290209477a1175e8be5655c6da096e9b604 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 3 Nov 2021 14:21:46 +0100 Subject: [PATCH 3/6] Avoid IllegalStateException when cache is not enabled --- .../org/apache/maven/caching/CacheEventSpy.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java b/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java index c6c9a202b380..3cd5578d9be3 100644 --- a/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java +++ b/maven-core/src/main/java/org/apache/maven/caching/CacheEventSpy.java @@ -19,6 +19,7 @@ * under the License. */ +import org.apache.maven.caching.xml.CacheConfig; import org.apache.maven.eventspy.AbstractEventSpy; import org.apache.maven.eventspy.EventSpy; import org.apache.maven.execution.ExecutionEvent; @@ -31,18 +32,24 @@ @Component( role = EventSpy.class ) public class CacheEventSpy extends AbstractEventSpy { + @Requirement + private CacheConfig cacheConfig; + @Requirement private CacheController cacheController; @Override public void onEvent( Object event ) throws Exception { - if ( event instanceof ExecutionEvent ) + if ( cacheConfig.isEnabled() ) { - ExecutionEvent executionEvent = (ExecutionEvent) event; - if ( executionEvent.getType() == ExecutionEvent.Type.SessionEnded ) + if ( event instanceof ExecutionEvent ) { - cacheController.saveCacheReport( executionEvent.getSession() ); + ExecutionEvent executionEvent = (ExecutionEvent) event; + if ( executionEvent.getType() == ExecutionEvent.Type.SessionEnded ) + { + cacheController.saveCacheReport( executionEvent.getSession() ); + } } } } From e0aa3de2edc0fdc86ab935a2f60669aff5c0e8ee Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 4 Nov 2021 20:57:07 +0100 Subject: [PATCH 4/6] 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 823882dbb1facb9f1348ad230fc8b2d3913f9579 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 5 Nov 2021 14:59:32 +0100 Subject: [PATCH 5/6] 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 4fe94e84cc6afe0189c7e9012e80851b30f0d945 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 5 Nov 2021 15:21:05 +0100 Subject: [PATCH 6/6] 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() ); }