Ver código fonte

[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
tags/archiva-1.4-M1
Brett Porter 14 anos atrás
pai
commit
3529172859

+ 25
- 0
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacetFactory.java Ver arquivo

@@ -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();
}

+ 4
- 2
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionFacet.java Ver arquivo

@@ -1,7 +1,5 @@
package org.apache.archiva.metadata.model;

import java.util.Map;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -21,9 +19,13 @@ import java.util.Map;
* under the License.
*/

import java.util.Map;

public interface ProjectVersionFacet
{
String getFacetId();

Map<String, String> toProperties();

void fromProperties( Map<String, String> properties );
}

+ 23
- 7
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java Ver arquivo

@@ -84,16 +84,32 @@ public class MavenProjectFacet

public Map<String, String> toProperties()
{
Map<String, String> properties = new HashMap<String,String>();
properties.put( getFacetId() + ":groupId", groupId );
properties.put( getFacetId() + ":artifactId", artifactId );
properties.put( getFacetId() + ":packaging", packaging );
HashMap<String, String> properties = new HashMap<String, String>();
properties.put( FACET_ID + ":groupId", groupId );
properties.put( FACET_ID + ":artifactId", artifactId );
properties.put( FACET_ID + ":packaging", packaging );
if ( parent != null )
{
properties.put( getFacetId() + ":parent.groupId", parent.getGroupId() );
properties.put( getFacetId() + ":parent.artifactId", parent.getArtifactId() );
properties.put( getFacetId() + ":parent.version", parent.getVersion() );
properties.put( FACET_ID + ":parent.groupId", parent.getGroupId() );
properties.put( FACET_ID + ":parent.artifactId", parent.getArtifactId() );
properties.put( FACET_ID + ":parent.version", parent.getVersion() );
}
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;
}
}
}

+ 35
- 0
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java Ver arquivo

@@ -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();
}
}

+ 4
- 0
archiva-modules/plugins/metadata-repository-file/pom.xml Ver arquivo

@@ -36,5 +36,9 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
</project>

+ 30
- 3
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java Ver arquivo

@@ -26,6 +26,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.IssueManagement;
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.ProjectMetadata;
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.repository.MetadataRepository;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @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" );

/**
* @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 )
{
// 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( "," ) )
{
// TODO: we need a factory for the facets here
// call fromProperties( properties )
// versionMetadata.addFacet( );
MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
if ( factory == null )
{
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() )

Carregando…
Cancelar
Salvar