diff options
author | Brett Porter <brett@apache.org> | 2014-07-30 11:37:49 +1000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2014-07-30 11:46:30 +1000 |
commit | 8007a47a3aaa83dfa62fdc0e35d9841e3dd16e42 (patch) | |
tree | a1dbbfd520d9f1d8d9ccbf0ca4aa057fd38d952c /archiva-modules/archiva-base/archiva-artifact-converter/src/main | |
parent | 48f57dcf51dd6b102fc1b0853ec53d8617967fad (diff) | |
download | archiva-8007a47a3aaa83dfa62fdc0e35d9841e3dd16e42.tar.gz archiva-8007a47a3aaa83dfa62fdc0e35d9841e3dd16e42.zip |
merge artifact-converter into converter
Large amount of duplicated information and an unnecessary split package
caused duplicates in the produced bundle
Diffstat (limited to 'archiva-modules/archiva-base/archiva-artifact-converter/src/main')
7 files changed, 0 insertions, 1090 deletions
diff --git a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/ArtifactConversionException.java b/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/ArtifactConversionException.java deleted file mode 100644 index 0fe5dff85..000000000 --- a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/ArtifactConversionException.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.apache.archiva.converter.artifact; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * ArtifactConversionException - * - * - */ -public class ArtifactConversionException - extends Exception -{ - - public ArtifactConversionException() - { - } - - public ArtifactConversionException( String message ) - { - super( message ); - } - - public ArtifactConversionException( Throwable cause ) - { - super( cause ); - } - - public ArtifactConversionException( String message, Throwable cause ) - { - super( message, cause ); - } -} diff --git a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/ArtifactConverter.java b/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/ArtifactConverter.java deleted file mode 100644 index 842f01e7c..000000000 --- a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/ArtifactConverter.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apache.archiva.converter.artifact; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; - -import java.util.List; -import java.util.Map; - -/** - * ArtifactConverter - * - * - */ -public interface ArtifactConverter -{ - /** - * Convert an provided artifact, and place it into the destination repository. - * - * @param artifact the artifact to convert. - * @param destinationRepository the respository to send the artifact to. - * @throws ArtifactConversionException - */ - void convert( Artifact artifact, ArtifactRepository destinationRepository ) - throws ArtifactConversionException; - - /** - * Get the map of accumulated warnings for the conversion. - * - * @return the {@link Map}<{@link Artifact}, {@link String}> warning messages. - */ - Map<Artifact, List<String>> getWarnings(); - - /** - * Clear the list of warning messages. - */ - void clearWarnings(); -} diff --git a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyRepositoryLayout.java b/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyRepositoryLayout.java deleted file mode 100644 index 310123693..000000000 --- a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyRepositoryLayout.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.apache.archiva.converter.artifact; -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.metadata.ArtifactMetadata; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; - -/** - * @author jdcasey - */ -public class LegacyRepositoryLayout - implements ArtifactRepositoryLayout -{ - - private static final String PATH_SEPARATOR = "/"; - - public String getId() - { - return "legacy"; - } - - @Override - public String pathOf( Artifact artifact ) - { - ArtifactHandler artifactHandler = artifact.getArtifactHandler(); - - StringBuilder path = new StringBuilder( 128 ); - - path.append( artifact.getGroupId() ).append( '/' ); - path.append( artifactHandler.getDirectory() ).append( '/' ); - path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() ); - - if ( artifact.hasClassifier() ) - { - path.append( '-' ).append( artifact.getClassifier() ); - } - - if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 ) - { - path.append( '.' ).append( artifactHandler.getExtension() ); - } - - return path.toString(); - } - - @Override - public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) - { - return pathOfRepositoryMetadata( metadata, metadata.getLocalFilename( repository ) ); - } - - private String pathOfRepositoryMetadata( ArtifactMetadata metadata, String filename ) - { - StringBuilder path = new StringBuilder( 128 ); - - path.append( metadata.getGroupId() ).append( PATH_SEPARATOR ).append( "poms" ).append( PATH_SEPARATOR ); - - path.append( filename ); - - return path.toString(); - } - - @Override - public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata ) - { - return pathOfRepositoryMetadata( metadata, metadata.getRemoteFilename() ); - } - -} diff --git a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverter.java b/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverter.java deleted file mode 100644 index ba8bf2703..000000000 --- a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverter.java +++ /dev/null @@ -1,742 +0,0 @@ -package org.apache.archiva.converter.artifact; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.common.plexusbridge.DigesterUtils; -import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; -import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; -import org.apache.archiva.transaction.FileTransaction; -import org.apache.archiva.transaction.TransactionException; -import org.apache.commons.io.FileUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Metadata; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Snapshot; -import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Versioning; -import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; -import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; -import org.apache.maven.model.DistributionManagement; -import org.apache.maven.model.Model; -import org.apache.maven.model.Relocation; -import org.apache.maven.model.converter.ModelConverter; -import org.apache.maven.model.converter.PomTranslationException; -import org.apache.maven.model.io.xpp3.MavenXpp3Writer; -import org.codehaus.plexus.digest.Digester; -import org.codehaus.plexus.digest.DigesterException; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import java.io.File; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.regex.Matcher; - -/** - * LegacyToDefaultConverter - */ -@Service("artifactConverter#legacy-to-default") -public class LegacyToDefaultConverter - implements ArtifactConverter -{ - /** - * {@link List}<{@link Digester} - */ - private List<? extends Digester> digesters; - - @Inject - private PlexusSisuBridge plexusSisuBridge; - - @Inject - private DigesterUtils digesterUtils; - - private ModelConverter translator; - - private ArtifactFactory artifactFactory; - - private ArtifactHandlerManager artifactHandlerManager; - - private boolean force; - - private boolean dryrun; - - private Map<Artifact, List<String>> warnings = new HashMap<>(); - - @PostConstruct - public void initialize() - throws PlexusSisuBridgeException - { - this.digesters = digesterUtils.getAllDigesters(); - translator = plexusSisuBridge.lookup( ModelConverter.class ); - artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class ); - artifactHandlerManager = plexusSisuBridge.lookup( ArtifactHandlerManager.class ); - } - - @Override - public void convert( Artifact artifact, ArtifactRepository targetRepository ) - throws ArtifactConversionException - { - if ( artifact.getRepository().getUrl().equals( targetRepository.getUrl() ) ) - { - throw new ArtifactConversionException( Messages.getString( "exception.repositories.match" ) ); //$NON-NLS-1$ - } - - if ( !validateMetadata( artifact ) ) - { - addWarning( artifact, Messages.getString( "unable.to.validate.metadata" ) ); //$NON-NLS-1$ - return; - } - - FileTransaction transaction = new FileTransaction(); - - if ( !copyPom( artifact, targetRepository, transaction ) ) - { - addWarning( artifact, Messages.getString( "unable.to.copy.pom" ) ); //$NON-NLS-1$ - return; - } - - if ( !copyArtifact( artifact, targetRepository, transaction ) ) - { - addWarning( artifact, Messages.getString( "unable.to.copy.artifact" ) ); //$NON-NLS-1$ - return; - } - - Metadata metadata = createBaseMetadata( artifact ); - Versioning versioning = new Versioning(); - versioning.addVersion( artifact.getBaseVersion() ); - metadata.setVersioning( versioning ); - updateMetadata( new ArtifactRepositoryMetadata( artifact ), targetRepository, metadata, transaction ); - - metadata = createBaseMetadata( artifact ); - metadata.setVersion( artifact.getBaseVersion() ); - versioning = new Versioning(); - - Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() ); - if ( matcher.matches() ) - { - Snapshot snapshot = new Snapshot(); - snapshot.setBuildNumber( Integer.parseInt( matcher.group( 3 ) ) ); - snapshot.setTimestamp( matcher.group( 2 ) ); - versioning.setSnapshot( snapshot ); - } - - // TODO: merge latest/release/snapshot from source instead - metadata.setVersioning( versioning ); - updateMetadata( new SnapshotArtifactRepositoryMetadata( artifact ), targetRepository, metadata, transaction ); - - if ( !dryrun ) - { - try - { - transaction.commit(); - } - catch ( TransactionException e ) - { - throw new ArtifactConversionException( Messages.getString( "transaction.failure", e.getMessage() ), - e ); //$NON-NLS-1$ - } - } - } - - @SuppressWarnings("unchecked") - private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction ) - throws ArtifactConversionException - { - Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion() ); - pom.setBaseVersion( artifact.getBaseVersion() ); - ArtifactRepository repository = artifact.getRepository(); - File file = new File( repository.getBasedir(), repository.pathOf( pom ) ); - - boolean result = true; - if ( file.exists() ) - { - File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pom ) ); - - String contents = null; - boolean checksumsValid = false; - try - { - if ( testChecksums( artifact, file ) ) - { - checksumsValid = true; - } - - // Even if the checksums for the POM are invalid we should still convert the POM - contents = FileUtils.readFileToString( file, Charset.defaultCharset() ); - } - catch ( IOException e ) - { - throw new ArtifactConversionException( - Messages.getString( "unable.to.read.source.pom", e.getMessage() ), e ); //$NON-NLS-1$ - } - - if ( checksumsValid && contents.indexOf( "modelVersion" ) >= 0 ) //$NON-NLS-1$ - { - // v4 POM - try - { - boolean matching = false; - if ( !force && targetFile.exists() ) - { - String targetContents = FileUtils.readFileToString( targetFile, Charset.defaultCharset() ); - matching = targetContents.equals( contents ); - } - if ( force || !matching ) - { - transaction.createFile( contents, targetFile, digesters ); - } - } - catch ( IOException e ) - { - throw new ArtifactConversionException( - Messages.getString( "unable.to.write.target.pom", e.getMessage() ), e ); //$NON-NLS-1$ - } - } - else - { - // v3 POM - try (StringReader stringReader = new StringReader( contents )) - { - - try (StringWriter writer = new StringWriter()) - { - org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader v3Reader = - new org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader(); - org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( stringReader ); - - if ( doRelocation( artifact, v3Model, targetRepository, transaction ) ) - { - Artifact relocatedPom = - artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion() ); - targetFile = - new File( targetRepository.getBasedir(), targetRepository.pathOf( relocatedPom ) ); - } - - Model v4Model = translator.translate( v3Model ); - - translator.validateV4Basics( v4Model, v3Model.getGroupId(), v3Model.getArtifactId(), - v3Model.getVersion(), v3Model.getPackage() ); - - MavenXpp3Writer xpp3Writer = new MavenXpp3Writer(); - xpp3Writer.write( writer, v4Model ); - - transaction.createFile( writer.toString(), targetFile, digesters ); - - List<String> warnings = translator.getWarnings(); - - for ( String message : warnings ) - { - addWarning( artifact, message ); - } - } - catch ( XmlPullParserException e ) - { - addWarning( artifact, - Messages.getString( "invalid.source.pom", e.getMessage() ) ); //$NON-NLS-1$ - result = false; - } - catch ( IOException e ) - { - throw new ArtifactConversionException( Messages.getString( "unable.to.write.converted.pom" ), - e ); //$NON-NLS-1$ - } - catch ( PomTranslationException e ) - { - addWarning( artifact, - Messages.getString( "invalid.source.pom", e.getMessage() ) ); //$NON-NLS-1$ - result = false; - } - } - } - } - else - { - addWarning( artifact, Messages.getString( "warning.missing.pom" ) ); //$NON-NLS-1$ - } - return result; - } - - private boolean testChecksums( Artifact artifact, File file ) - throws IOException - { - boolean result = true; - for ( Digester digester : digesters ) - { - result &= verifyChecksum( file, file.getName() + "." + getDigesterFileExtension( digester ), digester, - //$NON-NLS-1$ - artifact, - "failure.incorrect." + getDigesterFileExtension( digester ) ); //$NON-NLS-1$ - } - return result; - } - - private boolean verifyChecksum( File file, String fileName, Digester digester, Artifact artifact, String key ) - throws IOException - { - boolean result = true; - - File checksumFile = new File( file.getParentFile(), fileName ); - if ( checksumFile.exists() ) - { - String checksum = FileUtils.readFileToString( checksumFile, Charset.defaultCharset() ); - try - { - digester.verify( file, checksum ); - } - catch ( DigesterException e ) - { - addWarning( artifact, Messages.getString( key ) ); - result = false; - } - } - return result; - } - - /** - * File extension for checksums - * TODO should be moved to plexus-digester ? - */ - private String getDigesterFileExtension( Digester digester ) - { - return digester.getAlgorithm().toLowerCase().replaceAll( "-", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - } - - private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction ) - throws ArtifactConversionException - { - File sourceFile = artifact.getFile(); - - if ( sourceFile.getAbsolutePath().indexOf( "/plugins/" ) > -1 ) //$NON-NLS-1$ - { - artifact.setArtifactHandler( artifactHandlerManager.getArtifactHandler( "maven-plugin" ) ); //$NON-NLS-1$ - } - - File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - - boolean result = true; - try - { - boolean matching = false; - if ( !force && targetFile.exists() ) - { - matching = FileUtils.contentEquals( sourceFile, targetFile ); - if ( !matching ) - { - addWarning( artifact, Messages.getString( "failure.target.already.exists" ) ); //$NON-NLS-1$ - result = false; - } - } - if ( result ) - { - if ( force || !matching ) - { - if ( testChecksums( artifact, sourceFile ) ) - { - transaction.copyFile( sourceFile, targetFile, digesters ); - } - else - { - result = false; - } - } - } - } - catch ( IOException e ) - { - throw new ArtifactConversionException( Messages.getString( "error.copying.artifact" ), e ); //$NON-NLS-1$ - } - return result; - } - - private Metadata createBaseMetadata( Artifact artifact ) - { - Metadata metadata = new Metadata(); - metadata.setArtifactId( artifact.getArtifactId() ); - metadata.setGroupId( artifact.getGroupId() ); - return metadata; - } - - private Metadata readMetadata( File file ) - throws ArtifactConversionException - { - MetadataXpp3Reader reader = new MetadataXpp3Reader(); - - try (Reader fileReader = Files.newBufferedReader( file.toPath(), Charset.defaultCharset() )) - { - return reader.read( fileReader ); - } - catch ( IOException | XmlPullParserException e ) - { - throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), - e ); //$NON-NLS-1$ - } - } - - private boolean validateMetadata( Artifact artifact ) - throws ArtifactConversionException - { - ArtifactRepository repository = artifact.getRepository(); - - boolean result = true; - - RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact ); - File file = - new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) ); - if ( file.exists() ) - { - Metadata metadata = readMetadata( file ); - result = validateMetadata( metadata, repositoryMetadata, artifact ); - } - - repositoryMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); - file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) ); - if ( file.exists() ) - { - Metadata metadata = readMetadata( file ); - result = result && validateMetadata( metadata, repositoryMetadata, artifact ); - } - - return result; - } - - @SuppressWarnings("unchecked") - private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact ) - { - String groupIdKey; - String artifactIdKey = null; - String snapshotKey = null; - String versionKey = null; - String versionsKey = null; - - if ( repositoryMetadata.storedInGroupDirectory() ) - { - groupIdKey = "failure.incorrect.groupMetadata.groupId"; //$NON-NLS-1$ - } - else if ( repositoryMetadata.storedInArtifactVersionDirectory() ) - { - groupIdKey = "failure.incorrect.snapshotMetadata.groupId"; //$NON-NLS-1$ - artifactIdKey = "failure.incorrect.snapshotMetadata.artifactId"; //$NON-NLS-1$ - versionKey = "failure.incorrect.snapshotMetadata.version"; //$NON-NLS-1$ - snapshotKey = "failure.incorrect.snapshotMetadata.snapshot"; //$NON-NLS-1$ - } - else - { - groupIdKey = "failure.incorrect.artifactMetadata.groupId"; //$NON-NLS-1$ - artifactIdKey = "failure.incorrect.artifactMetadata.artifactId"; //$NON-NLS-1$ - versionsKey = "failure.incorrect.artifactMetadata.versions"; //$NON-NLS-1$ - } - - boolean result = true; - - if ( metadata.getGroupId() == null || !metadata.getGroupId().equals( artifact.getGroupId() ) ) - { - addWarning( artifact, Messages.getString( groupIdKey ) ); - result = false; - } - if ( !repositoryMetadata.storedInGroupDirectory() ) - { - if ( metadata.getGroupId() == null || !metadata.getArtifactId().equals( artifact.getArtifactId() ) ) - { - addWarning( artifact, Messages.getString( artifactIdKey ) ); - result = false; - } - if ( !repositoryMetadata.storedInArtifactVersionDirectory() ) - { - // artifact metadata - - boolean foundVersion = false; - if ( metadata.getVersioning() != null ) - { - for ( String version : (List<String>) metadata.getVersioning().getVersions() ) - { - if ( version.equals( artifact.getBaseVersion() ) ) - { - foundVersion = true; - break; - } - } - } - - if ( !foundVersion ) - { - addWarning( artifact, Messages.getString( versionsKey ) ); - result = false; - } - } - else - { - // snapshot metadata - if ( !artifact.getBaseVersion().equals( metadata.getVersion() ) ) - { - addWarning( artifact, Messages.getString( versionKey ) ); - result = false; - } - - if ( artifact.isSnapshot() ) - { - Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() ); - if ( matcher.matches() ) - { - boolean correct = false; - if ( metadata.getVersioning() != null && metadata.getVersioning().getSnapshot() != null ) - { - Snapshot snapshot = metadata.getVersioning().getSnapshot(); - int build = Integer.parseInt( matcher.group( 3 ) ); - String ts = matcher.group( 2 ); - if ( build == snapshot.getBuildNumber() && ts.equals( snapshot.getTimestamp() ) ) - { - correct = true; - } - } - - if ( !correct ) - { - addWarning( artifact, Messages.getString( snapshotKey ) ); - result = false; - } - } - } - } - } - return result; - } - - private void updateMetadata( RepositoryMetadata artifactMetadata, ArtifactRepository targetRepository, - Metadata newMetadata, FileTransaction transaction ) - throws ArtifactConversionException - { - File file = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); - - Metadata metadata; - boolean changed; - - if ( file.exists() ) - { - metadata = readMetadata( file ); - changed = metadata.merge( newMetadata ); - } - else - { - changed = true; - metadata = newMetadata; - } - - if ( changed ) - { - - try (StringWriter writer = new StringWriter()) - { - MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer(); - - mappingWriter.write( writer, metadata ); - - transaction.createFile( writer.toString(), file, digesters ); - } - catch ( IOException e ) - { - throw new ArtifactConversionException( Messages.getString( "error.writing.target.metadata" ), - e ); //$NON-NLS-1$ - } - } - } - - private boolean doRelocation( Artifact artifact, org.apache.maven.model.v3_0_0.Model v3Model, - ArtifactRepository repository, FileTransaction transaction ) - throws IOException - { - Properties properties = v3Model.getProperties(); - if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" ) - //$NON-NLS-1$ //$NON-NLS-2$ - || properties.containsKey( "relocated.version" ) ) //$NON-NLS-1$ - { - String newGroupId = properties.getProperty( "relocated.groupId", v3Model.getGroupId() ); //$NON-NLS-1$ - properties.remove( "relocated.groupId" ); //$NON-NLS-1$ - - String newArtifactId = - properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() ); //$NON-NLS-1$ - properties.remove( "relocated.artifactId" ); //$NON-NLS-1$ - - String newVersion = properties.getProperty( "relocated.version", v3Model.getVersion() ); //$NON-NLS-1$ - properties.remove( "relocated.version" ); //$NON-NLS-1$ - - String message = properties.getProperty( "relocated.message", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - properties.remove( "relocated.message" ); //$NON-NLS-1$ - - if ( properties.isEmpty() ) - { - v3Model.setProperties( null ); - } - - writeRelocationPom( v3Model.getGroupId(), v3Model.getArtifactId(), v3Model.getVersion(), newGroupId, - newArtifactId, newVersion, message, repository, transaction ); - - v3Model.setGroupId( newGroupId ); - v3Model.setArtifactId( newArtifactId ); - v3Model.setVersion( newVersion ); - - artifact.setGroupId( newGroupId ); - artifact.setArtifactId( newArtifactId ); - artifact.setVersion( newVersion ); - - return true; - } - else - { - return false; - } - } - - private void writeRelocationPom( String groupId, String artifactId, String version, String newGroupId, - String newArtifactId, String newVersion, String message, - ArtifactRepository repository, FileTransaction transaction ) - throws IOException - { - Model pom = new Model(); - pom.setGroupId( groupId ); - pom.setArtifactId( artifactId ); - pom.setVersion( version ); - - DistributionManagement dMngt = new DistributionManagement(); - - Relocation relocation = new Relocation(); - relocation.setGroupId( newGroupId ); - relocation.setArtifactId( newArtifactId ); - relocation.setVersion( newVersion ); - if ( message != null && message.length() > 0 ) - { - relocation.setMessage( message ); - } - - dMngt.setRelocation( relocation ); - - pom.setDistributionManagement( dMngt ); - - Artifact artifact = artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" ); //$NON-NLS-1$ - File pomFile = new File( repository.getBasedir(), repository.pathOf( artifact ) ); - - StringWriter strWriter = new StringWriter(); - MavenXpp3Writer pomWriter = new MavenXpp3Writer(); - pomWriter.write( strWriter, pom ); - - transaction.createFile( strWriter.toString(), pomFile, digesters ); - } - - private void addWarning( Artifact artifact, String message ) - { - List<String> messages = warnings.get( artifact ); - if ( messages == null ) - { - messages = new ArrayList<>( 1 ); - } - messages.add( message ); - warnings.put( artifact, messages ); - } - - @Override - public void clearWarnings() - { - warnings.clear(); - } - - @Override - public Map<Artifact, List<String>> getWarnings() - { - return warnings; - } - - - public List<? extends Digester> getDigesters() - { - return digesters; - } - - public void setDigesters( List<Digester> digesters ) - { - this.digesters = digesters; - } - - public ModelConverter getTranslator() - { - return translator; - } - - public void setTranslator( ModelConverter translator ) - { - this.translator = translator; - } - - public ArtifactFactory getArtifactFactory() - { - return artifactFactory; - } - - public void setArtifactFactory( ArtifactFactory artifactFactory ) - { - this.artifactFactory = artifactFactory; - } - - public ArtifactHandlerManager getArtifactHandlerManager() - { - return artifactHandlerManager; - } - - public void setArtifactHandlerManager( ArtifactHandlerManager artifactHandlerManager ) - { - this.artifactHandlerManager = artifactHandlerManager; - } - - public boolean isForce() - { - return force; - } - - public void setForce( boolean force ) - { - this.force = force; - } - - public boolean isDryrun() - { - return dryrun; - } - - public void setDryrun( boolean dryrun ) - { - this.dryrun = dryrun; - } -} diff --git a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/Messages.java b/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/Messages.java deleted file mode 100644 index 0cec0fee7..000000000 --- a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/archiva/converter/artifact/Messages.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.apache.archiva.converter.artifact; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/** - * Messages - * - * - */ -public class Messages -{ - private static final String BUNDLE_NAME = "org.apache.archiva.converter.artifact.messages"; //$NON-NLS-1$ - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME ); - - private Messages() - { - // no op - } - - public static String getString( String key ) - { - try - { - return RESOURCE_BUNDLE.getString( key ); - } - catch ( MissingResourceException e ) - { - return '!' + key + '!'; - } - } - - public static String getString( String key, Object argument ) - { - return getString( key, new Object[] { argument } ); - } - - public static String getString( String key, Object arguments[] ) - { - try - { - String pattern = RESOURCE_BUNDLE.getString( key ); - return MessageFormat.format( pattern, arguments ); - } - catch ( MissingResourceException e ) - { - return '!' + key + '!'; - } - } -} diff --git a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-artifact-converter/src/main/resources/META-INF/spring-context.xml deleted file mode 100644 index fcc10b5a3..000000000 --- a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/resources/META-INF/spring-context.xml +++ /dev/null @@ -1,33 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:context="http://www.springframework.org/schema/context" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-3.0.xsd - http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-3.0.xsd" - default-lazy-init="true"> - - <context:annotation-config/> - <context:component-scan base-package="org.apache.archiva.converter.artifact"/> - -</beans>
\ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/resources/org/apache/archiva/converter/artifact/messages.properties b/archiva-modules/archiva-base/archiva-artifact-converter/src/main/resources/org/apache/archiva/converter/artifact/messages.properties deleted file mode 100644 index 5e5bc6dd3..000000000 --- a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/resources/org/apache/archiva/converter/artifact/messages.properties +++ /dev/null @@ -1,51 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -unable.to.validate.metadata=Unable to validate metadata -unable.to.copy.pom=Unable to copy pom. -unable.to.copy.artifact=Unable to copy artifact -unable.to.read.source.pom=Unable to read source POM: {0} -unable.to.write.target.pom=Unable to write target POM: {0} -unable.to.write.converted.pom=Unable to write converted POM - - -exception.repositories.match=Source repository of artifact, and target repository are the same. No conversion needed. -transaction.failure=Transaction failure: {0} -invalid.source.pom=Invalid source pom: {0} - -warning.missing.pom=The artifact had no POM in the source repository. - -error.copying.artifact=Error copying artifact -error.reading.target.metadata=Error reading target metadata -error.writing.target.metadata=Error writing target metadata - -failure.target.already.exists=The artifact could not be converted because it already exists. -failure.incorrect.groupMetadata.groupId=The group ID in the source group metadata is incorrect. - -failure.incorrect.artifactMetadata.artifactId=The artifact ID in the source artifact metadata is incorrect. -failure.incorrect.artifactMetadata.groupId=The group ID in the source artifact metadata is incorrect. -failure.incorrect.artifactMetadata.versions=The version list in the source artifact metadata is incorrect. - -failure.incorrect.snapshotMetadata.artifactId=The artifact ID in the source artifact version metadata is incorrect. -failure.incorrect.snapshotMetadata.groupId=The group ID in the source artifact version metadata is incorrect. -failure.incorrect.snapshotMetadata.version=The version in the source artifact version metadata is incorrect. -failure.incorrect.snapshotMetadata.snapshot=The snapshot information in the source artifact version metadata is incorrect. - -failure.incorrect.md5=The MD5 checksum value was incorrect. -failure.incorrect.sha1=The SHA1 checksum value was incorrect. |