2 * Copyright 2008 jdumay.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 package org.apache.archiva.consumers;
21 import java.io.IOException;
22 import java.util.Arrays;
23 import java.util.Date;
24 import java.util.List;
25 import org.apache.commons.io.FileUtils;
26 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
27 import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
28 import org.apache.maven.archiva.consumers.ConsumerException;
29 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
30 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
31 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
32 import org.apache.tools.ant.BuildException;
33 import org.apache.tools.ant.types.FileSet;
34 import org.apache.tools.ant.types.selectors.FilenameSelector;
35 import org.osgi.impl.bundle.bindex.ant.BindexTask;
41 public class OBRRepositoryConsumer
42 extends AbstractMonitoredConsumer
43 implements KnownRepositoryContentConsumer
45 private ManagedRepositoryContent content;
47 public String getDescription() {
48 return "Produces the OSGi OBR repository index";
51 public String getId() {
52 return "create-obr-repositoryxml";
55 public boolean isPermanent() {
59 public void beginScan(ManagedRepositoryConfiguration repository, Date whenGathered) throws ConsumerException {
60 content = new ManagedDefaultRepositoryContent();
61 content.setRepository(repository);
64 public void completeScan() {
68 public List<String> getExcludes() {
72 public List<String> getIncludes() {
73 return Arrays.asList("**/*.jar");
76 public void processFile(String path)
77 throws ConsumerException
79 BindexTask task = new BindexTask();
80 File repositoryIndexFile = new File(new File(path).getParentFile(), ".repository.xml");
81 task.setRepositoryFile(repositoryIndexFile);
82 task.setName(content.getRepository().getName());
84 task.setRoot(new File(content.getRepoRoot()));
86 FileSet fileSet = new FileSet();
87 fileSet.setDir(new File(path).getParentFile());
88 fileSet.setIncludes("**/*.jar");
93 catch (BuildException e)
95 throw new ConsumerException("Could not add jar " + path + " to obr repository.xml", e);