From: James William Dumay Date: Thu, 18 Dec 2008 06:25:27 +0000 (+0000) Subject: Adding obr repository support. branch is experimental. X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=06119bad3fcdd48b896d0d686bf5c0963aed65b4;p=archiva.git Adding obr repository support. branch is experimental. git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-obr-repository@727655 13f79535-47bb-0310-9956-ffa450edef68 --- 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 index 000000000..6b36da4c0 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/nb-configuration.xml @@ -0,0 +1,15 @@ + + + + + + src/main/resources/META-INF/spring-context.xml + + + + 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 index 000000000..102f7d9e2 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/pom.xml @@ -0,0 +1,70 @@ + + + + + + archiva-consumers + org.apache.archiva + 1.2-SNAPSHOT + + 4.0.0 + org.apache.archiva + archiva-obr-consumer + archiva-obr-consumer + 1.2-SNAPSHOT + http://maven.apache.org + + + org.springframework + spring-context + + + org.apache.archiva + archiva-database + + + org.apache.archiva + archiva-configuration + + + org.apache.archiva + archiva-consumer-api + + + org.apache.archiva + archiva-repository-layer + + + org.codehaus.plexus + plexus-spring + test + + + ant + ant + 1.6.1 + + + org.osgi.impl.bundle.bindex + bindex + 2.2 + + + \ 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 index 000000000..f7d86f407 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/main/java/org/apache/archiva/consumers/OBRRepositoryConsumer.java @@ -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 getExcludes() { + return null; + } + + public List 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 index 000000000..1cc05cedd --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/main/resources/META-INF/spring-context.xml @@ -0,0 +1,7 @@ + + + + + \ 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 index 000000000..aec5a619c --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-obr-consumer/src/test/java/org/apache/archiva/consumers/OBRRepositoryConsumerTest.java @@ -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 index 000000000..c69504a81 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 index 000000000..ed7e8253c 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 diff --git a/archiva-modules/archiva-base/archiva-consumers/pom.xml b/archiva-modules/archiva-base/archiva-consumers/pom.xml index 4d6752164..6d985635c 100644 --- a/archiva-modules/archiva-base/archiva-consumers/pom.xml +++ b/archiva-modules/archiva-base/archiva-consumers/pom.xml @@ -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. - --> - - + --> 4.0.0 org.apache.archiva @@ -35,6 +33,7 @@ archiva-lucene-consumers archiva-signature-consumers archiva-dependency-tree-consumer + archiva-obr-consumer @@ -45,4 +44,4 @@ - + \ No newline at end of file