maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mic...@apache.org
Subject cvs commit: maven-wagon/wagon-maven-bindings/src/main/java/org/apache/maven/wagon/bindings MavenRepositoryManager.java
Date Sun, 07 Dec 2003 15:00:01 GMT
michal      2003/12/07 07:00:01

  Added:       wagon-maven-bindings project.xml checkstyle.xml .cvsignore
                        notes.txt LICENSE.txt
               wagon-maven-bindings/src/test/test-data/mavenHomeLocal/proxies
                        http.properties
               wagon-maven-bindings/src/test/java/org/apache/maven/wagon/bindings
                        MavenRepositoryManagerTest.java
               wagon-maven-bindings/src/test/test-data/mavenHomeLocal/repositories
                        http_www_ibiblio_org_maven.properties
               wagon-maven-bindings/src/main/java/org/apache/maven/wagon/bindings
                        MavenRepositoryManager.java
  Log:
  Initial check-in.
  
  Revision  Changes    Path
  1.1                  maven-wagon/wagon-maven-bindings/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <project>
      <pomVersion>3</pomVersion>
      <id>wagon-maven-bindings</id>
      <groupId>wagon</groupId>
      <artifactId>wagon-maven-bindings</artifactId>
      <type>jar</type>
      <name>Wagon Maven Bindings</name>
      <currentVersion>1.0-beta-1</currentVersion>
      <description></description>
      <shortDescription>Wagon binding for Maven</shortDescription>
      <description>
        Allows to initialize Wagon Repository object from Maven configuration
        files.
      </description>
      <url>http://maven.apache.org/reference/plugins/artifact/</url>
      <siteDirectory>/www/maven.apache.org/reference/plugins/artifact/</siteDirectory>
  
      <package>org.apache.maven.wagon.providers.file</package>
      <inceptionYear>2003</inceptionYear>
  
  <url>http://maven.apache.org/wagon/wagon-api</url>
      <issueTrackingUrl>http://jira.codehaus.org/BrowseProject.jspa?id=10319</issueTrackingUrl>
      <repository>
          <connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven-wagon/wagon-maven-bindings</connection>
          <url>http://cvs.apache.org/viewcvs/maven-wagon/wagon-maven-bindings/</url>
      </repository>
  
      <versions>
          <version>
              <id>beta-1</id>
              <name>1.0-beta-1</name>
              <tag>HEAD</tag>
          </version>
      </versions>
  
  
      <developers>
          <developer>
              <name>Michal Maczka</name>
              <id>michal</id>
              <email>michal@dimatics.com</email>
              <organization>Dimatics</organization>
              <roles>
                  <role>Architect</role>
              </roles>
          </developer>
      </developers>
  
      <licenses>
          <license>
              <name>The Apache Software License, Version 1.1</name>
              <url>http://cvs.apache.org/viewcvs.cgi/*checkout*/maven/LICENSE.txt</url>
              <distribution>repo</distribution>
          </license>
      </licenses>
  
  
      <dependencies/>
  
      <build>
  
          <sourceDirectory>src/main/java</sourceDirectory>
          <unitTestSourceDirectory>src/test/java</unitTestSourceDirectory>
          <unitTest>
              <includes>
                  <include>**/*Test.java</include>
              </includes>
  
              <resources>
                  <resource>
                      <directory>src/test/test-data</directory>
                      <includes>
                          <include>**/*.xml</include>
                          <include>**/*.properties</include>
                          <include>**/*.txt</include>
                      </includes>
                  </resource>
              </resources>
          </unitTest>
  
  
      </build>
  
  
      <reports>
          <report>maven-jdepend-plugin</report>
          <report>maven-checkstyle-plugin</report>
          <report>maven-changes-plugin</report>
          <report>maven-changelog-plugin</report>
          <report>maven-file-activity-plugin</report>
          <report>maven-developer-activity-plugin</report>
          <report>maven-javadoc-plugin</report>
          <report>maven-jxr-plugin</report>
          <report>maven-junit-report-plugin</report>
          <report>maven-tasklist-plugin</report>
          <report>maven-pmd-plugin</report>
          <report>maven-simian-plugin</report>
          <report>maven-clover-plugin</report>
      </reports>
  
  
  </project>
  
  
  
  1.1                  maven-wagon/wagon-maven-bindings/checkstyle.xml
  
  Index: checkstyle.xml
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE module PUBLIC
      "-//Puppy Crawl//DTD Check Configuration 1.1//EN"
      "http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
  
  <!--
    Checkstyle checks configured for Maven.
  -->
  
  <module name="Checker">
  
      <!-- Checks that a package.html file exists for each package.     -->
      <!-- See http://checkstyle.sf.net/config_javadoc.html#PackageHtml -->
      <module name="PackageHtml"/>
  
      <!-- Checks whether files end with a new line.                        -->
      <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
      <module name="NewlineAtEndOfFile"/>
  
      <!-- Checks that property files contain the same keys.         -->
      <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
      <module name="Translation"/>
  
      <module name="TreeWalker">
  
          <property name="cacheFile" value="${checkstyle.cache.file}"/>
  
          <!-- ************************************************************** -->
          <!-- Checks that are different from the sun coding conventions ones -->
          <!-- ************************************************************** -->
          <module name="Header">
              <property name="headerFile" value="${basedir}/LICENSE.txt"/>
              <property name="ignoreLines" value="1,2,3,4,5,6"/>
          </module>
          <property name="tabWidth" value="4"/>
          <module name="LeftCurly">
            <property name="option" value="nl"/>
          </module>
          <module name="RightCurly">
            <property name="option" value="alone"/>
          </module>
          <module name="LineLength">
            <property name="max" value="132"/>
          </module>
          <module name="MethodLength">
            <property name="max" value="175"/>
          </module>
          <!-- No Paren pad check
          <module name="ParenPad"/>
          -->
          <module name="ConstantName">
            <property name="format" value="log|^[a-zA-Z][a-zA-Z0-9_]*$"/>
          </module>
          
          <!-- ************************************************************** -->
          <!-- Default Sun coding conventions checks                          -->
          <!-- ************************************************************** -->
  
          <!-- Checks for Javadoc comments.                     -->
          <!-- See http://checkstyle.sf.net/config_javadoc.html -->
          <module name="JavadocMethod"/>
          <module name="JavadocType"/>
          <module name="JavadocVariable"/>
  
  
          <!-- Checks for Naming Conventions.                  -->
          <!-- See http://checkstyle.sf.net/config_naming.html -->
          <module name="LocalFinalVariableName"/>
          <module name="LocalVariableName"/>
          <module name="MethodName"/>
          <module name="PackageName"/>
          <module name="ParameterName"/>
          <module name="StaticVariableName"/>
          <module name="TypeName"/>
          <module name="MemberName"/>
  
          <!-- Checks for imports                              -->
          <!-- See http://checkstyle.sf.net/config_import.html -->
          <module name="AvoidStarImport"/>
          <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
          <module name="RedundantImport"/>
          <module name="UnusedImports"/>
  
  
          <!-- Checks for Size Violations.                    -->
          <!-- See http://checkstyle.sf.net/config_sizes.html -->
          <module name="FileLength"/>
          <module name="ParameterNumber"/>
  
  
          <!-- Checks for whitespace                               -->
          <!-- See http://checkstyle.sf.net/config_whitespace.html -->
          <module name="EmptyForIteratorPad"/>
          <module name="NoWhitespaceAfter"/>
          <module name="NoWhitespaceBefore"/>
          <module name="OperatorWrap"/>
          <module name="TabCharacter"/>
          <module name="WhitespaceAfter"/>
          <module name="WhitespaceAround"/>
  
  
          <!-- Modifier Checks                                    -->
          <!-- See http://checkstyle.sf.net/config_modifiers.html -->
          <module name="ModifierOrder"/>
          <module name="RedundantModifier"/>
  
  
          <!-- Checks for blocks. You know, those {}'s         -->
          <!-- See http://checkstyle.sf.net/config_blocks.html -->
          <module name="AvoidNestedBlocks"/>
          <module name="EmptyBlock"/>
          
          <module name="NeedBraces"/>
  
  
          <!-- Checks for common coding problems               -->
          <!-- See http://checkstyle.sf.net/config_coding.html -->
          <module name="AvoidInlineConditionals"/>
          <module name="DoubleCheckedLocking"/>    <!-- MY FAVOURITE -->
          <module name="EmptyStatement"/>
          <module name="EqualsHashCode"/>
          <module name="HiddenField"/>
          <module name="IllegalInstantiation"/>
          <module name="InnerAssignment"/>
          <module name="MagicNumber"/>
          <module name="MissingSwitchDefault"/>
          <!--<module name="RedundantThrows"/>-->
          <module name="SimplifyBooleanExpression"/>
          <module name="SimplifyBooleanReturn"/>
  
          <!-- Checks for class design                         -->
          <!-- See http://checkstyle.sf.net/config_design.html -->
          <!--<module name="DesignForExtension"/>-->
          <module name="FinalClass"/>
          <module name="HideUtilityClassConstructor"/>
          <module name="InterfaceIsType"/>
          <module name="VisibilityModifier"/>
  
  
          <!-- Miscellaneous other checks.                   -->
          <!-- See http://checkstyle.sf.net/config_misc.html -->
          <module name="ArrayTypeStyle"/>
          <!-- <module name="FinalParameters"/> -->
          <module name="GenericIllegalRegexp">
              <property name="format" value="\s+$"/>
              <property name="message" value="Line has trailing spaces."/>
          </module>
          <module name="TodoComment"/>
          <module name="UpperEll"/>
  
      </module>
  
  </module>
  
  
  
  1.1                  maven-wagon/wagon-maven-bindings/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  *.log
  target
  .classpath
  .project
  default.lst
  test.out
  default.ajsym
  *.iml
  *.ipr
  *.iws
  
  
  
  1.1                  maven-wagon/wagon-maven-bindings/notes.txt
  
  Index: notes.txt
  ===================================================================
  ****
  What are wagon-maven-bindings?
  
  
  It's an attempt to define relations between maven/plexus and wagon's beans:
  - Repository 
  - AutheticationInfo
  - ProxyInfo
  
  
  I have following thoughts:
  
  a) Proxy server settings are individual per each developer and AFIK
  (correct me if I am wrong) they can be different per each protocol.
  b) It will be nice to separate POM (project.xml + set of properties files)
  from the definition of auth info and proxy server
      so those definitions can be shared among many projects (I know it is
  also currently possible via ${user.home}/build.properties)
  
  My naive thoughts are that maybe (for Maven/Plexus) following
  organization of directories will be appropriate( I hope that the example is
  clear):
  
  ${maven.home}
                         /proxy-servers
                               http.properties)
                               ssh.properties
                               ftp.properties
                               https.properties
                        /auth-info
                            http_www_ibiblio_org_maven.properties
  
                            ftp_ftp_mycompany_com_repo.properties
  
  -- http.properties
  username=michal
  password=proxypassword
  host=www.apache.org
  port=100
  
  
  -- http_www_ibiblio_org_maven.properties
  username=michal
  password=ihatejelly
  passphrase=ireallydo
  privatekey=/home/michal/key
  group=power_users
  
  
  
  
  
  wagon-maven-binding project is containing classes for unmarshalling such
  configuration files.
  
  This means that users will be able to define (as they are used to do) per
  project
  
  maven.repo.remote=http://www.ibiblio.org/maven
  
  
  and only when extra information for the repository will be needed (e.g. auth
  info) they will be forced to edit some more configuration files (which will
  be centralized for all project)
  
  Maven before downloading from any repository will check if transfer over
  given protocol should go via proxy server
  and if auth info should be used.
  
  
  
  
  
  1.1                  maven-wagon/wagon-maven-bindings/LICENSE.txt
  
  Index: LICENSE.txt
  ===================================================================
  
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Maven", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  
  
  1.1                  maven-wagon/wagon-maven-bindings/src/test/test-data/mavenHomeLocal/proxies/http.properties
  
  Index: http.properties
  ===================================================================
  username=michal
  password=proxypassword
  host=www.apache.org
  port=100
  
  
  1.1                  maven-wagon/wagon-maven-bindings/src/test/java/org/apache/maven/wagon/bindings/MavenRepositoryManagerTest.java
  
  Index: MavenRepositoryManagerTest.java
  ===================================================================
  package org.apache.maven.wagon.bindings;
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are met: 1.
   * Redistributions of source code must retain the above copyright notice, this
   * list of conditions and the following disclaimer. 2. Redistributions in
   * binary form must reproduce the above copyright notice, this list of
   * conditions and the following disclaimer in the documentation and/or other
   * materials provided with the distribution. 3. The end-user documentation
   * included with the redistribution, if any, must include the following
   * acknowledgment: "This product includes software developed by the Apache
   * Software Foundation (http://www.apache.org/)." Alternately, this
   * acknowledgment may appear in the software itself, if and wherever such
   * third-party acknowledgments normally appear. 4. The names "Apache" and
   * "Apache Software Foundation" and "Apache Maven" must not be used to endorse
   * or promote products derived from this software without prior written
   * permission. For written permission, please contact apache@apache.org. 5.
   * Products derived from this software may not be called "Apache", "Apache
   * Maven", nor may "Apache" appear in their name, without prior written
   * permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many individuals
   * on behalf of the Apache Software Foundation. For more information on the
   * Apache Software Foundation, please see <http://www.apache.org/> .
   *
   * ====================================================================
   */
  
  import java.io.File;
  import java.net.URL;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  
  import junit.framework.TestCase;
  
  import org.apache.maven.wagon.AuthenticationInfo;
  import org.apache.maven.wagon.ProxyInfo;
  import org.apache.maven.wagon.Repository;
  
  
  /**
   * Implementation of common facilties for Wagon providers.
   *
   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
   * @version $Id: MavenRepositoryManagerTest.java,v 1.1 2003/12/07 15:00:01 michal Exp $
   */
  public class MavenRepositoryManagerTest extends TestCase
  {
  
      private MavenRepositoryManager repositoryManager;
  
      /*
       * @see TestCase#setUp()
       */
      protected void setUp() throws Exception
      {
          super.setUp();
          repositoryManager = new MavenRepositoryManager();
  
      }
  
  
  
     public void testGetAuthenticationInfoFile()
     {
         String filename = repositoryManager.getAuthenticationInfoFile("http://www.ibiblio.org/maven",
"test") ;
         assertEquals( "test" + File.separator + "http_www_ibiblio_org_maven.properties",
filename );
  
         filename = repositoryManager.getAuthenticationInfoFile("http://www.ibiblio.org/maven",
"test" + File.separator) ;
         assertEquals( "test" + File.separator + "http_www_ibiblio_org_maven.properties",
filename );
     }
  
  
      public void testConfigure()
      {
           final Map context = new HashMap();
           final String repos = "http://www.ibiblio.org/maven";
           context.put("maven.repo.remote", repos);
           
           
           File mavenHomeLocal = new File ( System.getProperty( "basedir" ), "src/test/test-data/mavenHomeLocal"
) ;
           context.put("maven.home.local", mavenHomeLocal.getAbsolutePath() );
  
           repositoryManager.configure( context  );
  
          final Set set = repositoryManager.getRepositories();
          assertEquals( 1, set.size() );
          for ( Iterator iterator = set.iterator(); iterator.hasNext(); )
          {
              final Repository repository = ( Repository ) iterator.next();
              System.out.println( repository.getUrl() );
              assertEquals( repository.getUrl(), "http://www.ibiblio.org/maven" );
              assertEquals( repository.getProtocol(), "http");
              assertEquals( repository.getHost(), "www.ibiblio.org");
              assertEquals( repository.getBasedir(), "maven");
  
              final AuthenticationInfo authenticationInfo = repository.getAuthenticationInfo();
              assertNotNull( authenticationInfo );
  
              assertEquals( "michal", authenticationInfo.getUserName() );
              assertEquals( "ihatejelly", authenticationInfo.getPassword() );
              assertEquals( "ireallydo", authenticationInfo.getPassphrase() );
              assertEquals( "/home/michal/key", authenticationInfo.getPrivateKey() );
              assertEquals( "power_users", authenticationInfo.getGroup() );
              
              final ProxyInfo proxyInfo = repository.getProxyInfo();
              assertNotNull( proxyInfo );
              
              assertEquals( "michal", proxyInfo.getUserName() );
              assertEquals( "proxypassword", proxyInfo.getPassword() );            
              assertEquals( "www.apache.org", proxyInfo.getHost() );
              assertEquals( 100 , proxyInfo.getPort() );
              
              
          }
  
      }
  
  }
  
  
  
  1.1                  maven-wagon/wagon-maven-bindings/src/test/test-data/mavenHomeLocal/repositories/http_www_ibiblio_org_maven.properties
  
  Index: http_www_ibiblio_org_maven.properties
  ===================================================================
  username=michal
  password=ihatejelly
  passphrase=ireallydo
  privatekey=/home/michal/key
  group=power_users
  
  
  1.1                  maven-wagon/wagon-maven-bindings/src/main/java/org/apache/maven/wagon/bindings/MavenRepositoryManager.java
  
  Index: MavenRepositoryManager.java
  ===================================================================
  package org.apache.maven.wagon.bindings;
  
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are met: 1.
   * Redistributions of source code must retain the above copyright notice, this
   * list of conditions and the following disclaimer. 2. Redistributions in
   * binary form must reproduce the above copyright notice, this list of
   * conditions and the following disclaimer in the documentation and/or other
   * materials provided with the distribution. 3. The end-user documentation
   * included with the redistribution, if any, must include the following
   * acknowledgment: "This product includes software developed by the Apache
   * Software Foundation (http://www.apache.org/)." Alternately, this
   * acknowledgment may appear in the software itself, if and wherever such
   * third-party acknowledgments normally appear. 4. The names "Apache" and
   * "Apache Software Foundation" and "Apache Maven" must not be used to endorse
   * or promote products derived from this software without prior written
   * permission. For written permission, please contact apache@apache.org. 5.
   * Products derived from this software may not be called "Apache", "Apache
   * Maven", nor may "Apache" appear in their name, without prior written
   * permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many individuals
   * on behalf of the Apache Software Foundation. For more information on the
   * Apache Software Foundation, please see <http://www.apache.org/> .
   *
   * ====================================================================
   */
  
  import org.apache.maven.wagon.AuthenticationInfo;
  import org.apache.maven.wagon.PathUtils;
  import org.apache.maven.wagon.ProxyInfo;
  import org.apache.maven.wagon.Repository;
  import org.apache.maven.wagon.managers.RepositoryManager;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.Map;
  import java.util.Properties;
  import java.util.StringTokenizer;
  
  /**
   * Mapping between Maven's configuration files (including POM) and Wagon's beans:
   * Repository, ProxyInfo, AuthenticationInfo
   * 
   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
   * @version $Id: MavenRepositoryManager.java,v 1.1 2003/12/07 15:00:01 michal Exp $
   */
  public class MavenRepositoryManager extends RepositoryManager
  {
  
      public void configure( final InputStream inputStream ) throws IOException
      {
          final Properties context = new Properties();
          context.load( inputStream );
          configure( context );
  
      }
  
      public void configure( final Map context )
      {
          String repos = ( String ) context.get( "maven.repo.remote" );
          repos = repos.trim();
          if ( repos == null || repos.length() == 0 )
          {
              System.out.println( "No remote repository was defined." );
              return;
          }
  
          final String mavenHomeLocal = ( String ) context.get( "maven.home.local" );
          final StringTokenizer tokenizer = new StringTokenizer( repos, "," );
          while ( tokenizer.hasMoreTokens() )
          {
  
              final String url = tokenizer.nextToken().trim();
              final Repository repository = buildRepository( url, mavenHomeLocal );
              add( repository );
          }
  
      }
  
      private Repository buildRepository( final String url, final String mavenHomeLocal )
      {
          final Repository repository = new Repository();
          repository.setName( url );
          repository.setUrl( url );
          repository.setAuthenticationInfo( buildAuthenticationInfo( url, mavenHomeLocal )
);
          repository.setProxyInfo( buildProxyInfo( url, mavenHomeLocal ) );
          return repository;
  
      }
  
      private ProxyInfo buildProxyInfo( final String url, final String mavenHomeLocal )
      {
          final String protocol = PathUtils.protocol( url );
          final String basedir = mavenHomeLocal + File.separator + "proxies";
          final Properties properties = new Properties();
          // read file like ${maven.home.local}/proxies/http.properties
          final File file = new File( basedir, protocol + ".properties" );
          if (! file.exists())
          {
              return null;
          }
          try
          {
              final InputStream inputStream = new FileInputStream( file );
              properties.load( inputStream );
          }
          catch ( IOException e )
          {
              e.printStackTrace();
              return null;
          }
  
          final ProxyInfo proxyInfo = new ProxyInfo();
          final String userName =
                  ( String ) properties.get( "username" );
          final String password =
                  ( String ) properties.get( "password" );
          final String host =
                  ( String ) properties.get( "host" );
          final String port =
                  ( String ) properties.get( "port" );
          proxyInfo.setUserName( userName );
          proxyInfo.setPassword( password );
          proxyInfo.setHost( host );
          try
          {
             proxyInfo.setPort( Integer.parseInt(port) );
          }
          catch(Exception e)
          {
              //at the moment just ignored
          }
  
          return proxyInfo;
  
      }
  
      private AuthenticationInfo buildAuthenticationInfo( final String url, final String mavenHomeLocal
 )
      {
          final String basedir = mavenHomeLocal + File.separator + "repositories";
          final File file = new File( getAuthenticationInfoFile( url, basedir ) );
       
          if ( !file.exists() )
          {
          	System.out.println("File: " + file + " does not exist" );
          	return null;
          }
          System.out.println("Reading from: " + file);
          final Properties properties = new Properties();
          try
          {
              final InputStream inputStream = new FileInputStream( file );
              properties.load( inputStream );
          }
          catch ( IOException e )
          {
              e.printStackTrace();
              return null;
          }
  
          final AuthenticationInfo authenticationInfo = new AuthenticationInfo();
          final String userName =
                  ( String ) properties.get( "username" );
          final String password =
                  ( String ) properties.get( "password" );
          final String passphrase =
                  ( String ) properties.get( "passphrase" );
          final String privateKey =
                  ( String ) properties.get( "privatekey" );
          final String remoteGroup =
                  ( String ) properties.get( "group" );
  
          authenticationInfo.setUserName( userName );
          authenticationInfo.setPassword( password );
          authenticationInfo.setPassphrase( passphrase );
          authenticationInfo.setPrivateKey( privateKey );
          authenticationInfo.setGroup( remoteGroup );
  
          return authenticationInfo;
  
      }
  
      protected String getAuthenticationInfoFile( final String url, final String basedir )
      {
          String filename = url.replace( '/', '_' );
          filename = filename.replace( ':', '_' );
          filename = filename.replaceAll( "__", "_" );
          filename = filename.replaceAll( "__", "_" );
          filename = filename.replace( '.', '_' );
          String retValue;
          if ( !basedir.endsWith( File.separator ) )
          {
              retValue = basedir + File.separator + filename + ".properties";
          }
          else
          {
              retValue = basedir + filename + ".properties";
  
          }
          return retValue;
      }
  
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-cvs-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-cvs-help@maven.apache.org


Mime
View raw message