mirror of https://github.com/apache/archiva.git
cleanup duplicated classes used classes from model
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1299575 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6a46674535
commit
038fbdadf8
|
@ -31,6 +31,7 @@ import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
|
|||
import org.apache.archiva.checksum.ChecksumAlgorithm;
|
||||
import org.apache.archiva.checksum.ChecksummedFile;
|
||||
import org.apache.archiva.common.utils.VersionUtil;
|
||||
import org.apache.archiva.maven2.metadata.MavenMetadataReader;
|
||||
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||
import org.apache.archiva.metadata.model.ProjectMetadata;
|
||||
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
|
||||
|
@ -40,10 +41,11 @@ import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
|
|||
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
|
||||
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
|
||||
import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
|
||||
import org.apache.archiva.model.ArchivaRepositoryMetadata;
|
||||
import org.apache.archiva.model.SnapshotVersion;
|
||||
import org.apache.archiva.proxy.common.WagonFactory;
|
||||
import org.apache.archiva.reports.RepositoryProblemFacet;
|
||||
import org.apache.archiva.xml.XMLException;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.model.CiManagement;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.IssueManagement;
|
||||
|
@ -159,10 +161,10 @@ public class Maven2RepositoryStorage
|
|||
pathTranslator.toFile( basedir, namespace, projectId, projectVersion, METADATA_FILENAME );
|
||||
try
|
||||
{
|
||||
MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile );
|
||||
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
|
||||
|
||||
// re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename
|
||||
MavenRepositoryMetadata.Snapshot snapshotVersion = metadata.getSnapshotVersion();
|
||||
SnapshotVersion snapshotVersion = metadata.getSnapshotVersion();
|
||||
if ( snapshotVersion != null )
|
||||
{
|
||||
artifactVersion =
|
||||
|
@ -220,22 +222,16 @@ public class Maven2RepositoryStorage
|
|||
}
|
||||
|
||||
ModelBuildingRequest req =
|
||||
new DefaultModelBuildingRequest()
|
||||
.setProcessPlugins( false )
|
||||
.setPomFile( file )
|
||||
.setTwoPhaseBuilding( false )
|
||||
.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
|
||||
|
||||
new DefaultModelBuildingRequest().setProcessPlugins( false ).setPomFile( file ).setTwoPhaseBuilding(
|
||||
false ).setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
|
||||
|
||||
//MRM-1607. olamy this will resolve jdk profiles on the current running archiva jvm
|
||||
req.setSystemProperties( System.getProperties() );
|
||||
|
||||
|
||||
|
||||
// MRM-1411
|
||||
req.setModelResolver(
|
||||
new RepositoryModelResolver( managedRepository, pathTranslator, wagonFactory, remoteRepositories, networkProxies,
|
||||
managedRepository ) );
|
||||
new RepositoryModelResolver( managedRepository, pathTranslator, wagonFactory, remoteRepositories,
|
||||
networkProxies, managedRepository ) );
|
||||
|
||||
Model model;
|
||||
try
|
||||
|
@ -255,7 +251,7 @@ public class Maven2RepositoryStorage
|
|||
// || ( StringUtils.startsWith( problem.getMessage(), "Failed to determine Java version for profile" ) )
|
||||
// but setTwoPhaseBuilding(true) fix that
|
||||
if ( ( problem.getException() instanceof FileNotFoundException && e.getModelId() != null &&
|
||||
!e.getModelId().equals( problem.getModelId() ) ) )
|
||||
!e.getModelId().equals( problem.getModelId() ) ) )
|
||||
{
|
||||
log.warn( "The artifact's parent POM file '" + file + "' cannot be resolved. " +
|
||||
"Using defaults for project version metadata.." );
|
||||
|
@ -631,7 +627,7 @@ public class Maven2RepositoryStorage
|
|||
}
|
||||
|
||||
// if a metadata file is present, check if this is the "artifactId" directory, marking it as a project
|
||||
MavenRepositoryMetadata metadata = readMetadata( dir );
|
||||
ArchivaRepositoryMetadata metadata = readMetadata( dir );
|
||||
if ( metadata != null && dir.getName().equals( metadata.getArtifactId() ) )
|
||||
{
|
||||
return true;
|
||||
|
@ -683,7 +679,7 @@ public class Maven2RepositoryStorage
|
|||
}
|
||||
|
||||
// if a metadata file is present, check if this is the "version" directory, marking it as a project version
|
||||
MavenRepositoryMetadata metadata = readMetadata( dir );
|
||||
ArchivaRepositoryMetadata metadata = readMetadata( dir );
|
||||
if ( metadata != null && projectVersion.equals( metadata.getVersion() ) )
|
||||
{
|
||||
return true;
|
||||
|
@ -692,15 +688,15 @@ public class Maven2RepositoryStorage
|
|||
return false;
|
||||
}
|
||||
|
||||
private MavenRepositoryMetadata readMetadata( File directory )
|
||||
private ArchivaRepositoryMetadata readMetadata( File directory )
|
||||
{
|
||||
MavenRepositoryMetadata metadata = null;
|
||||
ArchivaRepositoryMetadata metadata = null;
|
||||
File metadataFile = new File( directory, METADATA_FILENAME );
|
||||
if ( metadataFile.exists() )
|
||||
{
|
||||
try
|
||||
{
|
||||
metadata = MavenRepositoryMetadataReader.read( metadataFile );
|
||||
metadata = MavenMetadataReader.read( metadataFile );
|
||||
}
|
||||
catch ( XMLException e )
|
||||
{
|
||||
|
|
|
@ -1,239 +0,0 @@
|
|||
package org.apache.archiva.metadata.repository.storage.maven2;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MavenRepositoryMetadata
|
||||
{
|
||||
private String groupId;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String version;
|
||||
|
||||
private String lastUpdated;
|
||||
|
||||
private String latestVersion;
|
||||
|
||||
private String releasedVersion;
|
||||
|
||||
private List<String> availableVersions;
|
||||
|
||||
private Snapshot snapshotVersion;
|
||||
|
||||
private List<Plugin> plugins = new ArrayList<Plugin>();
|
||||
|
||||
public List<Plugin> getPlugins()
|
||||
{
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public void setGroupId( String groupId )
|
||||
{
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public void setArtifactId( String artifactId )
|
||||
{
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public void setVersion( String version )
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public void setLastUpdated( String lastUpdated )
|
||||
{
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
public void setLatestVersion( String latestVersion )
|
||||
{
|
||||
this.latestVersion = latestVersion;
|
||||
}
|
||||
|
||||
public void setReleasedVersion( String releasedVersion )
|
||||
{
|
||||
this.releasedVersion = releasedVersion;
|
||||
}
|
||||
|
||||
public void setAvailableVersions( List<String> availableVersions )
|
||||
{
|
||||
this.availableVersions = availableVersions;
|
||||
}
|
||||
|
||||
public void setSnapshotVersion( Snapshot snapshotVersion )
|
||||
{
|
||||
this.snapshotVersion = snapshotVersion;
|
||||
}
|
||||
|
||||
public void addPlugin( Plugin plugin )
|
||||
{
|
||||
this.plugins.add( plugin );
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getLastUpdated()
|
||||
{
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
public String getLatestVersion()
|
||||
{
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
public String getReleasedVersion()
|
||||
{
|
||||
return releasedVersion;
|
||||
}
|
||||
|
||||
public List<String> getAvailableVersions()
|
||||
{
|
||||
return availableVersions;
|
||||
}
|
||||
|
||||
public Snapshot getSnapshotVersion()
|
||||
{
|
||||
return snapshotVersion;
|
||||
}
|
||||
|
||||
public static class Snapshot
|
||||
{
|
||||
private String timestamp;
|
||||
|
||||
private int buildNumber;
|
||||
|
||||
public void setTimestamp( String timestamp )
|
||||
{
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public void setBuildNumber( int buildNumber )
|
||||
{
|
||||
this.buildNumber = buildNumber;
|
||||
}
|
||||
|
||||
public int getBuildNumber()
|
||||
{
|
||||
return buildNumber;
|
||||
}
|
||||
|
||||
public String getTimestamp()
|
||||
{
|
||||
return timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Plugin
|
||||
{
|
||||
private String prefix;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String name;
|
||||
|
||||
public void setPrefix( String prefix )
|
||||
{
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public void setArtifactId( String artifactId )
|
||||
{
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPrefix()
|
||||
{
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Plugin plugin = (Plugin) o;
|
||||
|
||||
if ( !artifactId.equals( plugin.artifactId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( name != null ? !name.equals( plugin.name ) : plugin.name != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( !prefix.equals( plugin.prefix ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = prefix.hashCode();
|
||||
result = 31 * result + artifactId.hashCode();
|
||||
result = 31 * result + ( name != null ? name.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
package org.apache.archiva.metadata.repository.storage.maven2;
|
||||
|
||||
/*
|
||||
* 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.commons.lang.math.NumberUtils;
|
||||
import org.apache.archiva.xml.XMLException;
|
||||
import org.apache.archiva.xml.XMLReader;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* RepositoryMetadataReader - read maven-metadata.xml files.
|
||||
*
|
||||
* TODO: we should improve on this, ideally using the Maven standard library
|
||||
*/
|
||||
public final class MavenRepositoryMetadataReader
|
||||
{
|
||||
private MavenRepositoryMetadataReader()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and return the {@link MavenRepositoryMetadata} object from the provided xml file.
|
||||
*
|
||||
* @param metadataFile the maven-metadata.xml file to read.
|
||||
* @return the archiva repository metadata object that represents the provided file contents.
|
||||
* @throws org.apache.archiva.xml.XMLException
|
||||
*
|
||||
*/
|
||||
public static MavenRepositoryMetadata read( File metadataFile )
|
||||
throws XMLException
|
||||
{
|
||||
XMLReader xml = new XMLReader( "metadata", metadataFile );
|
||||
// invoke this to remove namespaces, see MRM-1136
|
||||
xml.removeNamespaces();
|
||||
|
||||
MavenRepositoryMetadata metadata = new MavenRepositoryMetadata();
|
||||
|
||||
metadata.setGroupId( xml.getElementText( "//metadata/groupId" ) );
|
||||
metadata.setArtifactId( xml.getElementText( "//metadata/artifactId" ) );
|
||||
metadata.setVersion( xml.getElementText( "//metadata/version" ) );
|
||||
|
||||
metadata.setLastUpdated( xml.getElementText( "//metadata/versioning/lastUpdated" ) );
|
||||
metadata.setLatestVersion( xml.getElementText( "//metadata/versioning/latest" ) );
|
||||
metadata.setReleasedVersion( xml.getElementText( "//metadata/versioning/release" ) );
|
||||
metadata.setAvailableVersions( xml.getElementListText( "//metadata/versioning/versions/version" ) );
|
||||
|
||||
Element snapshotElem = xml.getElement( "//metadata/versioning/snapshot" );
|
||||
if ( snapshotElem != null )
|
||||
{
|
||||
MavenRepositoryMetadata.Snapshot snapshot = new MavenRepositoryMetadata.Snapshot();
|
||||
snapshot.setTimestamp( snapshotElem.elementTextTrim( "timestamp" ) );
|
||||
String tmp = snapshotElem.elementTextTrim( "buildNumber" );
|
||||
if ( NumberUtils.isNumber( tmp ) )
|
||||
{
|
||||
snapshot.setBuildNumber( NumberUtils.toInt( tmp ) );
|
||||
}
|
||||
metadata.setSnapshotVersion( snapshot );
|
||||
}
|
||||
|
||||
for ( Element plugin : xml.getElementList( "//metadata/plugins/plugin" ) )
|
||||
{
|
||||
MavenRepositoryMetadata.Plugin p = new MavenRepositoryMetadata.Plugin();
|
||||
p.setPrefix( plugin.elementTextTrim( "prefix" ) );
|
||||
p.setArtifactId( plugin.elementTextTrim( "artifactId" ) );
|
||||
p.setName( plugin.elementTextTrim( "name" ) );
|
||||
metadata.addPlugin( p );
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
}
|
|
@ -229,10 +229,10 @@ public class RepositoryModelResolver
|
|||
|
||||
log.debug( "Successfully downloaded metadata." );
|
||||
|
||||
MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( tmpMetadataResource );
|
||||
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( tmpMetadataResource );
|
||||
|
||||
// re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename
|
||||
MavenRepositoryMetadata.Snapshot snapshotVersion = metadata.getSnapshotVersion();
|
||||
SnapshotVersion snapshotVersion = metadata.getSnapshotVersion();
|
||||
String timestampVersion = version;
|
||||
if ( snapshotVersion != null )
|
||||
{
|
||||
|
|
|
@ -20,6 +20,9 @@ package org.apache.archiva.metadata.repository.storage.maven2;
|
|||
*/
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.archiva.maven2.metadata.MavenMetadataReader;
|
||||
import org.apache.archiva.model.ArchivaRepositoryMetadata;
|
||||
import org.apache.archiva.model.Plugin;
|
||||
import org.apache.archiva.xml.XMLException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -46,7 +49,7 @@ public class MavenRepositoryMetadataReaderTest
|
|||
{
|
||||
File metadataFile = new File( defaultRepoDir, "org/apache/maven/plugins/maven-metadata.xml" );
|
||||
|
||||
MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile );
|
||||
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
|
||||
|
||||
assertNotNull( metadata );
|
||||
assertEquals( "org.apache.maven.plugins", metadata.getGroupId() );
|
||||
|
@ -57,17 +60,17 @@ public class MavenRepositoryMetadataReaderTest
|
|||
assertNull( metadata.getSnapshotVersion() );
|
||||
assertNull( metadata.getLastUpdated() );
|
||||
|
||||
MavenRepositoryMetadata.Plugin cleanPlugin = new MavenRepositoryMetadata.Plugin();
|
||||
Plugin cleanPlugin = new Plugin();
|
||||
cleanPlugin.setPrefix( "clean" );
|
||||
cleanPlugin.setArtifactId( "maven-clean-plugin" );
|
||||
cleanPlugin.setName( "Maven Clean Plugin" );
|
||||
|
||||
MavenRepositoryMetadata.Plugin compilerPlugin = new MavenRepositoryMetadata.Plugin();
|
||||
Plugin compilerPlugin = new Plugin();
|
||||
compilerPlugin.setPrefix( "compiler" );
|
||||
compilerPlugin.setArtifactId( "maven-compiler-plugin" );
|
||||
compilerPlugin.setName( "Maven Compiler Plugin" );
|
||||
|
||||
MavenRepositoryMetadata.Plugin surefirePlugin = new MavenRepositoryMetadata.Plugin();
|
||||
Plugin surefirePlugin = new Plugin();
|
||||
surefirePlugin.setPrefix( "surefire" );
|
||||
surefirePlugin.setArtifactId( "maven-surefire-plugin" );
|
||||
surefirePlugin.setName( "Maven Surefire Plugin" );
|
||||
|
@ -81,7 +84,7 @@ public class MavenRepositoryMetadataReaderTest
|
|||
{
|
||||
File metadataFile = new File( defaultRepoDir, "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
|
||||
|
||||
MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile );
|
||||
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
|
||||
|
||||
assertNotNull( metadata );
|
||||
assertEquals( "org.apache.maven.shared", metadata.getGroupId() );
|
||||
|
@ -99,7 +102,7 @@ public class MavenRepositoryMetadataReaderTest
|
|||
{
|
||||
File metadataFile = new File( defaultRepoDir, "org/apache/apache/5-SNAPSHOT/maven-metadata.xml" );
|
||||
|
||||
MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile );
|
||||
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
|
||||
|
||||
assertNotNull( metadata );
|
||||
assertEquals( "org.apache", metadata.getGroupId() );
|
||||
|
|
Loading…
Reference in New Issue