From 3f03f0e7b29c0b68365d570d55b78ded9daea2ac Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 21 Nov 2022 09:50:33 +0100 Subject: [PATCH] [MNG-7576] Restore compatibility with maven 3.x (#841) --- .../internal/impl/TestRepositorySystem.java | 4 ++-- .../maven/repository/TestRepositorySystem.java | 2 +- .../model/building/DefaultModelBuilder.java | 14 ++++++++------ .../model/building/DefaultModelProcessor.java | 2 +- .../maven/model/io/DefaultModelReader.java | 18 ++++++++---------- .../org/apache/maven/model/io/ModelReader.java | 5 ++--- .../superpom/DefaultSuperPomProvider.java | 4 ++-- .../DefaultInheritanceAssemblerTest.java | 2 +- 8 files changed, 25 insertions(+), 26 deletions(-) diff --git a/maven-core/src/test/java/org/apache/maven/internal/impl/TestRepositorySystem.java b/maven-core/src/test/java/org/apache/maven/internal/impl/TestRepositorySystem.java index 430b276319..6bba90b06b 100644 --- a/maven-core/src/test/java/org/apache/maven/internal/impl/TestRepositorySystem.java +++ b/maven-core/src/test/java/org/apache/maven/internal/impl/TestRepositorySystem.java @@ -251,7 +251,7 @@ public class TestRepositorySystem try { - Model model = modelReader.read( pomFile, null ); + Model model = modelReader.read( pomFile, null ).getDelegate(); dependencies = Dependency.dependencyToApiV3( model.getDependencies() ); } @@ -338,4 +338,4 @@ public class TestRepositorySystem { } -} \ No newline at end of file +} diff --git a/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java b/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java index 7fdaef8d5d..cec73d273e 100644 --- a/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java +++ b/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java @@ -248,7 +248,7 @@ public class TestRepositorySystem try { - Model model = modelReader.read( pomFile, null ); + Model model = modelReader.read( pomFile, null ).getDelegate(); dependencies = model.getDependencies().stream().map( Dependency::new ).collect( Collectors.toList() ); } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 6899f0304b..f1a9976720 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -850,7 +850,7 @@ public class DefaultModelBuilder if ( request.isLocationTracking() ) { source = new InputSource( null, modelSource.getLocation() ); - options.put( ModelProcessor.INPUT_SOURCE, source ); + options.put( ModelProcessor.INPUT_SOURCE, new org.apache.maven.model.InputSource( source ) ); } else { @@ -859,7 +859,7 @@ public class DefaultModelBuilder try { - model = modelProcessor.read( modelSource.getInputStream(), options ); + model = modelProcessor.read( modelSource.getInputStream(), options ).getDelegate(); } catch ( ModelParseException e ) { @@ -872,7 +872,7 @@ public class DefaultModelBuilder try { - model = modelProcessor.read( modelSource.getInputStream(), options ); + model = modelProcessor.read( modelSource.getInputStream(), options ).getDelegate(); } catch ( ModelParseException ne ) { @@ -890,9 +890,11 @@ public class DefaultModelBuilder { try { + org.apache.maven.api.model.InputSource v4src + = model.getLocation( "" ).getSource(); Field field = InputSource.class.getDeclaredField( "modelId" ); field.setAccessible( true ); - field.set( source, ModelProblemUtils.toId( model ) ); + field.set( v4src, ModelProblemUtils.toId( model ) ); } catch ( Throwable t ) { @@ -974,14 +976,14 @@ public class DefaultModelBuilder try { // must implement TransformContext, but should use request to access properties/model cache - org.apache.maven.api.model.Model transformedFileModel = modelProcessor.read( pomFile, + Model transformedFileModel = modelProcessor.read( pomFile, Collections.singletonMap( ModelReader.TRANSFORMER_CONTEXT, context ) ); // rawModel with locationTrackers, required for proper feedback during validations // Apply enriched data rawModel = new Model( modelMerger.merge( rawModel.getDelegate(), - transformedFileModel, false, null ) ); + transformedFileModel.getDelegate(), false, null ) ); } catch ( IOException e ) { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java index 82af820d0e..168612d399 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java @@ -29,7 +29,7 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.apache.maven.api.model.Model; +import org.apache.maven.model.Model; import org.apache.maven.model.io.ModelReader; import org.apache.maven.model.locator.ModelLocator; import org.eclipse.sisu.Typed; diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java b/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java index 568dfac197..964dea786a 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java @@ -31,8 +31,8 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.apache.maven.api.model.InputSource; -import org.apache.maven.api.model.Model; +import org.apache.maven.model.InputSource; +import org.apache.maven.model.Model; import org.apache.maven.model.building.ModelSourceTransformer; import org.apache.maven.model.building.TransformerContext; import org.apache.maven.model.v4.MavenXpp3Reader; @@ -72,7 +72,9 @@ public class DefaultModelReader { Model model = read( in, input.toPath(), options ); - return model.withPomFile( input.toPath() ); + model.setPomFile( input ); + + return model; } } @@ -109,11 +111,6 @@ public class DefaultModelReader private InputSource getSource( Map options ) { Object value = ( options != null ) ? options.get( INPUT_SOURCE ) : null; - if ( value instanceof org.apache.maven.model.InputSource ) - { - org.apache.maven.model.InputSource src = ( org.apache.maven.model.InputSource ) value; - return new InputSource( src.getModelId(), src.getLocation() ); - } return (InputSource) value; } @@ -164,14 +161,15 @@ public class DefaultModelReader throws XmlPullParserException, IOException { MavenXpp3Reader mr = new MavenXpp3Reader(); - return mr.read( parser, strict ); + return new Model( mr.read( parser, strict ) ); } private Model readModelEx( XmlPullParser parser, InputSource source, boolean strict ) throws XmlPullParserException, IOException { MavenXpp3ReaderEx mr = new MavenXpp3ReaderEx(); - return mr.read( parser, strict, source ); + return new Model( mr.read( parser, strict, + new org.apache.maven.api.model.InputSource( source.getModelId(), source.getLocation() ) ) ); } } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java b/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java index c6ab1cf71d..04b1a3017c 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java @@ -25,8 +25,7 @@ import java.io.InputStream; import java.io.Reader; import java.util.Map; -import org.apache.maven.api.model.InputSource; -import org.apache.maven.api.model.Model; +import org.apache.maven.model.Model; /** * Handles deserialization of a model from some kind of textual format like XML. @@ -44,7 +43,7 @@ public interface ModelReader /** * The key for the option to enable tracking of line/column numbers. This option is of type - * {@link InputSource} and defaults to {@code null}. Providing an input source enables + * {@link org.apache.maven.model.InputSource} and defaults to {@code null}. Providing an input source enables * location tracking. */ String INPUT_SOURCE = "org.apache.maven.model.io.inputSource"; diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java b/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java index bb6a820256..f83231739d 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java @@ -80,9 +80,9 @@ public class DefaultSuperPomProvider + this.getClass().getPackage().getImplementationVersion() + ":super-pom"; InputSource inputSource = new InputSource( modelId, getClass().getResource( resource ).toExternalForm() ); - options.put( ModelProcessor.INPUT_SOURCE, inputSource ); + options.put( ModelProcessor.INPUT_SOURCE, new org.apache.maven.model.InputSource( inputSource ) ); - superModel = modelProcessor.read( is, options ); + superModel = modelProcessor.read( is, options ).getDelegate(); } catch ( IOException e ) { diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java index a2191f0b9b..3bab8c0a93 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java @@ -76,7 +76,7 @@ public class DefaultInheritanceAssemblerTest private Model getModel( String name ) throws IOException { - return reader.read( getPom( name ), null ); + return reader.read( getPom( name ), null ).getDelegate(); } @Test