]> source.dussan.org Git - archiva.git/commitdiff
Add some code for a possible implementation for syncing repositories using only one...
authorCarlos Sanchez Gonzalez <carlos@apache.org>
Thu, 21 Jun 2007 18:27:33 +0000 (18:27 +0000)
committerCarlos Sanchez Gonzalez <carlos@apache.org>
Thu, 21 Jun 2007 18:27:33 +0000 (18:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@549579 13f79535-47bb-0310-9956-ffa450edef68

maven-meeper/pom.xml
maven-meeper/src/main/java/org/apache/maven/archiva/meeper/Reader.java [new file with mode: 0644]
maven-meeper/src/main/java/org/apache/maven/archiva/meeper/SyncedRepository.java [new file with mode: 0644]
maven-meeper/src/test/java/org/apache/maven/archiva/meeper/ReaderTest.java [new file with mode: 0644]
maven-meeper/src/test/resources/org/apache/maven/archiva/meeper/sync.csv [new file with mode: 0644]

index a449f58cd55ef5fef49b8db5137c050967b498ff..94a9a656c73412df96374c7e423f4013d701c314 100644 (file)
@@ -15,7 +15,8 @@
   ~ 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">
   <parent>
     <groupId>org.apache.maven.archiva</groupId>
     <artifactId>archiva-parent</artifactId>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>maven-meeper</artifactId>
-  <packaging>pom</packaging>
   <name>Maven Meeper</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-csv</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.2</version>
+    </dependency>
+  </dependencies>
+
 </project>
diff --git a/maven-meeper/src/main/java/org/apache/maven/archiva/meeper/Reader.java b/maven-meeper/src/main/java/org/apache/maven/archiva/meeper/Reader.java
new file mode 100644 (file)
index 0000000..ea47a67
--- /dev/null
@@ -0,0 +1,62 @@
+package org.apache.maven.archiva.meeper;
+
+/*
+ * 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.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.csv.CSVParser;
+
+/**
+ * Read a csv file with the synced repositories information
+ * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class Reader
+{
+    private CSVParser parser;
+
+    public Reader( InputStream stream )
+    {
+        parser = new CSVParser( new InputStreamReader( stream ) );
+    }
+
+    public List parse()
+        throws IOException
+    {
+        String[][] data = parser.getAllValues();
+        List repos = new ArrayList( data.length - 1 );
+
+        /* ignore headers line */
+        for ( int i = 1; i < data.length; i++ )
+        {
+            int j = 0;
+            SyncedRepository repo = new SyncedRepository();
+            repo.setGroupId( data[i][j++] );
+            repo.setLocation( data[i][j++] );
+            repo.setProtocol( data[i][j++] );
+            repo.setContactName( data[i][j++] );
+            repo.setContactMail( data[i][j++] );
+            repos.add( repo );
+        }
+
+        return repos;
+    }
+}
diff --git a/maven-meeper/src/main/java/org/apache/maven/archiva/meeper/SyncedRepository.java b/maven-meeper/src/main/java/org/apache/maven/archiva/meeper/SyncedRepository.java
new file mode 100644 (file)
index 0000000..59e0107
--- /dev/null
@@ -0,0 +1,92 @@
+package org.apache.maven.archiva.meeper;
+
+/*
+ * 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.lang.builder.ReflectionToStringBuilder;
+
+/**
+ * Stores a synced repository data. 
+ * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class SyncedRepository
+{
+    private String groupId;
+
+    private String location;
+
+    private String protocol;
+
+    private String contactName;
+
+    private String contactMail;
+
+    public void setGroupId( String groupId )
+    {
+        this.groupId = groupId;
+    }
+
+    public String getGroupId()
+    {
+        return groupId;
+    }
+
+    public void setContactName( String contactName )
+    {
+        this.contactName = contactName;
+    }
+
+    public String getContactName()
+    {
+        return contactName;
+    }
+
+    public void setContactMail( String contactMail )
+    {
+        this.contactMail = contactMail;
+    }
+
+    public String getContactMail()
+    {
+        return contactMail;
+    }
+
+    public void setLocation( String location )
+    {
+        this.location = location;
+    }
+
+    public String getLocation()
+    {
+        return location;
+    }
+
+    public void setProtocol( String protocol )
+    {
+        this.protocol = protocol;
+    }
+
+    public String getProtocol()
+    {
+        return protocol;
+    }
+
+    public String toString()
+    {
+        return ReflectionToStringBuilder.toString( this );
+    }
+}
diff --git a/maven-meeper/src/test/java/org/apache/maven/archiva/meeper/ReaderTest.java b/maven-meeper/src/test/java/org/apache/maven/archiva/meeper/ReaderTest.java
new file mode 100644 (file)
index 0000000..bffb0db
--- /dev/null
@@ -0,0 +1,50 @@
+package org.apache.maven.archiva.meeper;
+
+/*
+ * 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.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class ReaderTest
+    extends TestCase
+{
+
+    private Reader reader;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        reader = new Reader( this.getClass().getClassLoader()
+            .getResourceAsStream( "org/apache/maven/archiva/meeper/sync.csv" ) );
+    }
+
+    public void testParse()
+        throws Exception
+    {
+        List repos = reader.parse();
+        assertEquals( 2, repos.size() );
+        for ( Iterator it = repos.iterator(); it.hasNext(); )
+        {
+            SyncedRepository repo = (SyncedRepository) it.next();
+            System.out.println( repo );
+        }
+    }
+
+}
diff --git a/maven-meeper/src/test/resources/org/apache/maven/archiva/meeper/sync.csv b/maven-meeper/src/test/resources/org/apache/maven/archiva/meeper/sync.csv
new file mode 100644 (file)
index 0000000..784e5c3
--- /dev/null
@@ -0,0 +1,3 @@
+"groupId","location","protocol","contactName","contactMail"
+"asm","maven@forge.objectweb.org:../../groups/maven/htdocs/maven2","rsync_ssh","EugeneKuleshov","eu@javatx.org"
+"ch.qos.logback","rsync://pixie.qos.ch/mvnrepo","rsync","Ceki Gulcu","ceki@qos.ch"