You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by jd...@apache.org on 2008/06/24 14:59:49 UTC
svn commit: r671161 - in /archiva/sandbox/new-repository-api: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/archiva/
src/main/java/org/apache/archiva/repository/
src/main/java/org/apache/archiva/...
Author: jdumay
Date: Tue Jun 24 05:59:48 2008
New Revision: 671161
URL: http://svn.apache.org/viewvc?rev=671161&view=rev
Log:
Initial version of my proposed new repository api with pluginable storage backend
Added:
archiva/sandbox/new-repository-api/pom.xml
archiva/sandbox/new-repository-api/src/
archiva/sandbox/new-repository-api/src/main/
archiva/sandbox/new-repository-api/src/main/java/
archiva/sandbox/new-repository-api/src/main/java/org/
archiva/sandbox/new-repository-api/src/main/java/org/apache/
archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/
archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/
archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/Repository.java
archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryException.java
archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryProxyManager.java
archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryReadException.java
archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryWriteException.java
archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/ResourceContext.java
archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/ResourceRepository.java
archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/filesystem/
archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/filesystem/FileSystemRepositoryBackend.java
archiva/sandbox/new-repository-api/src/test/
archiva/sandbox/new-repository-api/src/test/java/
archiva/sandbox/new-repository-api/src/test/java/org/
archiva/sandbox/new-repository-api/src/test/java/org/apache/
archiva/sandbox/new-repository-api/src/test/java/org/apache/archiva/
archiva/sandbox/new-repository-api/src/test/java/org/apache/archiva/repository/
Added: archiva/sandbox/new-repository-api/pom.xml
URL: http://svn.apache.org/viewvc/archiva/sandbox/new-repository-api/pom.xml?rev=671161&view=auto
==============================================================================
--- archiva/sandbox/new-repository-api/pom.xml (added)
+++ archiva/sandbox/new-repository-api/pom.xml Tue Jun 24 05:59:48 2008
@@ -0,0 +1,23 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.archiva.repository</groupId>
+ <artifactId>archiva-repository</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>archiva-repository</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/Repository.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/Repository.java?rev=671161&view=auto
==============================================================================
--- archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/Repository.java (added)
+++ archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/Repository.java Tue Jun 24 05:59:48 2008
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+package org.apache.archiva.repository;
+
+import java.io.InputStream;
+
+/**
+ *
+ * @author jdumay
+ */
+public interface Repository
+{
+ public InputStream getStream(ResourceContext context)
+ throws RepositoryReadException;
+
+ public void writeStream(ResourceContext context, InputStream is)
+ throws RepositoryWriteException;
+}
Added: archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryException.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryException.java?rev=671161&view=auto
==============================================================================
--- archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryException.java (added)
+++ archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryException.java Tue Jun 24 05:59:48 2008
@@ -0,0 +1,41 @@
+package org.apache.archiva.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.
+ */
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public class RepositoryException extends Exception
+{
+ public RepositoryException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public RepositoryException(String message)
+ {
+ super(message);
+ }
+
+ public RepositoryException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Added: archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryProxyManager.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryProxyManager.java?rev=671161&view=auto
==============================================================================
--- archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryProxyManager.java (added)
+++ archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryProxyManager.java Tue Jun 24 05:59:48 2008
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+package org.apache.archiva.repository;
+
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public interface RepositoryProxyManager
+{
+ /**
+ * Retrieves a stream to the given context
+ * @param context
+ * @return stream to proxied data or null if proxy is not nessesary
+ */
+ InputStream retrieve(ResourceContext context);
+}
Added: archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryReadException.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryReadException.java?rev=671161&view=auto
==============================================================================
--- archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryReadException.java (added)
+++ archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryReadException.java Tue Jun 24 05:59:48 2008
@@ -0,0 +1,41 @@
+package org.apache.archiva.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.
+ */
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public class RepositoryReadException extends RepositoryException
+{
+ public RepositoryReadException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public RepositoryReadException(String message)
+ {
+ super(message);
+ }
+
+ public RepositoryReadException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Added: archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryWriteException.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryWriteException.java?rev=671161&view=auto
==============================================================================
--- archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryWriteException.java (added)
+++ archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/RepositoryWriteException.java Tue Jun 24 05:59:48 2008
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+package org.apache.archiva.repository;
+
+/**
+ *
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public class RepositoryWriteException extends RepositoryException
+{
+ public RepositoryWriteException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public RepositoryWriteException(String message)
+ {
+ super(message);
+ }
+
+ public RepositoryWriteException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Added: archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/ResourceContext.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/ResourceContext.java?rev=671161&view=auto
==============================================================================
--- archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/ResourceContext.java (added)
+++ archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/ResourceContext.java Tue Jun 24 05:59:48 2008
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+package org.apache.archiva.repository;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public interface ResourceContext
+{
+ String getLogicalPath();
+
+ String getRepositoryId();
+}
Added: archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/ResourceRepository.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/ResourceRepository.java?rev=671161&view=auto
==============================================================================
--- archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/ResourceRepository.java (added)
+++ archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/ResourceRepository.java Tue Jun 24 05:59:48 2008
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+package org.apache.archiva.repository;
+
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public class ResourceRepository implements Repository
+{
+ private RepositoryProxyManager proxyManager;
+
+ private Repository sourceRepository;
+
+ public InputStream getStream(ResourceContext context)
+ throws RepositoryReadException
+ {
+ InputStream is = proxyManager.retrieve(context);
+ if (is == null)
+ {
+ is = sourceRepository.getStream(context);
+ }
+ return is;
+ }
+
+ public void writeStream(ResourceContext context, InputStream is)
+ throws RepositoryWriteException
+ {
+ sourceRepository.writeStream(context, is);
+ }
+
+ public RepositoryProxyManager getProxyManager()
+ {
+ return proxyManager;
+ }
+
+ public void setProxyManager(RepositoryProxyManager proxyManager)
+ {
+ this.proxyManager = proxyManager;
+ }
+
+ public Repository getSourceRepository()
+ {
+ return sourceRepository;
+ }
+
+ public void setRepositorySource(Repository sourceRepository)
+ {
+ this.sourceRepository = sourceRepository;
+ }
+}
Added: archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/filesystem/FileSystemRepositoryBackend.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/filesystem/FileSystemRepositoryBackend.java?rev=671161&view=auto
==============================================================================
--- archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/filesystem/FileSystemRepositoryBackend.java (added)
+++ archiva/sandbox/new-repository-api/src/main/java/org/apache/archiva/repository/filesystem/FileSystemRepositoryBackend.java Tue Jun 24 05:59:48 2008
@@ -0,0 +1,92 @@
+package org.apache.archiva.repository.filesystem;
+
+/*
+ * 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.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import org.apache.archiva.repository.Repository;
+import org.apache.archiva.repository.RepositoryReadException;
+import org.apache.archiva.repository.RepositoryWriteException;
+import org.apache.archiva.repository.ResourceContext;
+import org.apache.commons.io.IOUtils;
+
+/**
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public class FileSystemRepositoryBackend implements Repository
+{
+ private final String rootPath;
+
+ public FileSystemRepositoryBackend(String rootPath)
+ {
+ this.rootPath = rootPath;
+ }
+
+ public InputStream getStream(ResourceContext context)
+ throws RepositoryReadException
+ {
+ File file = new File(rootPath, context.getRepositoryId());
+ if (!file.exists())
+ {
+ throw new RepositoryReadException("");
+ }
+
+ try
+ {
+ return new FileInputStream(file);
+ }
+ catch (IOException e)
+ {
+ throw new RepositoryReadException(e);
+ }
+ }
+
+ public void writeStream(ResourceContext context, InputStream is)
+ throws RepositoryWriteException
+ {
+ File file = new File(rootPath, context.getLogicalPath());
+ if (!file.exists())
+ {
+ if (!file.getParentFile().mkdirs())
+ {
+ throw new RepositoryWriteException("Could not create directory " + file.getParent());
+ }
+ }
+
+ OutputStream os = null;
+ try
+ {
+ os = new FileOutputStream(file);
+ IOUtils.copy(is, os);
+ }
+ catch (IOException e)
+ {
+ throw new RepositoryWriteException(e);
+ }
+ finally
+ {
+ IOUtils.closeQuietly(os);
+ }
+ }
+}