mirror of
https://github.com/apache/archiva.git
synced 2025-02-21 01:15:08 +00:00
[MRM-1282] introduce a metadata resolver API that will allow just-in-time addition to the content repository and the ability to introduce proxying
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@883936 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
627ad47211
commit
d9e22fa778
@ -25,7 +25,7 @@
|
||||
|
||||
import com.opensymphony.xwork2.Validateable;
|
||||
import org.apache.archiva.metadata.model.ProjectBuildMetadata;
|
||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||
import org.apache.archiva.metadata.repository.MetadataResolver;
|
||||
import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
||||
@ -71,7 +71,7 @@ public class ShowArtifactAction
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private MetadataRepository metadataRepository;
|
||||
private MetadataResolver metadataResolver;
|
||||
|
||||
/* .\ Exposed Output Objects \.__________________________________ */
|
||||
|
||||
@ -112,16 +112,16 @@ public String artifact()
|
||||
{
|
||||
if ( build == null )
|
||||
{
|
||||
// TODO: we don't really want the implementation being that intelligent - so another resolver to do
|
||||
// the "just-in-time" nature of picking up the metadata (if appropriate for the repository type) if not
|
||||
// found in the content repository is needed here
|
||||
build = metadataRepository.getProjectBuild( repoId, groupId, artifactId, version );
|
||||
// we don't really want the implementation being that intelligent - so another resolver to do the
|
||||
// "just-in-time" nature of picking up the metadata (if appropriate for the repository type) is used
|
||||
build = metadataResolver.getProjectBuild( repoId, groupId, artifactId, version );
|
||||
if ( build != null )
|
||||
{
|
||||
repositoryId = repoId;
|
||||
}
|
||||
}
|
||||
snapshotVersions.addAll( metadataRepository.getArtifactVersions( repoId, groupId, artifactId, version ) );
|
||||
|
||||
snapshotVersions.addAll( metadataResolver.getArtifactVersions( repoId, groupId, artifactId, version ) );
|
||||
snapshotVersions.remove( version );
|
||||
}
|
||||
|
||||
@ -365,8 +365,8 @@ public void setSnapshotVersions( List<String> snapshotVersions )
|
||||
this.snapshotVersions = snapshotVersions;
|
||||
}
|
||||
|
||||
public MetadataRepository getMetadataRepository()
|
||||
public MetadataResolver getMetadataRepository()
|
||||
{
|
||||
return metadataRepository;
|
||||
return metadataResolver;
|
||||
}
|
||||
}
|
||||
|
@ -25,33 +25,17 @@
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||
import org.apache.archiva.metadata.model.ProjectBuildMetadata;
|
||||
import org.apache.archiva.metadata.model.ProjectMetadata;
|
||||
import org.apache.archiva.metadata.repository.MetadataRepository;
|
||||
import org.apache.archiva.metadata.repository.MetadataResolver;
|
||||
|
||||
public class MemoryMetadataRepository
|
||||
implements MetadataRepository
|
||||
public class TestMetadataResolver
|
||||
implements MetadataResolver
|
||||
{
|
||||
private Map<String, ProjectBuildMetadata> projectBuilds = new HashMap<String, ProjectBuildMetadata>();
|
||||
|
||||
private Map<String, List<String>> artifactVersions = new HashMap<String, List<String>>();
|
||||
|
||||
public void updateProject( String repoId, ProjectMetadata project )
|
||||
{
|
||||
throw new UnsupportedOperationException( );
|
||||
}
|
||||
|
||||
public void updateArtifact( String repoId, String namespace, String projectId, String buildId, ArtifactMetadata artifactMeta )
|
||||
{
|
||||
throw new UnsupportedOperationException( );
|
||||
}
|
||||
|
||||
public void updateBuild( String repoId, String namespace, String projectId, ProjectBuildMetadata build )
|
||||
{
|
||||
throw new UnsupportedOperationException( );
|
||||
}
|
||||
|
||||
public ProjectMetadata getProject( String repoId, String namespace, String projectId )
|
||||
{
|
||||
ProjectMetadata metadata = new ProjectMetadata();
|
@ -30,7 +30,7 @@
|
||||
import org.apache.archiva.metadata.model.Organization;
|
||||
import org.apache.archiva.metadata.model.ProjectBuildMetadata;
|
||||
import org.apache.archiva.metadata.model.Scm;
|
||||
import org.apache.archiva.metadata.repository.memory.MemoryMetadataRepository;
|
||||
import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
|
||||
import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
|
||||
import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
|
||||
import org.apache.maven.archiva.model.ArchivaProjectModel;
|
||||
@ -102,7 +102,7 @@ public class ShowArtifactActionTest
|
||||
|
||||
private ShowArtifactAction action;
|
||||
|
||||
private MemoryMetadataRepository metadataRepository;
|
||||
private TestMetadataResolver metadataResolver;
|
||||
|
||||
public void testInstantiation()
|
||||
{
|
||||
@ -111,7 +111,7 @@ public void testInstantiation()
|
||||
|
||||
public void testGetArtifactUniqueRelease()
|
||||
{
|
||||
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
createProjectModel( TEST_VERSION ) );
|
||||
|
||||
setActionParameters();
|
||||
@ -134,9 +134,9 @@ public void testGetArtifactUniqueRelease()
|
||||
|
||||
public void testGetArtifactUniqueSnapshot()
|
||||
{
|
||||
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
createProjectModel( TEST_SNAPSHOT_VERSION ) );
|
||||
metadataRepository.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
|
||||
metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
|
||||
ALL_TEST_SNAPSHOT_VERSIONS );
|
||||
|
||||
action.setGroupId( TEST_GROUP_ID );
|
||||
@ -164,9 +164,9 @@ public void testGetArtifactUniqueSnapshot()
|
||||
|
||||
public void testGetArtifactUniqueSnapshotTimestamped()
|
||||
{
|
||||
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
createProjectModel( TEST_TS_SNAPSHOT_VERSION ) );
|
||||
metadataRepository.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION,
|
||||
metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION,
|
||||
ALL_TEST_SNAPSHOT_VERSIONS );
|
||||
|
||||
action.setGroupId( TEST_GROUP_ID );
|
||||
@ -220,7 +220,7 @@ public void testGetArtifactNoObservableRepos()
|
||||
|
||||
public void testGetArtifactNotInObservableRepos()
|
||||
{
|
||||
metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
metadataResolver.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
createProjectModel( TEST_VERSION ) );
|
||||
|
||||
setActionParameters();
|
||||
@ -235,7 +235,7 @@ public void testGetArtifactNotInObservableRepos()
|
||||
public void testGetArtifactOnlySeenInSecondObservableRepo()
|
||||
{
|
||||
setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
|
||||
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
createProjectModel( TEST_VERSION ) );
|
||||
|
||||
setActionParameters();
|
||||
@ -259,9 +259,9 @@ public void testGetArtifactOnlySeenInSecondObservableRepo()
|
||||
public void testGetArtifactSeenInBothObservableRepo()
|
||||
{
|
||||
setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
|
||||
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
createProjectModel( TEST_VERSION ) );
|
||||
metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
metadataResolver.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
createProjectModel( TEST_VERSION ) );
|
||||
|
||||
setActionParameters();
|
||||
@ -285,9 +285,9 @@ public void testGetArtifactSeenInBothObservableRepo()
|
||||
public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
|
||||
{
|
||||
setObservableRepos( Arrays.asList( TEST_REPO ) );
|
||||
metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
metadataResolver.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
createProjectModel( TEST_VERSION ) );
|
||||
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
|
||||
createProjectModel( TEST_VERSION ) );
|
||||
|
||||
setActionParameters();
|
||||
@ -437,6 +437,6 @@ protected void setUp()
|
||||
{
|
||||
super.setUp();
|
||||
action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT );
|
||||
metadataRepository = (MemoryMetadataRepository) action.getMetadataRepository();
|
||||
metadataResolver = (TestMetadataResolver) action.getMetadataRepository();
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,9 @@
|
||||
<implementation>org.apache.maven.archiva.security.UserRepositoriesStub</implementation>
|
||||
</component>
|
||||
<component>
|
||||
<role>org.apache.archiva.metadata.repository.MetadataRepository</role>
|
||||
<role>org.apache.archiva.metadata.repository.MetadataResolver</role>
|
||||
<role-hint>default</role-hint>
|
||||
<implementation>org.apache.archiva.metadata.repository.memory.MemoryMetadataRepository</implementation>
|
||||
<implementation>org.apache.archiva.metadata.repository.memory.TestMetadataResolver</implementation>
|
||||
<instantiation-strategy>per-lookup</instantiation-strategy>
|
||||
</component>
|
||||
</components>
|
||||
|
@ -0,0 +1,69 @@
|
||||
package org.apache.archiva.metadata.repository;
|
||||
|
||||
/*
|
||||
* 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.Collection;
|
||||
|
||||
import org.apache.archiva.metadata.model.ProjectBuildMetadata;
|
||||
import org.apache.archiva.metadata.model.ProjectMetadata;
|
||||
|
||||
/**
|
||||
* @plexus.component role="org.apache.archiva.metadata.repository.MetadataResolver"
|
||||
*/
|
||||
public class DefaultMetadataResolver
|
||||
implements MetadataResolver
|
||||
{
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private MetadataRepository metadataRepository;
|
||||
|
||||
/**
|
||||
* TODO: this needs to be configurable based on storage type, and availability of proxy module
|
||||
* TODO: could be a different type since we need methods to modify the storage metadata
|
||||
* @plexus.requirement role-hint="maven2"
|
||||
*/
|
||||
private MetadataResolver storageResolver;
|
||||
|
||||
public ProjectMetadata getProject( String repoId, String namespace, String projectId )
|
||||
{
|
||||
// TODO: intercept
|
||||
return metadataRepository.getProject( repoId, namespace, projectId );
|
||||
}
|
||||
|
||||
public ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId )
|
||||
{
|
||||
ProjectBuildMetadata metadata = metadataRepository.getProjectBuild( repoId, namespace, projectId, buildId );
|
||||
// TODO: do we want to detect changes as well by comparing timestamps? isProjectBuildNewerThan(updated)
|
||||
// in such cases we might also remove/update stale metadata, including adjusting plugin-based facets
|
||||
if ( metadata == null )
|
||||
{
|
||||
metadata = storageResolver.getProjectBuild( repoId, namespace, projectId, buildId );
|
||||
metadataRepository.updateBuild( repoId, namespace, projectId, metadata );
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId )
|
||||
{
|
||||
// TODO: intercept
|
||||
return metadataRepository.getArtifactVersions( repoId, namespace, projectId, buildId );
|
||||
}
|
||||
}
|
@ -19,13 +19,12 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||
import org.apache.archiva.metadata.model.ProjectBuildMetadata;
|
||||
import org.apache.archiva.metadata.model.ProjectMetadata;
|
||||
|
||||
public interface MetadataRepository
|
||||
extends MetadataResolver
|
||||
{
|
||||
/**
|
||||
* Update metadata for a particular project in the metadata repository, or create it if it does not already exist.
|
||||
@ -37,9 +36,4 @@ public interface MetadataRepository
|
||||
|
||||
void updateBuild( String repoId, String namespace, String projectId, ProjectBuildMetadata build );
|
||||
|
||||
ProjectMetadata getProject( String repoId, String namespace, String projectId );
|
||||
|
||||
ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId );
|
||||
|
||||
Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId );
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
package org.apache.archiva.metadata.repository;
|
||||
|
||||
/*
|
||||
* 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.Collection;
|
||||
|
||||
import org.apache.archiva.metadata.model.ProjectBuildMetadata;
|
||||
import org.apache.archiva.metadata.model.ProjectMetadata;
|
||||
|
||||
public interface MetadataResolver
|
||||
{
|
||||
ProjectMetadata getProject( String repoId, String namespace, String projectId );
|
||||
|
||||
ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId );
|
||||
|
||||
Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId );
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package org.apache.archiva.metadata.repository.storage;
|
||||
|
||||
/*
|
||||
* 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.io.File;
|
||||
|
||||
public interface RepositoryPathTranslator
|
||||
{
|
||||
File toFile( File basedir, String namespace, String projectId, String buildId, String filename );
|
||||
|
||||
String toPath( String namespace, String projectId, String buildId, String filename );
|
||||
}
|
@ -32,5 +32,44 @@
|
||||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>metadata-model</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>metadata-repository-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-spring</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-model-builder</artifactId>
|
||||
<version>3.0-alpha-4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>archiva-configuration</artifactId>
|
||||
<version>1.3-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- TODO: this is to override the top level dependency management - we need to rationalise these -->
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-model</artifactId>
|
||||
<version>3.0-alpha-4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
@ -0,0 +1,39 @@
|
||||
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.maven.model.Model;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelProblemCollector;
|
||||
import org.apache.maven.model.plugin.LifecycleBindingsInjector;
|
||||
|
||||
/**
|
||||
* Required as plexus-spring doesn't understand the optional = true argument added to Plexus and used here.
|
||||
*
|
||||
* @plexus.component role="org.apache.maven.model.plugin.LifecycleBindingsInjector"
|
||||
*/
|
||||
public class DummyLifecycleBindingsInjector
|
||||
implements LifecycleBindingsInjector
|
||||
{
|
||||
public void injectLifecycleBindings( Model model, ModelBuildingRequest modelBuildingRequest, ModelProblemCollector modelProblemCollector )
|
||||
{
|
||||
// left intentionally blank
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
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.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.archiva.metadata.model.ProjectBuildMetadata;
|
||||
import org.apache.archiva.metadata.model.ProjectMetadata;
|
||||
import org.apache.archiva.metadata.repository.MetadataResolver;
|
||||
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
||||
import org.apache.maven.model.building.ModelBuilder;
|
||||
import org.apache.maven.model.building.ModelBuildingException;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
|
||||
/**
|
||||
* @plexus.component role="org.apache.archiva.metadata.repository.MetadataResolver" role-hint="maven2"
|
||||
*/
|
||||
public class Maven2RepositoryMetadataResolver
|
||||
implements MetadataResolver
|
||||
{
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ModelBuilder builder;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArchivaConfiguration archivaConfiguration;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="maven2"
|
||||
*/
|
||||
private RepositoryPathTranslator pathTranslator;
|
||||
|
||||
public ProjectMetadata getProject( String repoId, String namespace, String projectId )
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId )
|
||||
{
|
||||
ManagedRepositoryConfiguration repositoryConfiguration =
|
||||
archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId );
|
||||
|
||||
File basedir = new File( repositoryConfiguration.getLocation() );
|
||||
File file = pathTranslator.toFile( basedir, namespace, projectId, buildId, projectId + "-" + buildId + ".pom" );
|
||||
|
||||
ModelBuildingRequest req = new DefaultModelBuildingRequest();
|
||||
req.setProcessPlugins( false );
|
||||
req.setPomFile( file );
|
||||
req.setModelResolver( new RepositoryModelResolver( basedir, pathTranslator ) );
|
||||
|
||||
Model model;
|
||||
try
|
||||
{
|
||||
model = builder.build( req ).getEffectiveModel();
|
||||
}
|
||||
catch ( ModelBuildingException e )
|
||||
{
|
||||
// TODO: handle it
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
|
||||
MavenProjectFacet facet = new MavenProjectFacet();
|
||||
facet.setGroupId( model.getGroupId() != null ? model.getGroupId() : model.getParent().getGroupId() );
|
||||
facet.setArtifactId( model.getArtifactId() );
|
||||
facet.setPackaging( model.getPackaging() );
|
||||
if ( model.getParent() != null )
|
||||
{
|
||||
MavenProjectParent parent = new MavenProjectParent();
|
||||
parent.setGroupId( model.getParent().getGroupId() );
|
||||
parent.setArtifactId( model.getParent().getArtifactId() );
|
||||
parent.setVersion( model.getParent().getVersion() );
|
||||
facet.setParent( parent );
|
||||
}
|
||||
ProjectBuildMetadata metadata = new ProjectBuildMetadata();
|
||||
metadata.setUrl( model.getUrl() );
|
||||
metadata.addFacet( facet );
|
||||
// TODO: convert project
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId )
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package org.apache.archiva.metadata.repository.storage.maven2;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @plexus.component role="org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator" role-hint="maven2"
|
||||
*/
|
||||
public class Maven2RepositoryPathTranslator
|
||||
implements RepositoryPathTranslator
|
||||
{
|
||||
private static final char PATH_SEPARATOR = '/';
|
||||
|
||||
private static final char GROUP_SEPARATOR = '.';
|
||||
|
||||
public File toFile( File basedir, String namespace, String projectId, String buildId, String filename )
|
||||
{
|
||||
return new File( basedir, toPath( namespace, projectId, buildId, filename ) );
|
||||
}
|
||||
|
||||
public String toPath( String namespace, String projectId, String buildId, String filename )
|
||||
{
|
||||
StringBuilder path = new StringBuilder();
|
||||
|
||||
path.append( formatAsDirectory( namespace ) ).append( PATH_SEPARATOR );
|
||||
path.append( projectId ).append( PATH_SEPARATOR );
|
||||
path.append( buildId ).append( PATH_SEPARATOR );
|
||||
path.append( filename );
|
||||
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
private String formatAsDirectory( String directory )
|
||||
{
|
||||
return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
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.io.File;
|
||||
|
||||
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.building.FileModelSource;
|
||||
import org.apache.maven.model.building.ModelSource;
|
||||
import org.apache.maven.model.resolution.InvalidRepositoryException;
|
||||
import org.apache.maven.model.resolution.ModelResolver;
|
||||
import org.apache.maven.model.resolution.UnresolvableModelException;
|
||||
|
||||
public class RepositoryModelResolver
|
||||
implements ModelResolver
|
||||
{
|
||||
private File basedir;
|
||||
|
||||
private RepositoryPathTranslator pathTranslator;
|
||||
|
||||
public RepositoryModelResolver( File basedir, RepositoryPathTranslator pathTranslator )
|
||||
{
|
||||
this.basedir = basedir;
|
||||
|
||||
this.pathTranslator = pathTranslator;
|
||||
}
|
||||
|
||||
public ModelSource resolveModel( String groupId, String artifactId, String version )
|
||||
throws UnresolvableModelException
|
||||
{
|
||||
String filename = artifactId + "-" + version + ".pom";
|
||||
// TODO: we need to convert 1.0-20091120.112233-1 type paths to baseVersion for the below call - add a test
|
||||
return new FileModelSource( pathTranslator.toFile( basedir, groupId, artifactId, version, filename ) );
|
||||
}
|
||||
|
||||
public void addRepository( Repository repository )
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
// we just ignore repositories outside of the current one for now
|
||||
// TODO: it'd be nice to look them up from Archiva's set, but we want to do that by URL / mapping, not just the
|
||||
// ID since they will rarely match
|
||||
}
|
||||
|
||||
public ModelResolver newCopy()
|
||||
{
|
||||
return new RepositoryModelResolver( basedir, pathTranslator );
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package org.apache.archiva.configuration;
|
||||
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
import org.apache.maven.archiva.configuration.ConfigurationListener;
|
||||
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
|
||||
import org.codehaus.plexus.registry.RegistryException;
|
||||
import org.codehaus.plexus.registry.RegistryListener;
|
||||
|
||||
/*
|
||||
* 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 class TestConfiguration
|
||||
implements ArchivaConfiguration
|
||||
{
|
||||
private Configuration configuration;
|
||||
|
||||
public Configuration getConfiguration()
|
||||
{
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public void save( Configuration configuration )
|
||||
throws RegistryException, IndeterminateConfigurationException
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public boolean isDefaulted()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addListener( ConfigurationListener listener )
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void removeListener( ConfigurationListener listener )
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void addChangeListener( RegistryListener listener )
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
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.ProjectBuildMetadata;
|
||||
import org.apache.archiva.metadata.repository.MetadataResolver;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
|
||||
|
||||
public class Maven2RepositoryMetadataResolverTest
|
||||
extends PlexusInSpringTestCase
|
||||
{
|
||||
private Maven2RepositoryMetadataResolver resolver;
|
||||
|
||||
private static final String TEST_REPO_ID = "test";
|
||||
|
||||
public void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
|
||||
Configuration c = new Configuration();
|
||||
ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
|
||||
testRepo.setId( TEST_REPO_ID );
|
||||
testRepo.setLocation( getTestPath( "src/test/repositories/test" ) );
|
||||
c.addManagedRepository( testRepo );
|
||||
configuration.save( c );
|
||||
|
||||
resolver = (Maven2RepositoryMetadataResolver) lookup( MetadataResolver.class, "maven2" );
|
||||
}
|
||||
|
||||
public void testGetProjectBuildMetadata()
|
||||
{
|
||||
ProjectBuildMetadata metadata =
|
||||
resolver.getProjectBuild( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" );
|
||||
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
|
||||
assertEquals( "jar", facet.getPackaging() );
|
||||
assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
|
||||
// TODO: more testing
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<component-set>
|
||||
<components>
|
||||
<component>
|
||||
<role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
|
||||
<implementation>org.apache.archiva.configuration.TestConfiguration</implementation>
|
||||
</component>
|
||||
</components>
|
||||
</component-set>
|
@ -43,6 +43,7 @@ public class FileMetadataRepository
|
||||
implements MetadataRepository
|
||||
{
|
||||
/**
|
||||
* TODO: this isn't suitable for production use
|
||||
* @plexus.configuration
|
||||
*/
|
||||
private File directory = new File( System.getProperty( "user.home" ), ".archiva-metadata" );
|
||||
|
Loading…
x
Reference in New Issue
Block a user