From 9bfc58f2c4f0e039ea7f776ae859976cd85fbbaf Mon Sep 17 00:00:00 2001 From: Mikolaj Izdebski Date: Thu, 19 Dec 2013 14:41:05 +0100 Subject: [PATCH 2/4] Remove integration with for Apache Ivy [backport-feature-remove-ivy-support] --- xmvn-core/pom.xml | 4 - .../maven/model/impl/IvyModelReader.java | 160 --------------------- .../maven/installer/BasicIvyInstallerTest.java | 80 ----------- .../maven/installer/IvyInstallerExclusionTest.java | 87 ----------- xmvn-parent/pom.xml | 6 - 5 files changed, 337 deletions(-) delete mode 100644 xmvn-core/src/main/java/org/fedoraproject/maven/model/impl/IvyModelReader.java delete mode 100644 xmvn-core/src/test/java/org/fedoraproject/maven/installer/BasicIvyInstallerTest.java delete mode 100644 xmvn-core/src/test/java/org/fedoraproject/maven/installer/IvyInstallerExclusionTest.java diff --git a/xmvn-core/pom.xml b/xmvn-core/pom.xml index f7b9db3..79238cd 100644 --- a/xmvn-core/pom.xml +++ b/xmvn-core/pom.xml @@ -57,10 +57,6 @@ org.codehaus.plexus plexus-utils - - org.apache.ivy - ivy - diff --git a/xmvn-core/src/main/java/org/fedoraproject/maven/model/impl/IvyModelReader.java b/xmvn-core/src/main/java/org/fedoraproject/maven/model/impl/IvyModelReader.java deleted file mode 100644 index 1bd7aea..0000000 --- a/xmvn-core/src/main/java/org/fedoraproject/maven/model/impl/IvyModelReader.java +++ /dev/null @@ -1,160 +0,0 @@ -/*- - * Copyright (c) 2013 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.fedoraproject.maven.model.impl; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.nio.file.Path; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ExcludeRule; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Exclusion; -import org.apache.maven.model.Model; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.util.StringUtils; -import org.fedoraproject.maven.model.ModelFormatException; -import org.fedoraproject.maven.model.ModelReader; - -/** - * WARNING: This class is part of internal implementation of XMvn and it is marked as public only for - * technical reasons. This class is not part of XMvn API. Client code using XMvn should not reference - * it directly. - * - * @author Mikolaj Izdebski - */ -@Component( role = ModelReader.class, hint = "ivy", instantiationStrategy = "singleton" ) -public class IvyModelReader - implements ModelReader -{ - private static final List MAVEN_SCOPES = Arrays.asList( "compile", "runtime", "provided", "test", "system" ); - - private ModuleDescriptor readModule( Path modulePath ) - throws IOException, ParseException - { - try - { - XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); - IvySettings settings = new IvySettings(); - return parser.parseDescriptor( settings, modulePath.toUri().toURL(), false ); - } - catch ( MalformedURLException e ) - { - throw new RuntimeException( e ); - } - } - - private String nullify( String value, String defaultValue ) - { - if ( StringUtils.isEmpty( value ) || value.equals( defaultValue ) ) - return null; - - return value; - } - - private Model getModuleModel( ModuleDescriptor module ) - { - Model model = new Model(); - model.setModelVersion( "4.0.0" ); - - ModuleRevisionId moduleRevision = module.getModuleRevisionId(); - model.setGroupId( moduleRevision.getOrganisation() ); - model.setArtifactId( moduleRevision.getName() ); - model.setVersion( moduleRevision.getRevision() ); - - model.setPackaging( "pom" ); - for ( Artifact artifact : module.getAllArtifacts() ) - if ( artifact.getName().equals( moduleRevision.getName() ) && artifact.getAttribute( "classifier" ) == null ) - model.setPackaging( artifact.getType() ); - - for ( DependencyDescriptor dependencyModule : module.getDependencies() ) - { - Set scopes = new HashSet<>( MAVEN_SCOPES ); - scopes.retainAll( Arrays.asList( dependencyModule.getModuleConfigurations() ) ); - String scope = scopes.isEmpty() ? null : scopes.iterator().next(); - - Map map = new LinkedHashMap<>(); - for ( DependencyArtifactDescriptor dependencyArtifact : dependencyModule.getAllDependencyArtifacts() ) - { - String classifier = dependencyArtifact.getExtraAttribute( "classifier" ); - String type = dependencyArtifact.getType(); - map.put( classifier, type ); - } - if ( map.isEmpty() ) - map = Collections.singletonMap( null, null ); - - List exclusions = new ArrayList<>(); - for ( ExcludeRule rule : dependencyModule.getAllExcludeRules() ) - { - Exclusion exclusion = new Exclusion(); - exclusions.add( exclusion ); - - ModuleId exclusedModule = rule.getId().getModuleId(); - exclusion.setGroupId( exclusedModule.getOrganisation() ); - exclusion.setArtifactId( exclusedModule.getName() ); - } - - for ( Entry entry : map.entrySet() ) - { - Dependency dependency = new Dependency(); - model.addDependency( dependency ); - - ModuleRevisionId dependencyRevision = dependencyModule.getDependencyRevisionId(); - dependency.setGroupId( dependencyRevision.getOrganisation() ); - dependency.setArtifactId( dependencyRevision.getName() ); - dependency.setVersion( nullify( dependencyRevision.getRevision(), "SYSTEM" ) ); - dependency.setType( nullify( entry.getValue(), "jar" ) ); - dependency.setClassifier( nullify( entry.getKey(), "" ) ); - dependency.setScope( nullify( scope, "compile" ) ); - dependency.setExclusions( new ArrayList<>( exclusions ) ); - } - } - - return model; - } - - @Override - public Model readModel( Path modelPath ) - throws IOException, ModelFormatException - { - try - { - ModuleDescriptor module = readModule( modelPath ); - return getModuleModel( module ); - } - catch ( ParseException e ) - { - throw new ModelFormatException( "Unable to parse Ivy module", e ); - } - } -} diff --git a/xmvn-core/src/test/java/org/fedoraproject/maven/installer/BasicIvyInstallerTest.java b/xmvn-core/src/test/java/org/fedoraproject/maven/installer/BasicIvyInstallerTest.java deleted file mode 100644 index cfbe2b2..0000000 --- a/xmvn-core/src/test/java/org/fedoraproject/maven/installer/BasicIvyInstallerTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * Copyright (c) 2013 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.fedoraproject.maven.installer; - -import static org.custommonkey.xmlunit.XMLUnit.setIgnoreWhitespace; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.fedoraproject.maven.utils.ArtifactUtils; -import org.sonatype.aether.artifact.Artifact; -import org.sonatype.aether.util.artifact.DefaultArtifact; - -/** - * @author Mikolaj Izdebski - */ -public class BasicIvyInstallerTest - extends AbstractInstallerTest -{ - /** - * Test installation of Ivy modules. - * - * @throws Exception - */ - public void testComponentLookup() - throws Exception - { - Path artifactPath = Paths.get( "src/test/resources/jar/empty.jar" ); - Path modelPath = Paths.get( "src/test/resources/ivy/simple.ivy" ); - - Artifact artifact = new DefaultArtifact( "org.apache", "hello-ivy", "jar", "1.2.3" ); - artifact = artifact.setFile( artifactPath.toFile() ); - artifact = ArtifactUtils.setRawModelPath( artifact, modelPath ); - artifact = ArtifactUtils.setEffectiveModelPath( artifact, modelPath ); - - request.addArtifact( artifact ); - - logger.info( "Added arrifact " + artifact ); - logger.info( " POM path: " + modelPath.toAbsolutePath() ); - logger.info( " JAR path: " + artifactPath.toAbsolutePath() ); - - performInstallation(); - - setIgnoreWhitespace( true ); - - assertTrue( Files.isRegularFile( installRoot.resolve( "repo/jar/hello-ivy.jar" ) ) ); - assertXmlEqual( "ivy/simple.ivy", "repo/raw-pom/JPP-hello-ivy.pom" ); - assertXmlEqual( "ivy/simple.pom", "repo/effective-pom/JPP-hello-ivy.pom" ); - - StringBuilder depmap = new StringBuilder(); - depmap.append( "" ); - depmap.append( " " ); - depmap.append( " " ); - depmap.append( " org.apache" ); - depmap.append( " hello-ivy" ); - depmap.append( " 1.2.3" ); - depmap.append( " " ); - depmap.append( " " ); - depmap.append( " JPP" ); - depmap.append( " hello-ivy" ); - depmap.append( " " ); - depmap.append( " " ); - depmap.append( "" ); - assertXmlEqual( depmap, "depmaps/package.xml" ); - } -} diff --git a/xmvn-core/src/test/java/org/fedoraproject/maven/installer/IvyInstallerExclusionTest.java b/xmvn-core/src/test/java/org/fedoraproject/maven/installer/IvyInstallerExclusionTest.java deleted file mode 100644 index ce7ccc8..0000000 --- a/xmvn-core/src/test/java/org/fedoraproject/maven/installer/IvyInstallerExclusionTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * Copyright (c) 2013 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.fedoraproject.maven.installer; - -import static org.custommonkey.xmlunit.XMLUnit.setIgnoreWhitespace; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.fedoraproject.maven.utils.ArtifactUtils; -import org.sonatype.aether.artifact.Artifact; -import org.sonatype.aether.util.artifact.DefaultArtifact; - -/** - * @author Mikolaj Izdebski - */ -public class IvyInstallerExclusionTest - extends AbstractInstallerTest -{ - /** - * Test installation of Ivy modules. - * - * @throws Exception - */ - public void testComponentLookup() - throws Exception - { - Path artifactPath = Paths.get( "src/test/resources/jar/empty.jar" ); - Path modelPath = Paths.get( "src/test/resources/ivy/dependency-exclusion.ivy" ); - - Artifact artifact = new DefaultArtifact( "org.apache", "hello-ivy", "jar", "1.2.3" ); - artifact = artifact.setFile( artifactPath.toFile() ); - artifact = ArtifactUtils.setRawModelPath( artifact, modelPath ); - artifact = ArtifactUtils.setEffectiveModelPath( artifact, modelPath ); - - request.addArtifact( artifact ); - - logger.info( "Added arrifact " + artifact ); - logger.info( " POM path: " + modelPath.toAbsolutePath() ); - logger.info( " JAR path: " + artifactPath.toAbsolutePath() ); - - performInstallation(); - - setIgnoreWhitespace( true ); - - assertTrue( Files.isRegularFile( installRoot.resolve( "repo/jar/hello-ivy.jar" ) ) ); - assertXmlEqual( "ivy/dependency-exclusion.ivy", "repo/raw-pom/JPP-hello-ivy.pom" ); - assertXmlEqual( "ivy/dependency-exclusion.pom", "repo/effective-pom/JPP-hello-ivy.pom" ); - - StringBuilder depmap = new StringBuilder(); - depmap.append( "" ); - depmap.append( " " ); - depmap.append( " " ); - depmap.append( " org.apache" ); - depmap.append( " hello-ivy" ); - depmap.append( " 1.2.3" ); - depmap.append( " " ); - depmap.append( " " ); - depmap.append( " JPP" ); - depmap.append( " hello-ivy" ); - depmap.append( " " ); - depmap.append( " " ); - depmap.append( " " ); - depmap.append( " UNKNOWN" ); - depmap.append( " junit" ); - depmap.append( " junit" ); - depmap.append( " UNKNOWN" ); - depmap.append( " " ); - - depmap.append( "" ); - assertXmlEqual( depmap, "depmaps/package.xml" ); - } -} diff --git a/xmvn-parent/pom.xml b/xmvn-parent/pom.xml index 9b3030b..bfa4da6 100644 --- a/xmvn-parent/pom.xml +++ b/xmvn-parent/pom.xml @@ -75,7 +75,6 @@ US-ASCII 1.13.1 - 2.3.0 1.32 2.1.1 3.0.5 @@ -195,11 +194,6 @@ maven-invoker ${mavenInvokerVersion} - - org.apache.ivy - ivy - ${ivyVersion} - -- 1.8.4.2