diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml index 538c0cd4d..2d1e5c78d 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml @@ -1,18 +1,21 @@ @@ -49,6 +52,21 @@ plexus-spring test + + org.apache.archiva + metadata-model + 1.2-SNAPSHOT + + + org.apache.archiva + metadata-repository-api + 1.2-SNAPSHOT + + + org.apache.archiva + metadata-repository-file + 1.2-SNAPSHOT + diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArchivaMetadataCreationConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArchivaMetadataCreationConsumer.java new file mode 100644 index 000000000..593f72c6c --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArchivaMetadataCreationConsumer.java @@ -0,0 +1,206 @@ +package org.apache.maven.archiva.consumers.core; + +/* + * 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.ArrayList; +import java.util.Date; +import java.util.List; + +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.file.FileMetadataRepository; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.ConfigurationNames; +import org.apache.maven.archiva.configuration.FileTypes; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.maven.archiva.consumers.ConsumerException; +import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.maven.archiva.model.ArtifactReference; +import org.apache.maven.archiva.repository.ManagedRepositoryContent; +import org.apache.maven.archiva.repository.RepositoryContentFactory; +import org.apache.maven.archiva.repository.RepositoryException; +import org.apache.maven.archiva.repository.layout.LayoutException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import org.codehaus.plexus.registry.Registry; +import org.codehaus.plexus.registry.RegistryListener; + +/** + * ArtifactUpdateDatabaseConsumer - Take an artifact off of disk and put it into the repository. + * + * @version $Id: ArtifactUpdateDatabaseConsumer.java 718864 2008-11-19 06:33:35Z brett $ + * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer" + * role-hint="create-archiva-metadata" instantiation-strategy="per-lookup" + */ +public class ArchivaMetadataCreationConsumer + extends AbstractMonitoredConsumer + implements KnownRepositoryContentConsumer, RegistryListener, Initializable +{ + /** + * @plexus.configuration default-value="create-archiva-metadata" + */ + private String id; + + /** + * @plexus.configuration default-value="Create basic metadata for Archiva to be able to reference the artifact" + */ + private String description; + + /** + * @plexus.requirement + */ + private ArchivaConfiguration configuration; + + /** + * @plexus.requirement + */ + private FileTypes filetypes; + + /** + * @plexus.requirement + */ + private RepositoryContentFactory repositoryFactory; + + private Date whenGathered; + + private ManagedRepositoryContent repository; + + private List includes = new ArrayList(); + + private MetadataRepository metadataRepository; + + public String getId() + { + return this.id; + } + + public String getDescription() + { + return this.description; + } + + public boolean isPermanent() + { + return true; + } + + public List getExcludes() + { + return getDefaultArtifactExclusions(); + } + + public List getIncludes() + { + return this.includes; + } + + public void beginScan( ManagedRepositoryConfiguration repo, Date whenGathered ) + throws ConsumerException + { + try + { + this.repository = repositoryFactory.getManagedRepositoryContent( repo.getId() ); + this.metadataRepository = new FileMetadataRepository( new File( repository.getRepoRoot(), ".metadata" ) ); + this.whenGathered = whenGathered; + } + catch ( RepositoryException e ) + { + throw new ConsumerException( "Unable to start ArtifactUpdateDatabaseConsumer: " + e.getMessage(), e ); + } + } + + public void processFile( String path ) + throws ConsumerException + { + // note that we do minimal processing including checksums and POM information for performance of + // the initial scan. Any request for this information will be intercepted and populated on-demand + // or picked up by subsequent scans + ArtifactReference artifact; + try + { + artifact = repository.toArtifactReference( path ); + } + catch ( LayoutException e ) + { + throw new ConsumerException( e.getMessage(), e ); + } + + File file = new File( repository.getRepoRoot(), path ); + + // TODO: needed in a more central place, but trying to isolate impact to start with + String metadataId = artifact.getGroupId() + "." + artifact.getArtifactId(); + + ProjectMetadata project = new ProjectMetadata(); + project.setId( metadataId ); + + ProjectBuildMetadata build = new ProjectBuildMetadata(); + build.setId( artifact.getVersion() ); + + ArtifactMetadata artifactMeta = new ArtifactMetadata(); + artifactMeta.setId( file.getName() ); + artifactMeta.setUpdated( file.lastModified() ); + artifactMeta.setSize( file.length() ); + + build.addArtifact( artifactMeta ); + project.addBuild( build ); + + // TODO: store "whenGathered" + + // read the metadata and update it if it is newer or doesn't exist + metadataRepository.update( project ); + } + + public void completeScan() + { + /* do nothing */ + } + + public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) + { + initIncludes(); + } + } + + public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + /* do nothing */ + } + + private void initIncludes() + { + includes.clear(); + + includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); + } + + public void initialize() + throws InitializationException + { + configuration.addChangeListener( this ); + + initIncludes(); + } +} diff --git a/archiva-modules/metadata/metadata-model/pom.xml b/archiva-modules/metadata/metadata-model/pom.xml new file mode 100644 index 000000000..e702fb89a --- /dev/null +++ b/archiva-modules/metadata/metadata-model/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + metadata + org.apache.archiva + 1.2-SNAPSHOT + + metadata-model + Archiva Metadata Model + diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java new file mode 100644 index 000000000..85b440759 --- /dev/null +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java @@ -0,0 +1,66 @@ +package org.apache.archiva.metadata.model; + +import java.util.Date; + +/* + * 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 ArtifactMetadata +{ + private String id; + + private Date updated; + + private long size; + + public String getId() + { + return id; + } + + public void setId( String id ) + { + this.id = id; + } + + public Date getUpdated() + { + return updated; + } + + public void setUpdated( Date updated ) + { + this.updated = updated; + } + + public void setUpdated( long updated ) + { + this.updated = new Date( updated ); + } + + public long getSize() + { + return size; + } + + public void setSize( long size ) + { + this.size = size; + } +} diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java new file mode 100644 index 000000000..57b9f4d0c --- /dev/null +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java @@ -0,0 +1,45 @@ +package org.apache.archiva.metadata.model; + +import java.util.LinkedHashMap; +import java.util.Map; + +/* + * 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 ProjectBuildMetadata +{ + private String id; + + private Map artifacts = new LinkedHashMap(); + + public String getId() + { + return id; + } + + public void setId( String id ) + { + this.id = id; + } + + public void addArtifact( ArtifactMetadata artifact ) + { + this.artifacts.put( artifact.getId(), artifact ); + } +} diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java new file mode 100644 index 000000000..783c91313 --- /dev/null +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java @@ -0,0 +1,45 @@ +package org.apache.archiva.metadata.model; + +import java.util.LinkedHashMap; +import java.util.Map; + +/* + * 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 ProjectMetadata +{ + private String id; + + private Map builds = new LinkedHashMap(); + + public void setId( String id ) + { + this.id = id; + } + + public String getId() + { + return id; + } + + public void addBuild( ProjectBuildMetadata build ) + { + this.builds.put( build.getId(), build ); + } +} diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/RepositoryMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/RepositoryMetadata.java new file mode 100644 index 000000000..d1448f24f --- /dev/null +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/RepositoryMetadata.java @@ -0,0 +1,28 @@ +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. + */ + +/** + * Information about the repository as a whole. + */ +public class RepositoryMetadata +{ + // TODO +} diff --git a/archiva-modules/metadata/metadata-repository-api/pom.xml b/archiva-modules/metadata/metadata-repository-api/pom.xml new file mode 100644 index 000000000..62e3afe8f --- /dev/null +++ b/archiva-modules/metadata/metadata-repository-api/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + metadata + org.apache.archiva + 1.2-SNAPSHOT + + metadata-repository-api + Archiva Metadata Repository API + + + org.apache.archiva + metadata-model + 1.2-SNAPSHOT + + + diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java new file mode 100644 index 000000000..f77253078 --- /dev/null +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -0,0 +1,33 @@ +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 org.apache.archiva.metadata.model.ProjectMetadata; + +public interface MetadataRepository +{ + + /** + * Update metadata for a particular project in the metadata repository, or create it if it does not already exist. + * @param project the project metadata to create or update + */ + void update( ProjectMetadata project ); + +} diff --git a/archiva-modules/metadata/pom.xml b/archiva-modules/metadata/pom.xml new file mode 100644 index 000000000..7474c7c88 --- /dev/null +++ b/archiva-modules/metadata/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + archiva-modules + org.apache.archiva + 1.2-SNAPSHOT + + metadata + Archiva Metadata + pom + + metadata-model + metadata-repository-api + + \ No newline at end of file diff --git a/archiva-modules/plugins/metadata-repository-file/pom.xml b/archiva-modules/plugins/metadata-repository-file/pom.xml new file mode 100644 index 000000000..47bdeaee8 --- /dev/null +++ b/archiva-modules/plugins/metadata-repository-file/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + plugins + org.apache.archiva + 1.2-SNAPSHOT + + metadata-repository-file + File System Backed Metadata Repository + + + org.apache.archiva + metadata-repository-api + 1.2-SNAPSHOT + + + commons-io + commons-io + + + \ No newline at end of file diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java new file mode 100644 index 000000000..9241ad316 --- /dev/null +++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -0,0 +1,75 @@ +package org.apache.archiva.metadata.repository.file; + +/* + * 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.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +import org.apache.archiva.metadata.model.ProjectMetadata; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.commons.io.IOUtils; + +public class FileMetadataRepository + implements MetadataRepository +{ + private File directory; + + public FileMetadataRepository( File directory ) + { + this.directory = directory; + } + + public void update( ProjectMetadata project ) + { + try + { + store( project ); + } + catch ( IOException e ) + { + // TODO! + e.printStackTrace(); + } + } + + private void store( ProjectMetadata project ) + throws FileNotFoundException, IOException + { + // TODO: this is a more braindead implementation than we would normally expect, for prototyping purposes + + Properties properties = new Properties(); + properties.put( "id", project.getId() ); + File directory = new File( this.directory, project.getId() ); + directory.mkdirs(); + FileOutputStream os = new FileOutputStream( new File( directory, "metadata.xml" ) ); + try + { + properties.storeToXML( os, null ); + } + finally + { + IOUtils.closeQuietly( os ); + } + } + +} diff --git a/archiva-modules/plugins/pom.xml b/archiva-modules/plugins/pom.xml new file mode 100644 index 000000000..2dfb21796 --- /dev/null +++ b/archiva-modules/plugins/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + archiva-modules + org.apache.archiva + 1.2-SNAPSHOT + + plugins + Archiva Core Plugins + pom + + metadata-repository-file + + \ No newline at end of file diff --git a/archiva-modules/pom.xml b/archiva-modules/pom.xml index 65a1868ae..d925ff4b6 100644 --- a/archiva-modules/pom.xml +++ b/archiva-modules/pom.xml @@ -1,5 +1,4 @@ - - - + --> archiva org.apache.archiva @@ -36,6 +33,8 @@ archiva-reporting archiva-scheduled archiva-web + metadata + plugins @@ -204,4 +203,4 @@ ${siteBaseDeployment}/ref/${project.version} - + \ No newline at end of file