From 3c07daf9e5c32d541bafe1fe0fb8d5aefc845cb9 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Gonzalez Date: Thu, 21 Jun 2007 18:27:33 +0000 Subject: [PATCH] Add some code for a possible implementation for syncing repositories using only one file with the data git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@549579 13f79535-47bb-0310-9956-ffa450edef68 --- maven-meeper/pom.xml | 18 +++- .../apache/maven/archiva/meeper/Reader.java | 62 +++++++++++++ .../archiva/meeper/SyncedRepository.java | 92 +++++++++++++++++++ .../maven/archiva/meeper/ReaderTest.java | 50 ++++++++++ .../org/apache/maven/archiva/meeper/sync.csv | 3 + 5 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 maven-meeper/src/main/java/org/apache/maven/archiva/meeper/Reader.java create mode 100644 maven-meeper/src/main/java/org/apache/maven/archiva/meeper/SyncedRepository.java create mode 100644 maven-meeper/src/test/java/org/apache/maven/archiva/meeper/ReaderTest.java create mode 100644 maven-meeper/src/test/resources/org/apache/maven/archiva/meeper/sync.csv diff --git a/maven-meeper/pom.xml b/maven-meeper/pom.xml index a449f58cd..94a9a656c 100644 --- a/maven-meeper/pom.xml +++ b/maven-meeper/pom.xml @@ -15,7 +15,8 @@ ~ limitations under the License. --> - + org.apache.maven.archiva archiva-parent @@ -23,6 +24,19 @@ 4.0.0 maven-meeper - pom Maven Meeper + + + + org.apache.commons + commons-csv + 1.0-SNAPSHOT + + + commons-lang + commons-lang + 2.2 + + + 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 index 000000000..ea47a67d1 --- /dev/null +++ b/maven-meeper/src/main/java/org/apache/maven/archiva/meeper/Reader.java @@ -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 Carlos Sanchez + * @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 index 000000000..59e010761 --- /dev/null +++ b/maven-meeper/src/main/java/org/apache/maven/archiva/meeper/SyncedRepository.java @@ -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 Carlos Sanchez + * @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 index 000000000..bffb0db18 --- /dev/null +++ b/maven-meeper/src/test/java/org/apache/maven/archiva/meeper/ReaderTest.java @@ -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 index 000000000..784e5c302 --- /dev/null +++ b/maven-meeper/src/test/resources/org/apache/maven/archiva/meeper/sync.csv @@ -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" -- 2.39.5