Author: ogusakov Date: Thu Dec 25 22:50:17 2008 New Revision: 729455 URL: http://svn.apache.org/viewvc?rev=729455&view=rev Log: [MERCURY-65] new syntax works, still need IT for pom attribute
Added: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Auth.java (with props) maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Repo.java (with props) maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/Messages.properties - copied, changed from r729251, maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Messages.properties Removed: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/mercury-build.xml maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Messages.properties Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/build.xml maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/AbstractAntTask.java maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Config.java maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Dep.java maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/WriteTask.java maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/antlib.xml maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/test/java/org/apache/maven/mercury/ant/tasks/MecuryAntTest.java Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/build.xml URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/build.xml?rev=729455&r1=729454&r2=729455&view=diff ============================================================================== --- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/build.xml (original) +++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/build.xml Thu Dec 25 22:50:17 2008 @@ -21,7 +21,12 @@ <property name="local.repo.dir" value="${basedir}/target/test-repo"/> <delete dir="${local.repo.dir}"/> <mkdir dir="${local.repo.dir}"/> + + <taskdef resource="org/apache/maven/mercury/ant/tasks/antlib.xml"/> + <!-- + | The most complex way to configure repositories + --> <merc:config id="conf"> <merc:repo id="localRepo" dir="${local.repo.dir}"/> <merc:repo id="central" url="http://repo1.maven.org/maven2"/> @@ -79,7 +84,6 @@ <javac srcdir="${src}" destdir="${target}" classpathref="compile-path" - debug="on" source="${compiler.version}" target="${compiler.version}" /> @@ -112,7 +116,6 @@ <javac srcdir="${src}" destdir="${target}" classpathref="compile-path-auth" - debug="on" source="${compiler.version}" target="${compiler.version}" /> @@ -183,7 +186,6 @@ <target name="compile-thin-path" depends="init"> <javac srcdir="${src}" destdir="${target}" - debug="on" source="${compiler.version}" target="${compiler.version}" > @@ -197,19 +199,50 @@ <target name="compile-thin-path-2" depends="init"> - <path id="thin-path-2"> - <merc:dep> + <path id="thin-path-2"> + <merc:dep> <merc:dependency name="asm:asm:3.0"/> </merc:dep> </path> - <javac srcdir="${src}" + <javac srcdir="${src}" destdir="${target}" - classpathref="thin-path-2" - debug="on" + classpathref="thin-path-2" source="${compiler.version}" target="${compiler.version}" /> </target> + + <target name="compile-fail" depends="init"> + <javac srcdir="${src}" + destdir="${target}" + source="${compiler.version}" + target="${compiler.version}" + /> + </target> + + + + <target name="compile-thin-path-3" depends="init"> + + <repository id="localPath3" dir="${basedir}/target/path-3"/> + + <repository id="remotePath3" url="http://localhost:${repo.port}/maven2"> + <auth name="foo" pass="bar"/> + </repository> + + <javac srcdir="${src}" + destdir="${target}" + source="${compiler.version}" + target="${compiler.version}" + > + <classpath> + <deps> + <dependency name="asm:asm:3.0"/> + </deps> + </classpath> + </javac> + + </target> </project> \ No newline at end of file Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/AbstractAntTask.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/AbstractAntTask.java?rev=729455&r1=729454&r2=729455&view=diff ============================================================================== --- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/AbstractAntTask.java (original) +++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/AbstractAntTask.java Thu Dec 25 22:50:17 2008 @@ -13,7 +13,7 @@ public class AbstractAntTask extends Task { - private static final Language _lang = new DefaultLanguage( ResolveTask.class ); + private static final Language LANG = new DefaultLanguage( ResolveTask.class ); protected boolean _failOnError = true; @@ -39,17 +39,17 @@ if ( configId == null ) { - config = new Config( null, null ); + config = Config.getDefaultConfig( project ); } else { Object so = project.getReference( configId ); if ( so == null ) - throw new Exception( _lang.getMessage( "config.id.object.null", configId ) ); + throw new Exception( LANG.getMessage( "config.id.object.null", configId ) ); if ( !Config.class.isAssignableFrom( so.getClass() ) ) - throw new Exception( _lang.getMessage( "config.id.object.wrong", configId, so.getClass().getName() ) ); + throw new Exception( LANG.getMessage( "config.id.object.wrong", configId, so.getClass().getName() ) ); config = (Config) so; } Added: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Auth.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Auth.java?rev=729455&view=auto ============================================================================== --- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Auth.java (added) +++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Auth.java Thu Dec 25 22:50:17 2008 @@ -0,0 +1,80 @@ +package org.apache.maven.mercury.ant.tasks; + +import java.io.File; +import java.io.IOException; + +import org.apache.maven.mercury.transport.api.Credentials; +import org.apache.maven.mercury.util.FileUtil; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.codehaus.plexus.lang.DefaultLanguage; +import org.codehaus.plexus.lang.Language; + +/** + * @author Oleg Gusakov + * @version $Id$ + */ +public class Auth + extends AbstractDataType +{ + private static final Language LANG = new DefaultLanguage( Auth.class ); + + private static final String DEFAULT_AUTH_ID = System.getProperty( "mercury.default.auth.id" + , "mercury.default.auth.id."+System.currentTimeMillis() + ); + String _name; + + String _pass; + + String _certfile; + + public void setName( String name ) + { + this._name = name; + } + + public void setPass( String pass ) + { + this._pass = pass; + } + + public void setCertfile( String certfile ) + { + this._certfile = certfile; + } + + protected static Auth findAuth( Project project, String authId ) + { + Object ao = authId == null ? project.getReference( DEFAULT_AUTH_ID ) : project.getReference( authId ); + + if( ao == null ) + return null; + + return (Auth) ao; + } + + protected Credentials createCredentials() + { + Credentials cred = null; + + if ( _certfile != null ) + { + File cf = new File( _certfile ); + if ( !cf.exists() ) + throw new BuildException( LANG.getMessage( "config.no.cert.file", _certfile ) ); + + try + { + cred = new Credentials( FileUtil.readRawData( cf ), _name, _pass ); + } + catch ( IOException e ) + { + throw new BuildException( e ); + } + } + else + cred = new Credentials( _name, _pass ); + + return cred; + } +} Propchange: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Auth.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Auth.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Config.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Config.java?rev=729455&r1=729454&r2=729455&view=diff ============================================================================== --- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Config.java (original) +++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Config.java Thu Dec 25 22:50:17 2008 @@ -1,32 +1,12 @@ package org.apache.maven.mercury.ant.tasks; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.maven.mercury.MavenDependencyProcessor; -import org.apache.maven.mercury.builder.api.DependencyProcessor; -import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes; -import org.apache.maven.mercury.crypto.api.StreamVerifierFactory; -import org.apache.maven.mercury.crypto.pgp.PgpStreamVerifierFactory; -import org.apache.maven.mercury.crypto.sha.SHA1VerifierFactory; + import org.apache.maven.mercury.repository.api.Repository; -import org.apache.maven.mercury.repository.local.m2.LocalRepositoryM2; -import org.apache.maven.mercury.repository.remote.m2.RemoteRepositoryM2; -import org.apache.maven.mercury.transport.api.Credentials; -import org.apache.maven.mercury.transport.api.Server; -import org.apache.maven.mercury.util.FileUtil; import org.apache.maven.mercury.util.Util; import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.Property; +import org.apache.tools.ant.Project; import org.codehaus.plexus.lang.DefaultLanguage; import org.codehaus.plexus.lang.Language; @@ -35,13 +15,17 @@ * @version $Id$ */ public class Config - extends AbstractDataType +extends AbstractDataType { - private static final Language _lang = new DefaultLanguage( Config.class ); + private static final Language LANG = new DefaultLanguage( Config.class ); private static final String DEFAULT_LOCAL_DIR = System.getProperty( "user.home" )+"/.m2/repository"; - private static final String DEFAULT_CENTRAL_URL = System.getProperty( "maven.central.url", "http://repo1.maven.org/maven2" ); + private static final String DEFAULT_CENTRAL_URL = System.getProperty( "mercury.central.url", "http://repo1.maven.org/maven2" ); + + private static final String DEFAULT_CONFIG_ID = System.getProperty( "mercury.default.config.id" + , "mercury.default.config.id."+System.currentTimeMillis() + ); Collection<Repo> _repos; @@ -49,9 +33,12 @@ Collection<Repository> _repositories; - public Config( String localDir, String remoteUrl ) + public Config() + { + } + + private Config( String localDir, String remoteUrl ) { - Repo local = createRepo(); local.setId( "defaultLocalRepo" ); local.setDir( localDir == null ? DEFAULT_LOCAL_DIR : localDir ); @@ -59,11 +46,6 @@ Repo central = createRepo(); central.setId( "central" ); central.setUrl( remoteUrl == null ? DEFAULT_CENTRAL_URL : remoteUrl ); - - } - - public Config() - { } public Collection<Repository> getRepositories() @@ -83,380 +65,67 @@ return _repositories; } - private static Credentials createCredentials( Auth a ) - { - Credentials cred = null; - - if ( a._certfile != null ) - { - File cf = new File( a._certfile ); - if ( !cf.exists() ) - throw new BuildException( _lang.getMessage( "config.no.cert.file", a._certfile ) ); - - try - { - cred = new Credentials( FileUtil.readRawData( cf ), a._name, a._pass ); - } - catch ( IOException e ) - { - throw new BuildException( e ); - } - } - else - cred = new Credentials( a._name, a._pass ); - - return cred; - } - public Repo createRepo() { - if ( _repos == null ) - _repos = new ArrayList<Repo>( 4 ); - - Repo r = new Repo(); + Repo r = new Repo(true); - _repos.add( r ); + listRepo( r ); return r; } - public Auth createAuth() + protected void listRepo( Repo repo ) { - if ( _auths == null ) - _auths = new ArrayList<Auth>( 4 ); - - Auth a = new Auth(); - - _auths.add( a ); + if ( _repos == null ) + _repos = new ArrayList<Repo>( 4 ); - return a; + _repos.add( repo ); } - - public class Repo - extends AbstractDataType + + public static void addDefaultRepository( Project project, Repo repo ) { - String _dir; - - String _url; - - String _type; - - String _authid; - - String _proxyauthid; - - boolean _readable = true; - - boolean _writeable = false; - - List<Verify> _writeVerifiers; - - List<Verify> _readVerifiers; - - public void setReadable( boolean readable ) - { - this._readable = readable; - } - - public void setWriteable( boolean writeable ) - { - this._writeable = writeable; - } - - public void setUrl( String url ) - { - this._url = url; - } - - public void setDir( String dir ) - { - this._dir = dir; - } - - public void setType( String type ) - { - this._type = type; - } - - public void setAuthid( String authid ) - { - this._authid = authid; - } - - public void setProxyauthid( String proxyauthid ) - { - this._proxyauthid = proxyauthid; - } - - boolean isLocal() - { - return _dir != null; - } - - public Verify createVerifywrite() - { - if ( _writeVerifiers == null ) - _writeVerifiers = new ArrayList<Verify>( 2 ); - - Verify v = new Verify(); - - _writeVerifiers.add( v ); - - return v; - } - - public Verify createVerifyread() - { - if ( _readVerifiers == null ) - _readVerifiers = new ArrayList<Verify>( 2 ); - - Verify v = new Verify(); - - _readVerifiers.add( v ); + Object co = project.getReference( DEFAULT_CONFIG_ID ); - return v; - } - - private Set<StreamVerifierFactory> getVerifiers( List<Verify> vlist ) - { - if ( Util.isEmpty( vlist ) ) - return null; - - Set<StreamVerifierFactory> facs = new HashSet<StreamVerifierFactory>( vlist.size() ); - - for ( Verify v : vlist ) - facs.add( v.getVerifierFactory() ); - - return facs; - - } - - public Repository getRepository() + if( co == null ) { - Repository r = null; - - if ( isLocal() ) - { - DependencyProcessor dp = new MavenDependencyProcessor(); - - Server server; - try - { - server = new Server( getId(), new File( _dir ).toURL() ); - - server.setReaderStreamVerifierFactories( getVerifiers( _readVerifiers ) ); - server.setWriterStreamVerifierFactories( getVerifiers( _writeVerifiers ) ); - } - catch ( MalformedURLException e ) - { - throw new BuildException( e ); - } - - r = new LocalRepositoryM2( server, dp ); - } - else - { - DependencyProcessor dp = new MavenDependencyProcessor(); - - Server server; - try - { - server = new Server( getId(), new URL( _url ) ); - - server.setReaderStreamVerifierFactories( getVerifiers( _readVerifiers ) ); - server.setWriterStreamVerifierFactories( getVerifiers( _writeVerifiers ) ); - } - catch ( MalformedURLException e ) - { - throw new BuildException( e ); - } - - if ( _authid != null ) - { - Auth au = null; - - if ( _auths == null ) - throw new BuildException( _lang.getMessage( "config.no.auths", _authid ) ); - - for ( Auth a : _auths ) - if ( _authid.equals( a.getId() ) ) - au = a; - - if ( au == null ) - throw new BuildException( _lang.getMessage( "config.no.auth.for.id", _authid ) ); - - Credentials serverCred = createCredentials( au ); - - server.setServerCredentials( serverCred ); - } - - if ( _proxyauthid != null ) - { - Auth au = null; - - if ( _auths == null ) - throw new BuildException( _lang.getMessage( "config.no.proxy.auths", _proxyauthid ) ); - - for ( Auth a : _auths ) - if ( _proxyauthid.equals( a.getId() ) ) - au = a; - - if ( au == null ) - throw new BuildException( _lang.getMessage( "config.no.proxy.auth.for.id", _proxyauthid ) ); - - Credentials proxyCred = createCredentials( au ); - - server.setProxyCredentials( proxyCred ); - - } - - server.setReaderStreamVerifierFactories( getVerifiers( _readVerifiers ) ); - server.setWriterStreamVerifierFactories( getVerifiers( _writeVerifiers ) ); - - r = new RemoteRepositoryM2( server, dp ); - - } - - return r; + co = new Config(); + + project.addReference( DEFAULT_CONFIG_ID, co ); } - + + Config config = (Config) co; + + config.listRepo( repo ); } - - public class Auth - extends AbstractDataType + + public static Config getDefaultConfig( Project project ) { - String _name; - - String _pass; - - String _certfile; - - public void setName( String name ) - { - this._name = name; - } - - public void setPass( String pass ) + Object co = project.getReference( DEFAULT_CONFIG_ID ); + if( co == null ) { - this._pass = pass; - } - - public void setCertfile( String certfile ) - { - this._certfile = certfile; + co = new Config( null, null ); + + project.addReference( DEFAULT_CONFIG_ID, co ); } + + Config config = (Config) co; + + return config; } - public class Verify - extends AbstractDataType + public Auth createAuth() { - public static final String PGP = "pgp"; - - public static final String SHA1 = "sha1"; - - String _type; - - boolean _lenient = true; - - boolean _sufficient = false; - - Map<String, String> _properties; - - public void setType( String type ) - { - this._type = type; - } - - public void setLenient( boolean lenient ) - { - this._lenient = lenient; - } - - public void setSufficient( boolean sufficient ) - { - this._sufficient = sufficient; - } - - public void addConfiguredProperty( Property property ) - { - if ( _properties == null ) - _properties = new HashMap<String, String>( 4 ); - - _properties.put( property.getName(), property.getValue() ); - } + if ( _auths == null ) + _auths = new ArrayList<Auth>( 4 ); - public StreamVerifierFactory getVerifierFactory() - throws BuildException - { - if ( _type == null ) - throw new BuildException( _lang.getMessage( "config.repo.verifier.no.type" ) ); + Auth a = new Auth(); - if ( _properties == null || _properties.isEmpty() ) - throw new BuildException( _lang.getMessage( "config.repo.verifier.no.properties", _type ) ); + _auths.add( a ); - if ( PGP.equals( _type ) ) - { - String keyRing = _properties.get( "keyring" ); - - if ( keyRing == null ) - throw new BuildException( _lang.getMessage( "config.repo.verifier.pgp.no.keyring" ) ); - - String pass = _properties.get( "pass" ); - - if ( pass == null ) // reader configuration - { - try - { - PgpStreamVerifierFactory fac = - new PgpStreamVerifierFactory( - new StreamVerifierAttributes( - PgpStreamVerifierFactory.DEFAULT_EXTENSION, - _lenient, _sufficient ), - FileUtil.toStream( keyRing ) ); - return fac; - } - catch ( Exception e ) - { - throw new BuildException( e ); - } - } - else - // writer configuration - { - String keyId = _properties.get( "key" ); - - if ( keyId == null || keyId.length() != 16 ) - throw new BuildException( _lang.getMessage( "config.repo.verifier.pgp.bad.keyid", keyId, - keyRing ) ); - - try - { - PgpStreamVerifierFactory fac = - new PgpStreamVerifierFactory( - new StreamVerifierAttributes( - PgpStreamVerifierFactory.DEFAULT_EXTENSION, - _lenient, _sufficient ), - FileUtil.toStream( keyRing ), keyId, pass ); - return fac; - } - catch ( Exception e ) - { - throw new BuildException( e ); - } - - } - } - else if ( SHA1.equals( _type ) ) - { - SHA1VerifierFactory fac = - new SHA1VerifierFactory( new StreamVerifierAttributes( SHA1VerifierFactory.DEFAULT_EXTENSION, - _lenient, _sufficient ) ); + return a; + } - return fac; - } + //====================================================================================== - throw new BuildException( _lang.getMessage( "config.repo.verifier.bad.type", _type ) ); - } - } } Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Dep.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Dep.java?rev=729455&r1=729454&r2=729455&view=diff ============================================================================== --- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Dep.java (original) +++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Dep.java Thu Dec 25 22:50:17 2008 @@ -33,8 +33,8 @@ extends AbstractDataType implements ResourceCollection { - private static final Language _lang = new DefaultLanguage( Dep.class ); - private static final IMercuryLogger _log = MercuryLoggerManager.getLogger( Dep.class ); + private static final Language LANG = new DefaultLanguage( Dep.class ); + private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( Dep.class ); private List<Dependency> _dependencies; @@ -59,7 +59,7 @@ for ( Dependency d : _dependencies ) { if( d._amd == null ) - throw new IllegalArgumentException( _lang.getMessage( "dep.dependency.name.mandatory" ) ); + throw new IllegalArgumentException( LANG.getMessage( "dep.dependency.name.mandatory" ) ); if( Util.isEmpty( d._pom )) res.add( d._amd ); @@ -112,7 +112,7 @@ this._pom = pom; if( _amd == null ) - throw new UnsupportedOperationException( _lang.getMessage( "dep.dependency.pom.needs.name", pom ) ); + throw new UnsupportedOperationException( LANG.getMessage( "dep.dependency.pom.needs.name", pom ) ); } } @@ -149,11 +149,11 @@ ArtifactResults aRes = vr.readArtifacts( res ); if ( aRes == null ) - throw new BuildException( _lang.getMessage( "resolve.cannot.read", config.getId(), res.toString() ) ); + throw new BuildException( LANG.getMessage( "resolve.cannot.read", config.getId(), res.toString() ) ); if ( aRes == null || aRes.hasExceptions() ) { - throw new Exception( _lang.getMessage( "vr.error", aRes.getExceptions().toString() ) ); + throw new Exception( LANG.getMessage( "vr.error", aRes.getExceptions().toString() ) ); } if ( !aRes.hasResults() ) @@ -234,7 +234,7 @@ } catch ( Exception e ) { - _log.error( e.getMessage() ); + LOG.error( e.getMessage() ); return null; } @@ -253,7 +253,7 @@ } catch ( Exception e ) { - _log.error( e.getMessage() ); + LOG.error( e.getMessage() ); return 0; } Added: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Repo.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Repo.java?rev=729455&view=auto ============================================================================== --- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Repo.java (added) +++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Repo.java Thu Dec 25 22:50:17 2008 @@ -0,0 +1,388 @@ +package org.apache.maven.mercury.ant.tasks; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.maven.mercury.MavenDependencyProcessor; +import org.apache.maven.mercury.builder.api.DependencyProcessor; +import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes; +import org.apache.maven.mercury.crypto.api.StreamVerifierFactory; +import org.apache.maven.mercury.crypto.pgp.PgpStreamVerifierFactory; +import org.apache.maven.mercury.crypto.sha.SHA1VerifierFactory; +import org.apache.maven.mercury.repository.api.Repository; +import org.apache.maven.mercury.repository.local.m2.LocalRepositoryM2; +import org.apache.maven.mercury.repository.remote.m2.RemoteRepositoryM2; +import org.apache.maven.mercury.transport.api.Credentials; +import org.apache.maven.mercury.transport.api.Server; +import org.apache.maven.mercury.util.FileUtil; +import org.apache.maven.mercury.util.Util; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.Property; +import org.codehaus.plexus.lang.DefaultLanguage; +import org.codehaus.plexus.lang.Language; + +/** + * repository data type + * + * @author Oleg Gusakov + * @version $Id$ + */ +public class Repo + extends AbstractDataType +{ + private static final Language LANG = new DefaultLanguage( Repo.class ); + + String _dir; + + String _url; + + String _type; + + String _authid; + + String _proxyauthid; + + boolean _readable = true; + + boolean _writeable = false; + + Auth _auth; + + Auth _proxyAuth; + + List<Verify> _writeVerifiers; + + List<Verify> _readVerifiers; + + transient boolean _managed = false; + + transient boolean _registered = false; + + public Repo() + { + } + + public Repo( boolean managed ) + { + _managed = managed; + } + + @Override + public void setId( String id ) + { + super.setId( id ); + + if( _managed ) + return; + + Config.addDefaultRepository( getProject(), this ); + + } + + public void setReadable( boolean readable ) + { + this._readable = readable; + } + + public void setWriteable( boolean writeable ) + { + this._writeable = writeable; + } + + public void setUrl( String url ) + { + if( getId() == null ) + throw new IllegalArgumentException( LANG.getMessage( "repo.no.id", url ) ); + + this._url = url; + } + + public void setDir( String dir ) + { + if( getId() == null ) + throw new IllegalArgumentException( LANG.getMessage( "repo.no.id", dir ) ); + + this._dir = dir; + } + + public void setType( String type ) + { + this._type = type; + } + + public void setAuthid( String authid ) + { + this._authid = authid; + } + + public void setProxyauthid( String proxyauthid ) + { + this._proxyauthid = proxyauthid; + } + + boolean isLocal() + { + return _dir != null; + } + + public Verify createVerifywrite() + { + if ( _writeVerifiers == null ) + _writeVerifiers = new ArrayList<Verify>( 2 ); + + Verify v = new Verify(); + + _writeVerifiers.add( v ); + + return v; + } + + public Verify createVerifyread() + { + if ( _readVerifiers == null ) + _readVerifiers = new ArrayList<Verify>( 2 ); + + Verify v = new Verify(); + + _readVerifiers.add( v ); + + return v; + } + + private Set<StreamVerifierFactory> getVerifiers( List<Verify> vlist ) + { + if ( Util.isEmpty( vlist ) ) + return null; + + Set<StreamVerifierFactory> facs = new HashSet<StreamVerifierFactory>( vlist.size() ); + + for ( Verify v : vlist ) + facs.add( v.getVerifierFactory() ); + + return facs; + + } + + public Repository getRepository() + { + Repository r = null; + + if ( isLocal() ) + { + DependencyProcessor dp = new MavenDependencyProcessor(); + + Server server; + try + { + server = new Server( getId(), new File( _dir ).toURL() ); + + server.setReaderStreamVerifierFactories( getVerifiers( _readVerifiers ) ); + server.setWriterStreamVerifierFactories( getVerifiers( _writeVerifiers ) ); + } + catch ( MalformedURLException e ) + { + throw new BuildException( e ); + } + + r = new LocalRepositoryM2( server, dp ); + } + else + { + DependencyProcessor dp = new MavenDependencyProcessor(); + + Server server; + try + { + server = new Server( getId(), new URL( _url ) ); + + server.setReaderStreamVerifierFactories( getVerifiers( _readVerifiers ) ); + server.setWriterStreamVerifierFactories( getVerifiers( _writeVerifiers ) ); + } + catch ( MalformedURLException e ) + { + throw new BuildException( e ); + } + + Auth au = null; + + if( _auth != null ) + { + au = _auth; + } + else if ( _authid != null ) + { + au = Auth.findAuth( getProject(), _authid ); + + if ( au == null ) + throw new BuildException( LANG.getMessage( "config.no.auth.for.id", _authid ) ); + } + + if( au != null ) + { + Credentials serverCred = au.createCredentials(); + + server.setServerCredentials( serverCred ); + + au = null; + } + + if( _proxyAuth != null ) + { + au = _proxyAuth; + } + else if ( _proxyauthid != null ) + { + au = Auth.findAuth( getProject(), _proxyauthid ); + + if ( au == null ) + throw new BuildException( LANG.getMessage( "config.no.proxy.auth.for.id", _proxyauthid ) ); + } + + if( au != null ) + { + Credentials proxyCred = au.createCredentials(); + + server.setProxyCredentials( proxyCred ); + } + + r = new RemoteRepositoryM2( server, dp ); + } + + return r; + } + + public Auth createAuth() + { + _auth = new Auth(); + + return _auth; + } + + public Auth createProxyauth() + { + _auth = new Auth(); + + return _auth; + } + + public class Verify + extends AbstractDataType +{ + public static final String PGP = "pgp"; + + public static final String SHA1 = "sha1"; + + String _type; + + boolean _lenient = true; + + boolean _sufficient = false; + + Map<String, String> _properties; + + public void setType( String type ) + { + this._type = type; + } + + public void setLenient( boolean lenient ) + { + this._lenient = lenient; + } + + public void setSufficient( boolean sufficient ) + { + this._sufficient = sufficient; + } + + public void addConfiguredProperty( Property property ) + { + if ( _properties == null ) + _properties = new HashMap<String, String>( 4 ); + + _properties.put( property.getName(), property.getValue() ); + } + + public StreamVerifierFactory getVerifierFactory() + throws BuildException + { + if ( _type == null ) + throw new BuildException( LANG.getMessage( "config.repo.verifier.no.type" ) ); + + if ( _properties == null || _properties.isEmpty() ) + throw new BuildException( LANG.getMessage( "config.repo.verifier.no.properties", _type ) ); + + if ( PGP.equals( _type ) ) + { + String keyRing = _properties.get( "keyring" ); + + if ( keyRing == null ) + throw new BuildException( LANG.getMessage( "config.repo.verifier.pgp.no.keyring" ) ); + + String pass = _properties.get( "pass" ); + + if ( pass == null ) // reader configuration + { + try + { + PgpStreamVerifierFactory fac = + new PgpStreamVerifierFactory( + new StreamVerifierAttributes( + PgpStreamVerifierFactory.DEFAULT_EXTENSION, + _lenient, _sufficient ), + FileUtil.toStream( keyRing ) ); + return fac; + } + catch ( Exception e ) + { + throw new BuildException( e ); + } + } + else + // writer configuration + { + String keyId = _properties.get( "key" ); + + if ( keyId == null || keyId.length() != 16 ) + throw new BuildException( LANG.getMessage( "config.repo.verifier.pgp.bad.keyid", keyId, + keyRing ) ); + + try + { + PgpStreamVerifierFactory fac = + new PgpStreamVerifierFactory( + new StreamVerifierAttributes( + PgpStreamVerifierFactory.DEFAULT_EXTENSION, + _lenient, _sufficient ), + FileUtil.toStream( keyRing ), keyId, pass ); + return fac; + } + catch ( Exception e ) + { + throw new BuildException( e ); + } + + } + } + else if ( SHA1.equals( _type ) ) + { + SHA1VerifierFactory fac = + new SHA1VerifierFactory( new StreamVerifierAttributes( SHA1VerifierFactory.DEFAULT_EXTENSION, + _lenient, _sufficient ) ); + + return fac; + } + + throw new BuildException( LANG.getMessage( "config.repo.verifier.bad.type", _type ) ); + } +} + +} Propchange: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Repo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Repo.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/WriteTask.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/WriteTask.java?rev=729455&r1=729454&r2=729455&view=diff ============================================================================== --- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/WriteTask.java (original) +++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/WriteTask.java Thu Dec 25 22:50:17 2008 @@ -24,10 +24,10 @@ public class WriteTask extends AbstractAntTask { - private static final Language _lang = new DefaultLanguage( WriteTask.class ); + private static final Language LANG = new DefaultLanguage( WriteTask.class ); - public static final String TASK_NAME = _lang.getMessage( "write.task.name" ); - public static final String TASK_DESC = _lang.getMessage( "write.task.desc" ); + public static final String TASK_NAME = LANG.getMessage( "write.task.name" ); + public static final String TASK_DESC = LANG.getMessage( "write.task.desc" ); private String _repoid; private String _file; @@ -82,7 +82,7 @@ { if( _repoid == null ) { - throwIfEnabled( _lang.getMessage( "write.repo.id.mandatory" ) ); + throwIfEnabled( LANG.getMessage( "write.repo.id.mandatory" ) ); return; } @@ -90,13 +90,13 @@ if( repo == null ) { - throwIfEnabled( _lang.getMessage( "write.repo.not.found", _repoid ) ); + throwIfEnabled( LANG.getMessage( "write.repo.not.found", _repoid ) ); return; } if( _file == null ) { - throwIfEnabled( _lang.getMessage( "write.file.mandatory" ) ); + throwIfEnabled( LANG.getMessage( "write.file.mandatory" ) ); return; } @@ -104,25 +104,25 @@ if( !file.exists() ) { - throwIfEnabled( _lang.getMessage( "write.file.not.found", _file, _repoid ) ); + throwIfEnabled( LANG.getMessage( "write.file.not.found", _file, _repoid ) ); return; } if( Util.isEmpty( _name ) && Util.isEmpty( _pom ) ) { - throwIfEnabled( _lang.getMessage( "write.no.name.no.pom", _file, _repoid ) ); + throwIfEnabled( LANG.getMessage( "write.no.name.no.pom", _file, _repoid ) ); return; } if( !Util.isEmpty( _name ) && !Util.isEmpty( _pom ) ) { - throwIfEnabled( _lang.getMessage( "write.no.name.no.pom", _file, _repoid ) ); + throwIfEnabled( LANG.getMessage( "write.no.name.no.pom", _file, _repoid ) ); return; } if( !Util.isEmpty( _pom ) ) { - throwIfEnabled( _lang.getMessage( "write.pom.not.supported", _file, _repoid ) ); + throwIfEnabled( LANG.getMessage( "write.pom.not.supported", _file, _repoid ) ); return; } @@ -157,7 +157,7 @@ } else { - throwIfEnabled( _lang.getMessage( "write.pom.not.supported", _file, _repoid ) ); + throwIfEnabled( LANG.getMessage( "write.pom.not.supported", _file, _repoid ) ); return; } Copied: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/Messages.properties (from r729251, maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Messages.properties) URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/Messages.properties?p2=maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/Messages.properties&p1=maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Messages.properties&r1=729251&r2=729455&rev=729455&view=diff ============================================================================== --- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/Messages.properties (original) +++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/Messages.properties Thu Dec 25 22:50:17 2008 @@ -36,7 +36,8 @@ config.repo.verifier.no.properties=Verifier configuration {0} does not have properties - don't know what to do config.repo.verifier.pgp.no.keyring=PGP verifier configuration does not have a keyring property config.repo.verifier.bad.type=Verfier does not understand type {0} -config.repo.verifier.pgp.bad.keyid=Bad key "{0}" for secret keyring {1}; expected to see 16 hex number, but did not find them +config.repo.verifier.pgp.bad.keyid=Bad key "{0}" for secret keyring {1}; expected to see 16 hex number, but did not find them +repo.no.id=repo {0} does not have an id attribute, or it's not the first attribute. dep.pom.not.implemented=pom attribute not implemented for <dep ../> tag Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/antlib.xml URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/antlib.xml?rev=729455&r1=729454&r2=729455&view=diff ============================================================================== --- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/antlib.xml (original) +++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/main/resources/org/apache/maven/mercury/ant/tasks/antlib.xml Thu Dec 25 22:50:17 2008 @@ -7,6 +7,10 @@ <taskdef name="write" classname="org.apache.maven.mercury.ant.tasks.WriteTask"/> <typedef name="dep" classname="org.apache.maven.mercury.ant.tasks.Dep"/> + <typedef name="deps" classname="org.apache.maven.mercury.ant.tasks.Dep"/> <typedef name="config" classname="org.apache.maven.mercury.ant.tasks.Config"/> + <typedef name="repository" classname="org.apache.maven.mercury.ant.tasks.Repo"/> + <typedef name="auth" classname="org.apache.maven.mercury.ant.tasks.Auth"/> + <typedef name="proxyauth" classname="org.apache.maven.mercury.ant.tasks.Auth"/> </antlib> Modified: maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/test/java/org/apache/maven/mercury/ant/tasks/MecuryAntTest.java URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/test/java/org/apache/maven/mercury/ant/tasks/MecuryAntTest.java?rev=729455&r1=729454&r2=729455&view=diff ============================================================================== --- maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/test/java/org/apache/maven/mercury/ant/tasks/MecuryAntTest.java (original) +++ maven/mercury/trunk/mercury-ant/mercury-ant-tasks/src/test/java/org/apache/maven/mercury/ant/tasks/MecuryAntTest.java Thu Dec 25 22:50:17 2008 @@ -114,7 +114,7 @@ FileUtil.delete( _localRepoDirFile ); _localRepoDirFile.mkdirs(); - Config.Repo localRepo = _config.createRepo(); + Repo localRepo = _config.createRepo(); localRepo.setId( "localRepo" ); localRepo.setDir( _localRepoDir ); @@ -123,7 +123,7 @@ _jetty.start(); _port = _jetty.getPort(); - Config.Repo remoteRepo = _config.createRepo(); + Repo remoteRepo = _config.createRepo(); remoteRepo.setId( "remoteRepo" ); remoteRepo.setUrl( _remoteRepoUrlPrefix + _port + _remoteRepoUrlSufix ); @@ -225,6 +225,31 @@ } // ----------------------------------- + public void testCompileFail() + { + String title = "compile-fail"; + System.out.println( "========> start " + title ); + System.out.flush(); + + File af = new File( _compileDirFile, "T.class" ); + + assertFalse( af.exists() ); + + try + { + executeTarget( title ); + + fail(title+" did not raise an exception"); + } + catch( Throwable e ) + { + System.out.println("Expected exception: "+e.getMessage() ); + } + + assertFalse( af.exists() ); + } + + // ----------------------------------- public void testCompile() { String title = "compile"; @@ -279,6 +304,33 @@ } // ----------------------------------- + public void testCompileThinPath3() + throws Exception + { + String title = "compile-thin-path-3"; + System.out.println( "========> start " + title ); + System.out.flush(); + + restart( _port, _remoteRepoDirFile, "/maven2", true ); + + File af = new File( _compileDirFile, "T.class" ); + + assertFalse( af.exists() ); + + File asm = new File( "target/path-3/asm/asm/3.0/asm-3.0.jar" ); + + asm.delete(); + + assertFalse( asm.exists() ); + + executeTarget( title ); + + assertTrue( af.exists() ); + + assertTrue( asm.exists() ); + } + + // ----------------------------------- public void testBadAuthRepo() throws Exception {