From: <st...@us...> - 2007-04-27 14:17:33
|
Revision: 4104 http://svn.sourceforge.net/smartfrog/?rev=4104&view=rev Author: steve_l Date: 2007-04-27 07:15:56 -0700 (Fri, 27 Apr 2007) Log Message: ----------- Ivy cache support..not existing until the tests come with it Modified Paths: -------------- trunk/core/smartfrog/src/org/smartfrog/services/os/java/AbstractPolicy.java trunk/core/smartfrog/src/org/smartfrog/services/os/java/library.sf Added Paths: ----------- trunk/core/smartfrog/src/org/smartfrog/services/os/java/IvyLocalCachePolicy.java Modified: trunk/core/smartfrog/src/org/smartfrog/services/os/java/AbstractPolicy.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/os/java/AbstractPolicy.java 2007-04-26 16:41:06 UTC (rev 4103) +++ trunk/core/smartfrog/src/org/smartfrog/services/os/java/AbstractPolicy.java 2007-04-27 14:15:56 UTC (rev 4104) @@ -13,61 +13,55 @@ */ package org.smartfrog.services.os.java; -import java.rmi.RemoteException; - import org.smartfrog.sfcore.common.SmartFrogRuntimeException; import org.smartfrog.sfcore.prim.PrimImpl; -/** - * base of our policies - */ +import java.rmi.RemoteException; + +/** base of our policies */ public abstract class AbstractPolicy extends PrimImpl { - /** - * what artifacts are separated by {@value} - */ + /** what artifacts are separated by {@value} */ public static final String ARTIFACT_SEPARATOR = "-"; /** - * Create an artifact filename. This claims to be maven1, but really it - * is also maven2, as if there is a classifier, we use that as well. There - * just near zero chance of that finding a match against the classic M1 repository. - * + * Create an artifact filename. This claims to be maven1, but really it is also maven2, as if there is a classifier, + * we use that as well. There just near zero chance of that finding a match against the classic M1 repository. + * * @param library * @return the filename of an artifact using maven separation rules */ protected String createMavenArtifactName(SerializedArtifact library) throws SmartFrogRuntimeException { - SerializedArtifact.assertValid(library,false); - StringBuffer buffer=new StringBuffer(); + SerializedArtifact.assertValid(library, false); + StringBuffer buffer = new StringBuffer(); buffer.append(library.artifact); - if(nonEmpty(library.version)) { + if (nonEmpty(library.version)) { buffer.append(ARTIFACT_SEPARATOR); buffer.append(library.version); } - if(nonEmpty(library.classifier)) { + if (nonEmpty(library.classifier)) { buffer.append(ARTIFACT_SEPARATOR); buffer.append(library.classifier); } - if(nonEmpty(library.extension)) { + if (nonEmpty(library.extension)) { buffer.append('.'); buffer.append(library.extension); } return buffer.toString(); } - /** - * @throws RemoteException - */ - public AbstractPolicy() throws RemoteException { + /** @throws RemoteException */ + protected AbstractPolicy() throws RemoteException { super(); } /** * test that a string is not empty + * * @param s * @return true iff the string is non null, and not "" */ - protected boolean nonEmpty(String s) { - return s!=null && s.length()>0; + protected boolean nonEmpty(String s) { + return s != null && s.length() > 0; } } Added: trunk/core/smartfrog/src/org/smartfrog/services/os/java/IvyLocalCachePolicy.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/os/java/IvyLocalCachePolicy.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/os/java/IvyLocalCachePolicy.java 2007-04-27 14:15:56 UTC (rev 4104) @@ -0,0 +1,74 @@ +/** (C) Copyright 2007 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.services.os.java; + +import org.smartfrog.sfcore.common.SmartFrogRuntimeException; + +import java.rmi.RemoteException; + +public class IvyLocalCachePolicy extends AbstractPolicy implements LocalCachePolicy { + + /** @throws RemoteException */ + public IvyLocalCachePolicy() throws RemoteException { + } + + /** @see LocalCachePolicy#createLocalPath(SerializedArtifact) */ + public String createLocalPath(SerializedArtifact artifact) + throws RemoteException, SmartFrogRuntimeException { + SerializedArtifact.assertValid(artifact, true); + String project = convertProjectToIvyFormat(artifact); + String urlPath = new StringBuffer().append(project) + .append("/") + .append(artifact.artifact) + .append("/") + .append(artifact.version) + .append("/") + .append(createIvyArtifactFilename(artifact)) + .toString(); + return urlPath; + } + + /** + * In Ivy, this is currently a noop + * + * @param artifact + * @return the project of an artifact + */ + private String convertProjectToIvyFormat(SerializedArtifact artifact) { + return artifact.project; + } + + private String createIvyArtifactFilename(SerializedArtifact artifact) { + StringBuffer buffer = new StringBuffer(); + buffer.append(artifact.artifact); + buffer.append(ARTIFACT_SEPARATOR); + buffer.append(artifact.version); + buffer.append('.'); + buffer.append(artifact.extension); + String filename = buffer.toString(); + return filename; + } + + /** @see LibraryCachePolicy#getDescription() */ + public String getDescription() throws RemoteException { + return "Ivy local cache policy"; + } + +} Modified: trunk/core/smartfrog/src/org/smartfrog/services/os/java/library.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/os/java/library.sf 2007-04-26 16:41:06 UTC (rev 4103) +++ trunk/core/smartfrog/src/org/smartfrog/services/os/java/library.sf 2007-04-27 14:15:56 UTC (rev 4104) @@ -65,6 +65,10 @@ sfClass "org.smartfrog.services.os.java.Maven2Policy"; } +IvyLocalPolicy extends Prim { + sfClass "org.smartfrog.services.os.java.IvyLocalCachePolicy"; +} + /** * This is a local file policy only. * It tells the library to save stuff flat @@ -140,13 +144,18 @@ /** * Maven repository at ibiblio.org. */ - repositories [| "http://mirrors.ibiblio.org/pub/mirrors/maven" |]; + repositories [| LibraryRepositories:Maven1_at_Ibiblio |]; //cache into the well known maven location cacheDir LAZY MavenLocalCacheDirectory:absolutePath; } +LibraryRepositories { + Maven1_at_Ibiblio "http://mirrors.ibiblio.org/pub/mirrors/maven" ; + Maven2_at_Ibiblio "http://mirrors.ibiblio.org/pub/mirrors/maven2" ; +} + Maven2Library extends Library { /** @@ -183,14 +192,58 @@ * Maven2 repository at ibiblio.org. Really we should permit mirrors; or include * the mirror list for easy selection. */ - repositories [| "http://mirrors.ibiblio.org/pub/mirrors/maven2" |]; + repositories [| LibraryRepositories:Maven2_at_Ibiblio |]; //cache into the well known maven location cacheDir LAZY localCacheDirectory:absolutePath; } +/** + * For Ivy artifacts we use the central M2 repository for remote artifacts, + * but the local cache. This currently causes us to miss out on things published + * locally but which are not in cache + */ +IvyLibrary extends Library { + /** + * Maven file policy + */ + policy + + /** + * local policy is maven2 + */ + localCachePolicy extends IvyLocalPolicy; + + /** + * Remote policy is maven2 + */ + remoteCachePolicy extends Maven2Policy;; + + + + /** + * Well known cache directory + */ + localCacheDirectory extends File { + //JVM property user.home + dir LAZY PROPERTY user.home; + //subdir + filename ".ivy/cache"; + } + + /** + * Maven2 repository at ibiblio.org. Really we should permit mirrors; or include + * the mirror list for easy selection. + */ + repositories [| LibraryRepositories:Maven2_at_Ibiblio |]; + + //cache into the well known maven location + cacheDir LAZY localCacheDirectory:absolutePath; +} + + /** * This is something that you can download * from a repository. @@ -281,3 +334,8 @@ MavenJar extends JarArtifact { } +/** + * An Ivy JAR is a JAR artifact + */ +IvyJar extends JarArtifact { +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |