mirror of https://github.com/apache/archiva.git
[MRM-1282] support storing facet content in the file metadata repository
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884372 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9062810001
commit
3529172859
|
@ -0,0 +1,25 @@
|
||||||
|
package org.apache.archiva.metadata.model;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface MetadataFacetFactory
|
||||||
|
{
|
||||||
|
ProjectVersionFacet createProjectVersionFacet();
|
||||||
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
package org.apache.archiva.metadata.model;
|
package org.apache.archiva.metadata.model;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
@ -21,9 +19,13 @@ import java.util.Map;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface ProjectVersionFacet
|
public interface ProjectVersionFacet
|
||||||
{
|
{
|
||||||
String getFacetId();
|
String getFacetId();
|
||||||
|
|
||||||
Map<String, String> toProperties();
|
Map<String, String> toProperties();
|
||||||
|
|
||||||
|
void fromProperties( Map<String, String> properties );
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,16 +84,32 @@ public class MavenProjectFacet
|
||||||
|
|
||||||
public Map<String, String> toProperties()
|
public Map<String, String> toProperties()
|
||||||
{
|
{
|
||||||
Map<String, String> properties = new HashMap<String,String>();
|
HashMap<String, String> properties = new HashMap<String, String>();
|
||||||
properties.put( getFacetId() + ":groupId", groupId );
|
properties.put( FACET_ID + ":groupId", groupId );
|
||||||
properties.put( getFacetId() + ":artifactId", artifactId );
|
properties.put( FACET_ID + ":artifactId", artifactId );
|
||||||
properties.put( getFacetId() + ":packaging", packaging );
|
properties.put( FACET_ID + ":packaging", packaging );
|
||||||
if ( parent != null )
|
if ( parent != null )
|
||||||
{
|
{
|
||||||
properties.put( getFacetId() + ":parent.groupId", parent.getGroupId() );
|
properties.put( FACET_ID + ":parent.groupId", parent.getGroupId() );
|
||||||
properties.put( getFacetId() + ":parent.artifactId", parent.getArtifactId() );
|
properties.put( FACET_ID + ":parent.artifactId", parent.getArtifactId() );
|
||||||
properties.put( getFacetId() + ":parent.version", parent.getVersion() );
|
properties.put( FACET_ID + ":parent.version", parent.getVersion() );
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fromProperties( Map<String, String> properties )
|
||||||
|
{
|
||||||
|
groupId = properties.get( FACET_ID + ":groupId" );
|
||||||
|
artifactId = properties.get( FACET_ID + ":artifactId" );
|
||||||
|
packaging = properties.get( FACET_ID + ":packaging" );
|
||||||
|
String parentArtifactId = properties.get( FACET_ID + ":parent.artifactId" );
|
||||||
|
if ( parentArtifactId != null )
|
||||||
|
{
|
||||||
|
MavenProjectParent parent = new MavenProjectParent();
|
||||||
|
parent.setGroupId( properties.get( FACET_ID + ":parent.groupId" ) );
|
||||||
|
parent.setArtifactId( parentArtifactId );
|
||||||
|
parent.setVersion( properties.get( FACET_ID + ":parent.version" ) );
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
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.archiva.metadata.model.MetadataFacetFactory;
|
||||||
|
import org.apache.archiva.metadata.model.ProjectVersionFacet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.storage.maven2"
|
||||||
|
*/
|
||||||
|
public class MavenProjectFacetFactory
|
||||||
|
implements MetadataFacetFactory
|
||||||
|
{
|
||||||
|
public ProjectVersionFacet createProjectVersionFacet()
|
||||||
|
{
|
||||||
|
return new MavenProjectFacet();
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,5 +36,9 @@
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -34,6 +35,7 @@ import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||||
import org.apache.archiva.metadata.model.CiManagement;
|
import org.apache.archiva.metadata.model.CiManagement;
|
||||||
import org.apache.archiva.metadata.model.IssueManagement;
|
import org.apache.archiva.metadata.model.IssueManagement;
|
||||||
import org.apache.archiva.metadata.model.License;
|
import org.apache.archiva.metadata.model.License;
|
||||||
|
import org.apache.archiva.metadata.model.MetadataFacetFactory;
|
||||||
import org.apache.archiva.metadata.model.Organization;
|
import org.apache.archiva.metadata.model.Organization;
|
||||||
import org.apache.archiva.metadata.model.ProjectMetadata;
|
import org.apache.archiva.metadata.model.ProjectMetadata;
|
||||||
import org.apache.archiva.metadata.model.ProjectVersionFacet;
|
import org.apache.archiva.metadata.model.ProjectVersionFacet;
|
||||||
|
@ -41,6 +43,8 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata;
|
||||||
import org.apache.archiva.metadata.model.Scm;
|
import org.apache.archiva.metadata.model.Scm;
|
||||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @plexus.component role="org.apache.archiva.metadata.repository.MetadataRepository"
|
* @plexus.component role="org.apache.archiva.metadata.repository.MetadataRepository"
|
||||||
|
@ -55,6 +59,13 @@ public class FileMetadataRepository
|
||||||
*/
|
*/
|
||||||
private File directory = new File( System.getProperty( "user.home" ), ".archiva-metadata" );
|
private File directory = new File( System.getProperty( "user.home" ), ".archiva-metadata" );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @plexus.requirement role="org.apache.archiva.metadata.model.MetadataFacetFactory"
|
||||||
|
*/
|
||||||
|
private Map<String, MetadataFacetFactory> metadataFacetFactories;
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger( FileMetadataRepository.class );
|
||||||
|
|
||||||
public void updateProject( String repoId, ProjectMetadata project )
|
public void updateProject( String repoId, ProjectMetadata project )
|
||||||
{
|
{
|
||||||
// TODO: this is a more braindead implementation than we would normally expect, for prototyping purposes
|
// TODO: this is a more braindead implementation than we would normally expect, for prototyping purposes
|
||||||
|
@ -287,9 +298,25 @@ public class FileMetadataRepository
|
||||||
|
|
||||||
for ( String facetId : properties.getProperty( "facetIds" ).split( "," ) )
|
for ( String facetId : properties.getProperty( "facetIds" ).split( "," ) )
|
||||||
{
|
{
|
||||||
// TODO: we need a factory for the facets here
|
MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
|
||||||
// call fromProperties( properties )
|
if ( factory == null )
|
||||||
// versionMetadata.addFacet( );
|
{
|
||||||
|
log.error( "Attempted to load unknown metadata facet: " + facetId );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProjectVersionFacet facet = factory.createProjectVersionFacet();
|
||||||
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
|
for ( String key : properties.stringPropertyNames() )
|
||||||
|
{
|
||||||
|
if ( key.startsWith( facet.getFacetId() ) )
|
||||||
|
{
|
||||||
|
map.put( key, properties.getProperty( key ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
facet.fromProperties( map );
|
||||||
|
versionMetadata.addFacet( facet );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ProjectVersionFacet facet : versionMetadata.getAllFacets() )
|
for ( ProjectVersionFacet facet : versionMetadata.getAllFacets() )
|
||||||
|
|
Loading…
Reference in New Issue