]> source.dussan.org Git - archiva.git/commitdiff
Adding obr repository support. branch is experimental.
authorJames William Dumay <jdumay@apache.org>
Thu, 18 Dec 2008 06:25:27 +0000 (06:25 +0000)
committerJames William Dumay <jdumay@apache.org>
Thu, 18 Dec 2008 06:25:27 +0000 (06:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-obr-repository@727655 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/nb-configuration.xml [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/pom.xml [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/main/java/org/apache/archiva/consumers/OBRRepositoryConsumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/main/resources/META-INF/spring-context.xml [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/java/org/apache/archiva/consumers/OBRRepositoryConsumerTest.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/resources/repository/commons-codec/commons-codec/1.3.0/commons-codec-1.3.0.jar [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/resources/repository/commons-io/commons-io/1.4.0/commons-io-1.4.0.jar [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/pom.xml

diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/nb-configuration.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/nb-configuration.xml
new file mode 100644 (file)
index 0000000..6b36da4
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-shared-configuration>
+    <!--
+This file contains additional configuration written by modules in the NetBeans IDE.
+The configuration is intended to be shared among all the users of project and
+therefore it is assumed to be part of version control checkout.
+Without this configuration present, some functionality in the IDE may be limited or fail altogether.
+-->
+    <spring-data xmlns="http://www.netbeans.org/ns/spring-data/1">
+        <config-files>
+            <config-file>src/main/resources/META-INF/spring-context.xml</config-file>
+        </config-files>
+        <config-file-groups/>
+    </spring-data>
+</project-shared-configuration>
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/pom.xml
new file mode 100644 (file)
index 0000000..102f7d9
--- /dev/null
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<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">
+    <parent>
+        <artifactId>archiva-consumers</artifactId>
+        <groupId>org.apache.archiva</groupId>
+        <version>1.2-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.archiva</groupId>
+    <artifactId>archiva-obr-consumer</artifactId>
+    <name>archiva-obr-consumer</name>
+    <version>1.2-SNAPSHOT</version>
+    <url>http://maven.apache.org</url>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.archiva</groupId>
+          <artifactId>archiva-database</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.archiva</groupId>
+          <artifactId>archiva-configuration</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.archiva</groupId>
+          <artifactId>archiva-consumer-api</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.archiva</groupId>
+          <artifactId>archiva-repository-layer</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-spring</artifactId>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+           <groupId>ant</groupId>
+           <artifactId>ant</artifactId>
+           <version>1.6.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi.impl.bundle.bindex</groupId>
+            <artifactId>bindex</artifactId>
+            <version>2.2</version>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/main/java/org/apache/archiva/consumers/OBRRepositoryConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/main/java/org/apache/archiva/consumers/OBRRepositoryConsumer.java
new file mode 100644 (file)
index 0000000..f7d86f4
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ *  Copyright 2008 jdumay.
+ * 
+ *  Licensed 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.
+ *  under the License.
+ */
+
+package org.apache.archiva.consumers;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import org.apache.commons.io.FileUtils;
+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.repository.ManagedRepositoryContent;
+import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.FileSet;
+import org.osgi.impl.bundle.bindex.Index;
+import org.osgi.impl.bundle.bindex.ant.BindexTask;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+/**
+ *
+ * @author jdumay
+ */
+public class OBRRepositoryConsumer 
+        extends AbstractMonitoredConsumer
+        implements KnownRepositoryContentConsumer, ApplicationContextAware
+{
+    private ManagedRepositoryContent content;
+
+    public void setApplicationContext(ApplicationContext context) throws BeansException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public String getDescription() {
+        return "Produces the OSGi OBR repository index";
+    }
+
+    public String getId() {
+        return "create-obr-repositoryxml";
+    }
+
+    public boolean isPermanent() {
+        return false;
+    }
+
+    public void beginScan(ManagedRepositoryConfiguration repository, Date whenGathered) throws ConsumerException {
+        content = new ManagedDefaultRepositoryContent();
+        content.setRepository(repository);
+    }
+
+    public void completeScan() {
+        /** do nothing **/
+    }
+
+    public List<String> getExcludes() {
+        return null;
+    }
+
+    public List<String> getIncludes() {
+        return Arrays.asList("**/*.jar");
+    }
+
+    public void processFile(String path)
+        throws ConsumerException
+    {
+        BindexTask task = new BindexTask();
+        File temporaryBindexLocation = new File(path, ".bindex");
+        temporaryBindexLocation.mkdirs();
+        task.setRepositoryFile(new File(temporaryBindexLocation, "repository.xml"));
+        task.setName(content.getRepository().getName());
+        task.setQuiet(true);
+        task.setRoot(new File(content.getRepoRoot()));
+
+        FileSet fileSet = new FileSet();
+        fileSet.setIncludesfile(new File(path));
+        try
+        {
+            task.execute();
+        }
+        catch (BuildException e)
+        {
+            throw new ConsumerException("Could not add jar " + path + " to obr repository.xml", e);
+        }
+        finally
+        {
+            try
+            {
+                FileUtils.deleteDirectory(temporaryBindexLocation);
+            }
+            catch (IOException e)
+            {
+                throw new ConsumerException(e.getMessage(), e);
+            }
+        }
+    }
+
+}
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/main/resources/META-INF/spring-context.xml
new file mode 100644 (file)
index 0000000..1cc05ce
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+    <bean id="obrRepositoryConsumer" class="org.apache.archiva.consumers.OBRRepositoryConsumer"/>
+</beans>
\ No newline at end of file
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/java/org/apache/archiva/consumers/OBRRepositoryConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/java/org/apache/archiva/consumers/OBRRepositoryConsumerTest.java
new file mode 100644 (file)
index 0000000..aec5a61
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *  Copyright 2008 jdumay.
+ * 
+ *  Licensed 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.
+ *  under the License.
+ */
+
+package org.apache.archiva.consumers;
+
+import java.io.File;
+import java.util.Date;
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.codehaus.plexus.spring.PlexusToSpringUtils;
+
+/**
+ *
+ * @author jdumay
+ */
+public class OBRRepositoryConsumerTest extends PlexusInSpringTestCase
+{
+    private OBRRepositoryConsumer consumer;
+
+    private File testRepo;
+
+    private ManagedRepositoryConfiguration configuration;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        File testRepoData = new File("src/test/resources/repository");
+        testRepo = new File("target/obrtestrepo").getAbsoluteFile();
+        testRepo.mkdirs();
+        consumer = (OBRRepositoryConsumer)lookup(PlexusToSpringUtils.buildSpringId(OBRRepositoryConsumer.class));
+        FileUtils.copyDirectory(testRepoData, testRepo);
+        configuration = new ManagedRepositoryConfiguration();
+        configuration.setName("My Test OSGi repository");
+        configuration.setId("test-obr-osgi-repo");
+        configuration.setLocation(testRepo.getAbsolutePath());
+        consumer.beginScan(configuration, new Date());
+    }
+
+    @Override
+    protected void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+        FileUtils.deleteDirectory(testRepo);
+    }
+
+    public void testCreatesRepositoryXml() throws Exception
+    {
+        File repositoryXml = new File(configuration.getLocation(), "repository.xml");
+        assertFalse("repository.xml should not exist", repositoryXml.exists());
+        consumer.processFile(new File(testRepo, "./commons-codec/commons-codec/1.3.0/commons-codec-1.3.0.jar").getAbsolutePath());
+        assertTrue("repository.xml should exist", repositoryXml.exists());
+    }
+}
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/resources/repository/commons-codec/commons-codec/1.3.0/commons-codec-1.3.0.jar b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/resources/repository/commons-codec/commons-codec/1.3.0/commons-codec-1.3.0.jar
new file mode 100644 (file)
index 0000000..c69504a
Binary files /dev/null and b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/resources/repository/commons-codec/commons-codec/1.3.0/commons-codec-1.3.0.jar differ
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/resources/repository/commons-io/commons-io/1.4.0/commons-io-1.4.0.jar b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/resources/repository/commons-io/commons-io/1.4.0/commons-io-1.4.0.jar
new file mode 100644 (file)
index 0000000..ed7e825
Binary files /dev/null and b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/resources/repository/commons-io/commons-io/1.4.0/commons-io-1.4.0.jar differ
index 4d67521645a19e2bf7516a715036e0bc8773f072..6d985635c6ded54f86b47b2b3359bd4a7366dca7 100644 (file)
@@ -13,9 +13,7 @@
   ~ 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.
-  -->
-
-<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">
+  --><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>
   <parent>
     <groupId>org.apache.archiva</groupId>
@@ -35,6 +33,7 @@
     <module>archiva-lucene-consumers</module>
     <module>archiva-signature-consumers</module>
     <module>archiva-dependency-tree-consumer</module>
+    <module>archiva-obr-consumer</module>
   </modules>
 
   <build>
@@ -45,4 +44,4 @@
       </plugin>
     </plugins>
   </build>
-</project>
+</project>
\ No newline at end of file