aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-base/archiva-configuration/src/main
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-05-08 16:05:18 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-05-08 16:05:18 +0000
commitc671224fbb399b1cc027c756d58eba8856e6c794 (patch)
tree80dfd493b1917b2069e060bf1b32e43cc72f3df1 /archiva-base/archiva-configuration/src/main
parent97a323704850ae24f7afbde73141a70e223fe007 (diff)
downloadarchiva-c671224fbb399b1cc027c756d58eba8856e6c794.tar.gz
archiva-c671224fbb399b1cc027c756d58eba8856e6c794.zip
Refactoring RepoContentConsumer into Known vs Invalid to aide in config/scanning
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@536233 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-base/archiva-configuration/src/main')
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java161
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/FiletypeSelectionPredicate.java55
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/FiletypeToMapClosure.java52
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/LocalRepositoryPredicate.java (renamed from archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/LocalRepositoryPredicate.java)2
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/NetworkProxyComparator.java (renamed from archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/NetworkProxyComparator.java)2
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/NetworkProxySelectionPredicate.java (renamed from archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/NetworkProxySelectionPredicate.java)2
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java (renamed from archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/ProxyConnectorSelectionPredicate.java)2
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RemoteRepositoryPredicate.java (renamed from archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/RemoteRepositoryPredicate.java)2
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationComparator.java (renamed from archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/RepositoryConfigurationComparator.java)2
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryIdListClosure.java (renamed from archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/RepositoryIdListClosure.java)2
-rw-r--r--archiva-base/archiva-configuration/src/main/mdo/configuration.mdo2
11 files changed, 277 insertions, 7 deletions
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java
new file mode 100644
index 000000000..783b35885
--- /dev/null
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/FileTypes.java
@@ -0,0 +1,161 @@
+package org.apache.maven.archiva.configuration;
+
+/*
+ * 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.commons.collections.Closure;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.configuration.functors.FiletypeSelectionPredicate;
+import org.apache.maven.archiva.xml.ElementTextListClosure;
+import org.apache.maven.archiva.xml.XMLException;
+import org.apache.maven.archiva.xml.XMLReader;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.dom4j.Element;
+
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * FileTypes
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.configuration.FileTypes"
+ */
+public class FileTypes
+ implements Initializable
+{
+ public static final String ARTIFACTS = "artifacts";
+
+ public static final String AUTO_REMOVE = "auto-remove";
+
+ public static final String INDEXABLE_CONTENT = "indexable-content";
+
+ /**
+ * @plexus.requirement
+ */
+ private ArchivaConfiguration archivaConfiguration;
+
+ /**
+ * Map of default values for the file types.
+ */
+ private Map defaultTypeMap = new HashMap();
+
+ /**
+ * <p>
+ * Get the list of patterns for a specified filetype.
+ * </p>
+ *
+ * <p>
+ * You will always get a list. In this order.
+ * <ul>
+ * <li>The Configured List</li>
+ * <li>The Default List</li>
+ * <li>A single item list of <code>"**<span>/</span>*"</code></li>
+ * </ul>
+ * </p>
+ *
+ * @param id the id to lookup.
+ * @return the list of patterns.
+ */
+ public List getFileTypePatterns( String id )
+ {
+ Configuration config = archivaConfiguration.getConfiguration();
+ Predicate selectedFiletype = new FiletypeSelectionPredicate( id );
+ FileType filetype = (FileType) CollectionUtils.find( config.getRepositoryScanning().getFileTypes(),
+ selectedFiletype );
+
+ if ( ( filetype != null ) && CollectionUtils.isNotEmpty( filetype.getPatterns() ) )
+ {
+ return filetype.getPatterns();
+ }
+
+ List defaultPatterns = (List) defaultTypeMap.get( id );
+
+ if ( CollectionUtils.isEmpty( defaultPatterns ) )
+ {
+ return Collections.singletonList( "**/*" );
+ }
+
+ return defaultPatterns;
+ }
+
+ public void initialize()
+ throws InitializationException
+ {
+ defaultTypeMap.clear();
+
+ try
+ {
+ URL defaultArchivaXml = this.getClass().getResource( "" );
+
+ XMLReader reader = new XMLReader( "configuration", defaultArchivaXml );
+ List resp = reader.getElementList( "//configuration/repositoryScanning/fileTypes/fileType" );
+
+ CollectionUtils.forAllDo( resp, new AddFileTypeToDefaultMap() );
+ }
+ catch ( XMLException e )
+ {
+ throw new InitializationException( "Unable to setup default filetype maps.", e );
+ }
+ }
+
+ class AddFileTypeToDefaultMap
+ implements Closure
+ {
+ public void execute( Object input )
+ {
+ if ( !( input instanceof Element ) )
+ {
+ // Not an element. skip.
+ return;
+ }
+
+ Element elem = (Element) input;
+ if ( !StringUtils.equals( "fileType", elem.getName() ) )
+ {
+ // Not a 'fileType' element. skip.
+ return;
+ }
+
+ String id = elem.elementText( "id" );
+ Element patternsElem = elem.element( "patterns" );
+ if ( patternsElem == null )
+ {
+ // No patterns. skip.
+ return;
+ }
+
+ List patternElemList = patternsElem.elements( "pattern" );
+
+ ElementTextListClosure elemTextList = new ElementTextListClosure();
+ CollectionUtils.forAllDo( patternElemList, elemTextList );
+ List patterns = elemTextList.getList();
+
+ defaultTypeMap.put( id, patterns );
+ }
+ }
+}
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/FiletypeSelectionPredicate.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/FiletypeSelectionPredicate.java
new file mode 100644
index 000000000..c3d58c686
--- /dev/null
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/FiletypeSelectionPredicate.java
@@ -0,0 +1,55 @@
+package org.apache.maven.archiva.configuration.functors;
+
+/*
+ * 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.commons.collections.Predicate;
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.configuration.FileType;
+
+/**
+ * FiletypeSelectionPredicate
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class FiletypeSelectionPredicate
+ implements Predicate
+{
+ private String filetypeId;
+
+ public FiletypeSelectionPredicate( String id )
+ {
+ this.filetypeId = id;
+ }
+
+ public boolean evaluate( Object object )
+ {
+ boolean satisfies = false;
+
+ if ( object instanceof FileType )
+ {
+ FileType filetype = (FileType) object;
+ return ( StringUtils.equals( filetypeId, filetype.getId() ) );
+ }
+
+ return satisfies;
+ }
+
+}
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/FiletypeToMapClosure.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/FiletypeToMapClosure.java
new file mode 100644
index 000000000..cfe7046e0
--- /dev/null
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/FiletypeToMapClosure.java
@@ -0,0 +1,52 @@
+package org.apache.maven.archiva.configuration.functors;
+
+/*
+ * 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.commons.collections.Closure;
+import org.apache.maven.archiva.configuration.FileType;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * FiletypeToMapClosure
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class FiletypeToMapClosure
+ implements Closure
+{
+ private Map map = new HashMap();
+
+ public void execute( Object input )
+ {
+ if ( input instanceof FileType )
+ {
+ FileType filetype = (FileType) input;
+ map.put( filetype.getId(), filetype );
+ }
+ }
+
+ public Map getMap()
+ {
+ return map;
+ }
+}
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/LocalRepositoryPredicate.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/LocalRepositoryPredicate.java
index 8284d72da..7cbad9560 100644
--- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/LocalRepositoryPredicate.java
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/LocalRepositoryPredicate.java
@@ -1,4 +1,4 @@
-package org.apache.maven.archiva.configuration.util;
+package org.apache.maven.archiva.configuration.functors;
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/NetworkProxyComparator.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/NetworkProxyComparator.java
index 6acd20ff5..c4f996c23 100644
--- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/NetworkProxyComparator.java
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/NetworkProxyComparator.java
@@ -1,4 +1,4 @@
-package org.apache.maven.archiva.configuration.util;
+package org.apache.maven.archiva.configuration.functors;
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/NetworkProxySelectionPredicate.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/NetworkProxySelectionPredicate.java
index c21630866..ea7832dd7 100644
--- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/NetworkProxySelectionPredicate.java
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/NetworkProxySelectionPredicate.java
@@ -1,4 +1,4 @@
-package org.apache.maven.archiva.configuration.util;
+package org.apache.maven.archiva.configuration.functors;
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/ProxyConnectorSelectionPredicate.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java
index b1fc9fc3f..12b0964e8 100644
--- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/ProxyConnectorSelectionPredicate.java
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java
@@ -1,4 +1,4 @@
-package org.apache.maven.archiva.configuration.util;
+package org.apache.maven.archiva.configuration.functors;
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/RemoteRepositoryPredicate.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RemoteRepositoryPredicate.java
index bb8db282b..9ae15b22e 100644
--- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/RemoteRepositoryPredicate.java
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RemoteRepositoryPredicate.java
@@ -1,4 +1,4 @@
-package org.apache.maven.archiva.configuration.util;
+package org.apache.maven.archiva.configuration.functors;
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/RepositoryConfigurationComparator.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationComparator.java
index 1077b0cc7..b69161f0c 100644
--- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/RepositoryConfigurationComparator.java
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationComparator.java
@@ -1,4 +1,4 @@
-package org.apache.maven.archiva.configuration.util;
+package org.apache.maven.archiva.configuration.functors;
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/RepositoryIdListClosure.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryIdListClosure.java
index 97503d5b0..a739f8c0b 100644
--- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/util/RepositoryIdListClosure.java
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryIdListClosure.java
@@ -1,4 +1,4 @@
-package org.apache.maven.archiva.configuration.util;
+package org.apache.maven.archiva.configuration.functors;
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
index 66b39a368..49efaad10 100644
--- a/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
+++ b/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
@@ -598,6 +598,7 @@
</description>
</field>
</fields>
+ <!--
<codeSegments>
<codeSegment>
<version>1.0.0+</version>
@@ -641,6 +642,7 @@
]]></code>
</codeSegment>
</codeSegments>
+ -->
</class>
<class>
<name>FileType</name>