├── .gitignore ├── src ├── main │ └── java │ │ └── org │ │ └── mule │ │ ├── farm │ │ ├── api │ │ │ ├── ArtifactNotRegisteredException.java │ │ │ ├── Animal.java │ │ │ ├── EmptyOrInvalidRepoException.java │ │ │ └── FarmRepository.java │ │ ├── impl │ │ │ ├── ManualWagonProvider.java │ │ │ ├── AnimalImpl.java │ │ │ └── FarmRepositoryImpl.java │ │ ├── util │ │ │ └── Util.java │ │ └── main │ │ │ ├── FarmApp.java │ │ │ └── Version.java │ │ └── barn │ │ ├── annotations │ │ ├── Command.java │ │ └── OnException.java │ │ └── Barn.java └── test │ └── java │ └── org │ └── mule │ └── farm │ ├── util │ ├── MockOutputStream.java │ └── TestUtil.java │ ├── VersionTest.java │ └── FarmTest.java ├── README.md └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .project 3 | .classpath 4 | -------------------------------------------------------------------------------- /src/main/java/org/mule/farm/api/ArtifactNotRegisteredException.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.api; 2 | 3 | public class ArtifactNotRegisteredException extends Exception { 4 | 5 | private static final long serialVersionUID = 1499973126753949669L; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/mule/farm/api/Animal.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.api; 2 | 3 | import org.sonatype.aether.artifact.Artifact; 4 | 5 | public interface Animal { 6 | /** 7 | * Retrieves the artifact associated with the Animal. 8 | * 9 | * @return an artifact , never Null. 10 | */ 11 | public Artifact getArtifact(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/mule/farm/api/EmptyOrInvalidRepoException.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.api; 2 | 3 | public class EmptyOrInvalidRepoException extends Exception { 4 | 5 | public EmptyOrInvalidRepoException(String string) { 6 | super(string); 7 | } 8 | 9 | private static final long serialVersionUID = 166746178098545580L; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/mule/barn/annotations/Command.java: -------------------------------------------------------------------------------- 1 | package org.mule.barn.annotations; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | /** 7 | * Annotate a method with this in order to process Command Line Arguments. 8 | * 9 | * @author Alberto Pose 10 | * 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface Command { 14 | } -------------------------------------------------------------------------------- /src/main/java/org/mule/farm/api/FarmRepository.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.api; 2 | 3 | import java.util.Collection; 4 | 5 | 6 | public interface FarmRepository { 7 | 8 | public Animal install(String identifier) 9 | throws ArtifactNotRegisteredException; 10 | 11 | public Animal get(String identifier) 12 | throws ArtifactNotRegisteredException; 13 | 14 | public Animal put(String identifier, String version, String url); 15 | 16 | public Collection list(); 17 | 18 | } -------------------------------------------------------------------------------- /src/main/java/org/mule/farm/impl/ManualWagonProvider.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.impl; 2 | 3 | import org.apache.maven.wagon.Wagon; 4 | import org.apache.maven.wagon.providers.http.HttpWagon; 5 | import org.sonatype.aether.connector.wagon.WagonProvider; 6 | 7 | public class ManualWagonProvider implements WagonProvider { 8 | 9 | public Wagon lookup(String roleHint) throws Exception { 10 | System.out.println("rolehit " + roleHint); 11 | if ("http".equals(roleHint)) { 12 | return new HttpWagon(); 13 | } 14 | return null; 15 | } 16 | 17 | public void release(Wagon wagon) { 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /src/main/java/org/mule/farm/impl/AnimalImpl.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.impl; 2 | 3 | import org.apache.commons.lang3.Validate; 4 | import org.mule.farm.api.Animal; 5 | import org.sonatype.aether.artifact.Artifact; 6 | 7 | public class AnimalImpl implements Animal { 8 | public static AnimalImpl createAnimalFromArtifact(Artifact artifact) { 9 | return new AnimalImpl(artifact); 10 | } 11 | 12 | private Artifact artifact; 13 | 14 | private AnimalImpl(Artifact artifact) { 15 | Validate.notNull(artifact); 16 | this.artifact = artifact; 17 | } 18 | 19 | @Override 20 | public Artifact getArtifact() { 21 | return this.artifact; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/mule/barn/annotations/OnException.java: -------------------------------------------------------------------------------- 1 | package org.mule.barn.annotations; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | /** 7 | * Annotate a method using this together with Command in order to specify the 8 | * behavior when that exception is thrown. 9 | * 10 | * @author Alberto Pose 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface OnException { 14 | /** 15 | * Exception to be handled. 16 | */ 17 | Class value(); 18 | 19 | /** 20 | * Message to output to stedrr. 21 | */ 22 | String message(); 23 | 24 | /** 25 | * Return code that the Barn must return in case this happens. 26 | */ 27 | int returnCode(); 28 | } -------------------------------------------------------------------------------- /src/test/java/org/mule/farm/util/MockOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.util; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | import org.apache.commons.lang3.Validate; 7 | 8 | public final class MockOutputStream extends OutputStream { 9 | private StringBuffer stringBuffer = new StringBuffer(); 10 | private OutputStream outputStream; 11 | 12 | public static MockOutputStream createWireTap(OutputStream outputStream) { 13 | return new MockOutputStream(outputStream); 14 | } 15 | 16 | private MockOutputStream(OutputStream outputStream) { 17 | Validate.notNull(outputStream); 18 | this.outputStream = outputStream; 19 | } 20 | 21 | @Override 22 | public void write(int b) throws IOException { 23 | stringBuffer.append((char) b); 24 | outputStream.write(b); 25 | } 26 | 27 | public String getContent() { 28 | return stringBuffer.toString(); 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/org/mule/farm/util/Util.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.util; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | 9 | public class Util { 10 | public static void createFolder(String name) { 11 | File folder = new File("." + File.separator + name); 12 | folder.mkdir(); 13 | } 14 | 15 | public static void removeFolder(String folderName) { 16 | deleteDirectory(new File("." + File.separator + folderName)); 17 | } 18 | 19 | public static boolean deleteDirectory(File path) { 20 | if (path.exists()) { 21 | File[] files = path.listFiles(); 22 | for (int i = 0; i < files.length; i++) { 23 | if (files[i].isDirectory()) { 24 | deleteDirectory(files[i]); 25 | } else { 26 | files[i].delete(); 27 | } 28 | } 29 | } 30 | return (path.delete()); 31 | } 32 | 33 | public static void copy(String origin, String destiny) { 34 | File inputFile = new File(origin); 35 | File outputFile = new File(destiny); 36 | 37 | FileReader in = null; 38 | FileWriter out = null; 39 | 40 | try { 41 | in = new FileReader(inputFile); 42 | out = new FileWriter(outputFile); 43 | 44 | int c; 45 | 46 | while ((c = in.read()) != -1) 47 | out.write(c); 48 | 49 | in.close(); 50 | out.close(); 51 | 52 | } catch (FileNotFoundException e) { 53 | e.printStackTrace(); 54 | throw new RuntimeException(); 55 | } catch (IOException e) { 56 | e.printStackTrace(); 57 | throw new RuntimeException(); 58 | } 59 | 60 | } 61 | 62 | public static void move(String origin, String destiny) { 63 | new File(origin).renameTo(new File(destiny)); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/org/mule/farm/util/TestUtil.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.util; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | import static org.junit.Assert.fail; 5 | 6 | import java.io.File; 7 | import java.util.regex.Pattern; 8 | 9 | import org.mule.farm.main.FarmApp; 10 | 11 | public class TestUtil { 12 | 13 | public static int callFarmAppMainWithRepo(String repo, String... s) { 14 | return FarmApp.trueMainWithRepo(s, repo); 15 | } 16 | 17 | public static int callFarmAppMain(String... s) { 18 | return FarmApp.trueMain(s); 19 | } 20 | 21 | public static void assertFileExistenceWithRegex(String regex) { 22 | 23 | File root = new File("."); 24 | 25 | for (File file : root.listFiles()) { 26 | String path = file.getPath(); 27 | String[] splittedPath = path.split(File.separator); 28 | if (splittedPath.length != 2) { 29 | continue; 30 | } 31 | 32 | if (Pattern.matches(regex, splittedPath[1])) { 33 | if (file.isFile()) { 34 | return; 35 | } 36 | } 37 | } 38 | fail(String.format("Files with the regex [%s] were not found", regex)); 39 | } 40 | 41 | public static void assertFileExistence(String fileName) { 42 | File file = new File("." + File.separator + fileName); 43 | assertTrue(String.format("Path [%s] does not exist", fileName), 44 | file.exists()); 45 | assertTrue(String.format("[%s] is not a file", fileName), file.isFile()); 46 | } 47 | 48 | public static void assertFolderExistence(String folderName) { 49 | File file = new File("." + File.separator + folderName); 50 | assertTrue(String.format("Path [%s] does not exist", folderName), 51 | file.exists()); 52 | assertTrue(String.format("[%s] is not a folder", folderName), 53 | file.isDirectory()); 54 | } 55 | 56 | public static void assertFolderExistenceWithRegex(String regex) { 57 | 58 | File root = new File("."); 59 | 60 | for (File file : root.listFiles()) { 61 | String path = file.getPath(); 62 | String[] splittedPath = path.split(File.separator); 63 | if (splittedPath.length != 2) { 64 | continue; 65 | } 66 | 67 | if (Pattern.matches(regex, splittedPath[1])) { 68 | if (file.isDirectory()) { 69 | return; 70 | } 71 | } 72 | } 73 | fail(String.format("Folders with regex [%s] were not found", regex)); 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /src/test/java/org/mule/farm/VersionTest.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import static junit.framework.Assert.*; 7 | 8 | import org.junit.Test; 9 | import org.mule.farm.main.Version; 10 | 11 | 12 | public class VersionTest { 13 | 14 | @Test(expected=IllegalArgumentException.class) 15 | public void testCreateWithInvalidStrings() { 16 | Version.fromString(""); 17 | } 18 | 19 | @Test(expected=NullPointerException.class) 20 | public void testCreateFromNullString() { 21 | Version.fromString(null); 22 | } 23 | 24 | @Test 25 | public void testCreateFromString() { 26 | List version = new ArrayList(); 27 | version.add(3); 28 | version.add(2); 29 | version.add(1); 30 | assertEquals(version,Version.fromString("3.2.1").getVersionNumbers()); 31 | 32 | version = new ArrayList(); 33 | version.add(3); 34 | version.add(2); 35 | assertEquals("3.2. case", version, Version.fromString("3.2.").getVersionNumbers()); 36 | } 37 | 38 | @Test 39 | public void testEquals() { 40 | assertEquals("Test 0 padding", Version.fromString("3.2.0"), Version.fromString("3.2")); 41 | } 42 | 43 | @Test 44 | public void testComparison() { 45 | assertEquals(1,Version.fromString("3.2.1").compareTo(Version.fromString("3.1"))); 46 | assertEquals(-1,Version.fromString("3.2.1").compareTo(Version.fromString("3.38"))); 47 | assertEquals(-1,Version.fromString("3.2.1").compareTo(Version.fromString("4"))); 48 | assertEquals("Test 0 padding", 0, Version.fromString("3.2.0").compareTo( Version.fromString("3.2"))); 49 | } 50 | 51 | @Test 52 | public void inferVersionFromFileName() { 53 | assertEquals(Version.fromString("6.0.32"), Version.inferVersionFromFileName("apache-tomcat-6.0.32.zip")); 54 | assertEquals(Version.fromString("7.0.20"), Version.inferVersionFromFileName("apache-tomcat-7.0.20.zip")); 55 | assertEquals(Version.fromString("4.2.3"), Version.inferVersionFromFileName("jboss-4.2.3.zip")); 56 | assertEquals(Version.fromString("5.1.0"), Version.inferVersionFromFileName("jboss-5.1.0.zip")); 57 | assertEquals(Version.fromString("6.1.0"), Version.inferVersionFromFileName("jboss-6.1.0.GA.zip")); 58 | //TODO Support SNAPSHOT versions 59 | // Version.inferVersionFromFileName("mule-server-3.2.0-SNAPSHOT.war"); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Farm 2 | The missing package manager for Java. 3 | 4 | ## Get 5 | `get` allows you to retrieve a saved animal. 6 | 7 | $ farm get tomcat6x 8 | $ ls 9 | tomcat6x-6.1.0.zip 10 | 11 | $ farm get tomcat7x jboss5x 12 | $ ls 13 | tomcat7x-7.0.32.zip jboss5x-5.0.32.zip 14 | 15 | $ farm get muleee 16 | $ farm get mule@3.1.2 17 | $ farm get muleee@3.2.0 18 | $ farm get tomcat6x@6.0.31 19 | 20 | By default, `get` fetches the latest version if it is not provided. 21 | 22 | ## Install 23 | `install` is similar to `get` but it only works on containers. As the name suggests, the container is set up and ready to run. 24 | 25 | $ farm install tomcat6x 26 | $ ls 27 | tomcat6x/ 28 | 29 | ## Put 30 | Nice, but how I manage to add new animals? Here comes `put` to the rescue. 31 | 32 | $ farm put tomcat6x apache-tomcat-6.0.32.zip 33 | Adding tomcat6x using "6.0.32" as the animal version 34 | 35 | $ farm put tomcat7x apache-tomcat-7.0.20.zip 36 | Adding tomcat7x using 7.0.20 as the animal version 37 | 38 | $ farm put tomcat6x http://mirrors.axint.net/apache/tomcat/tomcat-6/v6.0.33/bin/apache-tomcat-6.0.33.zip 39 | Downloading... 40 | Adding tomcat6x using 6.0.33 as the animal version 41 | 42 | $ farm put tomcat6x weirdname.zip 43 | Error: Version cannot be inferred from the package file 44 | 45 | $ farm put tomcat6x@6.0.20 weirdname.zip 46 | Adding tomcat6x using 6.0.20 as the animal version 47 | 48 | ## Ls 49 | So, do you want an easy way of knowing which animals are available? 50 | 51 | $ farm ls 52 | tomcat6x 53 | tomcat7x 54 | muleee 55 | mule 56 | 57 | Oh wait, what versions are available of the given animal? 58 | 59 | $ farm ls tomcat6x 60 | tomcat6x@6.0.20 61 | tomcat6x@6.0.21 62 | tomcat6x@6.0.22 63 | tomcat6x@6.0.27 64 | 65 | ## Maven 66 | Would you prefer to use Maven instead? No problem, we can give you a maven dependency too. 67 | 68 | $ farm mvn tomcat6x 69 | 70 | org.mule.farm.animals 71 | tomcat6x 72 | 6.0.32 73 | 74 | 75 | 76 | # The idea behind the project 77 | 78 | * Provide an easy way to test containers from Command Line. 79 | * Provide an API to perform complex build tasks (like running two containers at the same time and installing applications on them with custom configuration). 80 | 81 | ## The problem 82 | Testing with Cargo Maven Plugin requires a lot of xml configuration, specially for complex scenarios like having a Mule and a Tomcat instance running at the same time. 83 | 84 | The main idea is that with farm you will be able to smoke test in many platforms without much effort. 85 | 86 | -------------------------------------------------------------------------------- /src/main/java/org/mule/farm/main/FarmApp.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.main; 2 | 3 | import java.io.File; 4 | import java.util.Collection; 5 | 6 | import org.mule.barn.Barn; 7 | import org.mule.barn.annotations.Command; 8 | import org.mule.barn.annotations.OnException; 9 | import org.mule.farm.api.Animal; 10 | import org.mule.farm.api.ArtifactNotRegisteredException; 11 | import org.mule.farm.api.FarmRepository; 12 | import org.mule.farm.impl.FarmRepositoryImpl; 13 | 14 | 15 | public class FarmApp { 16 | 17 | public static final int VERSION_NOT_SPECIFIED_ERROR = -2; 18 | public static final int ANIMAL_NOT_FOUND_ERROR = -3; 19 | 20 | private FarmRepository farmRepo; 21 | 22 | private FarmApp(String repoPath) { 23 | this.farmRepo = FarmRepositoryImpl.createFarmRepository(repoPath); 24 | } 25 | 26 | @Command 27 | @OnException(value = ArtifactNotRegisteredException.class, message = "Error: Animal not found", returnCode = FarmApp.ANIMAL_NOT_FOUND_ERROR) 28 | public Animal install(String identifier) 29 | throws ArtifactNotRegisteredException { 30 | System.err.println("Installing..."); 31 | return farmRepo.install(identifier); 32 | } 33 | 34 | @Command 35 | @OnException(value = ArtifactNotRegisteredException.class, message = "Error: Animal not found", returnCode = FarmApp.ANIMAL_NOT_FOUND_ERROR) 36 | public Animal get(String identifier) throws ArtifactNotRegisteredException { 37 | System.err.println("Getting..."); 38 | return farmRepo.get(identifier); 39 | } 40 | 41 | @Command 42 | public void put(String artifactId, String version, String filePathOrUrl) { 43 | System.err.println("Putting..."); 44 | farmRepo.put(artifactId, version, filePathOrUrl); 45 | } 46 | 47 | @Command 48 | public void put(String artifactMaybeVersion, String filePathOrUrl) { 49 | String[] args2Parts = artifactMaybeVersion.split("@"); 50 | Version version = null; 51 | if (args2Parts.length != 2) { 52 | 53 | // If the version was not specified, try to infer it 54 | // from the file name. 55 | version = Version.inferVersionFromFileName(filePathOrUrl); 56 | } else { 57 | version = Version.fromString(args2Parts[1]); 58 | } 59 | 60 | put(args2Parts[0], version.toString(), filePathOrUrl); 61 | } 62 | 63 | @Command 64 | public void list() { 65 | Collection animals = farmRepo.list(); 66 | 67 | if (animals.size() == 0) { 68 | System.err.println("No results found."); 69 | return; 70 | } 71 | 72 | System.out.println("Available animals:"); 73 | 74 | for (Animal animalToIterate : animals) { 75 | System.out.println(animalToIterate.getArtifact().getArtifactId()); 76 | } 77 | } 78 | 79 | public static int trueMainWithRepo(String[] args, String repoPath) { 80 | FarmApp farmApp = new FarmApp(repoPath); 81 | Barn cli = new Barn(farmApp, "farm"); 82 | 83 | return cli.runCommandLine(args); 84 | } 85 | 86 | public static int trueMain(String[] args) { 87 | // TODO: Get the real .m2 folder 88 | return trueMainWithRepo(args, System.getProperty("user.home") 89 | + File.separator + ".m2" + File.separator + "repository"); 90 | } 91 | 92 | public static void main(String[] args) { 93 | System.exit(trueMain(args)); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/org/mule/farm/main/Version.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.main; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.apache.commons.lang3.Validate; 9 | 10 | public class Version implements Comparable { 11 | @Override 12 | public int hashCode() { 13 | final int prime = 31; 14 | int result = 1; 15 | result = prime * result 16 | + ((versionNumbers == null) ? 0 : versionNumbers.hashCode()); 17 | return result; 18 | } 19 | 20 | @Override 21 | public boolean equals(Object obj) { 22 | if (this == obj) 23 | return true; 24 | if (obj == null) 25 | return false; 26 | if (getClass() != obj.getClass()) 27 | return false; 28 | Version other = (Version) obj; 29 | if (versionNumbers == null) { 30 | if (other.versionNumbers != null) 31 | return false; 32 | } else if (this.compareTo(other) != 0) 33 | return false; 34 | return true; 35 | } 36 | 37 | public List getVersionNumbers() { 38 | return versionNumbers; 39 | } 40 | 41 | private List versionNumbers; 42 | 43 | public static Version inferVersionFromFileName(String path) { 44 | for ( String s : path.split("-|/") ) { 45 | if ( StringUtils.startsWithAny(s, "0","1","2","3","4","5","6","7","8","9") ) { 46 | String [] numbers = s.split("\\."); 47 | 48 | String versionString = null; 49 | int i = numbers.length - 1; 50 | for ( ; i >= 0; i--) { 51 | if (StringUtils.startsWithAny(numbers[i], "0","1","2","3","4","5","6","7","8","9")) { 52 | break; 53 | } 54 | } 55 | 56 | if (!StringUtils.startsWithAny(numbers[numbers.length - 1], "0","1","2","3","4","5","6","7","8","9")) { 57 | versionString = StringUtils.join(Arrays.copyOfRange(numbers, 0, i + 1), "."); 58 | return fromString(versionString); 59 | } else { 60 | continue; 61 | } 62 | } 63 | } 64 | throw new IllegalArgumentException(); 65 | } 66 | 67 | public static Version fromString(String versionString) { 68 | Validate.notNull(versionString); 69 | ArrayList versionNumbers = new ArrayList(); 70 | for (String versionNumber : versionString.split("\\.")) { 71 | versionNumbers.add(Integer.parseInt(versionNumber)); 72 | } 73 | return new Version(versionNumbers); 74 | } 75 | 76 | private Version(List versionNumbers) { 77 | Validate.notNull(versionNumbers); 78 | Validate.notEmpty(versionNumbers); 79 | Validate.noNullElements(versionNumbers); 80 | this.versionNumbers = versionNumbers; 81 | } 82 | 83 | @Override 84 | public String toString() { 85 | return StringUtils.join(versionNumbers, "."); 86 | } 87 | 88 | private Integer getOrZero(int position) { 89 | if ( this.versionNumbers.size() <= position ) { 90 | return 0; 91 | } 92 | return this.versionNumbers.get(position); 93 | } 94 | 95 | @Override 96 | public int compareTo(Version o) { 97 | int max = Math.max(this.versionNumbers.size(), o.versionNumbers.size()); 98 | for ( int i = 0; i < max; i++) { 99 | int comparisonResult = this.getOrZero(i).compareTo(o.getOrZero(i)); 100 | 101 | if ( comparisonResult != 0 ) { 102 | return comparisonResult; 103 | } 104 | } 105 | return 0; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/org/mule/barn/Barn.java: -------------------------------------------------------------------------------- 1 | package org.mule.barn; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.lang.reflect.Method; 5 | import java.util.Arrays; 6 | 7 | import org.apache.commons.lang3.Validate; 8 | import org.mule.barn.annotations.Command; 9 | import org.mule.barn.annotations.OnException; 10 | 11 | /** 12 | * Annotation based Command-Line Interface. 13 | * 14 | * @author Alberto Pose 15 | * 16 | * @param 17 | * Type of the annotated class. 18 | */ 19 | public class Barn { 20 | 21 | /** 22 | * Invalid parameters return code. 23 | */ 24 | public static final int INVALID_PARAMETERS = -1; 25 | 26 | /** 27 | * Success return code. 28 | */ 29 | public static final int SUCCESS = 0; 30 | 31 | /** 32 | * Annotated instance. 33 | */ 34 | private T instance; 35 | 36 | /** 37 | * Annotated instance class. 38 | */ 39 | private Class klass; 40 | 41 | /** 42 | * sh script name (in order to use it in help) 43 | */ 44 | private String appName; 45 | 46 | /** 47 | * Registers the instance for Barn parsing. 48 | * 49 | * @param instance 50 | * annotated instance for Barn parsing 51 | */ 52 | public Barn(T instance, String appName) { 53 | Validate.notNull(instance); 54 | Validate.notNull(appName); 55 | Validate.notBlank(appName); 56 | 57 | this.appName = appName; 58 | this.instance = instance; 59 | this.klass = instance.getClass(); 60 | } 61 | 62 | /** 63 | * Execute the command line parser using the specified arguments. Return 64 | * code is != 0 in case of error. 65 | * 66 | * @param args 67 | * Command-Line Arguments 68 | * @return the return code that the process should return. 69 | */ 70 | public int runCommandLine(String[] args) { 71 | Validate.notNull(args); 72 | if (args.length == 0) { 73 | help(); 74 | return SUCCESS; 75 | } 76 | 77 | for (Method method : klass.getMethods()) { 78 | if (method.isAnnotationPresent(Command.class) 79 | && method.getName().equals(args[0]) 80 | && method.getParameterTypes().length == args.length - 1) { 81 | try { 82 | method.invoke(instance, 83 | (Object[]) Arrays.copyOfRange(args, 1, args.length)); 84 | return SUCCESS; 85 | } catch (IllegalArgumentException e) { 86 | throw new RuntimeException(e); 87 | } catch (IllegalAccessException e) { 88 | throw new RuntimeException(e); 89 | } catch (InvocationTargetException e) { 90 | if (method.isAnnotationPresent(OnException.class)) { 91 | OnException annotation = method 92 | .getAnnotation(OnException.class); 93 | if (annotation != null 94 | && annotation.value().equals( 95 | e.getCause().getClass())) { 96 | System.err.println(annotation.message()); 97 | return annotation.returnCode(); 98 | } 99 | } 100 | throw new RuntimeException(e); 101 | } 102 | } 103 | } 104 | help(); 105 | return SUCCESS; 106 | } 107 | 108 | public void help() { 109 | System.err.println("Usage: " + appName + " []"); 110 | 111 | 112 | for (Method method : klass.getMethods()) { 113 | 114 | if (method.isAnnotationPresent(Command.class)) { 115 | StringBuffer stringBuffer = new StringBuffer(); 116 | for (int i = 0; i < method.getParameterTypes().length; i++) { 117 | stringBuffer.append(" "); 118 | } 119 | 120 | System.err.println(String.format(" %-7s %s", method.getName(), 121 | stringBuffer.toString())); 122 | } 123 | } 124 | 125 | } 126 | 127 | } -------------------------------------------------------------------------------- /src/test/java/org/mule/farm/FarmTest.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm; 2 | 3 | import static org.junit.Assert.*; 4 | import static org.mule.farm.util.TestUtil.*; 5 | import static org.mule.farm.util.Util.*; 6 | 7 | import java.io.PrintStream; 8 | 9 | import org.junit.After; 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | import org.mule.barn.Barn; 13 | import org.mule.farm.main.FarmApp; 14 | import org.mule.farm.util.MockOutputStream; 15 | 16 | public class FarmTest { 17 | 18 | @Before 19 | public void setUp() { 20 | removeFolder("repo_eraseme"); 21 | createFolder("repo_eraseme"); 22 | } 23 | 24 | @After 25 | public void tearDown() { 26 | removeFolder("repo_eraseme"); 27 | } 28 | 29 | @Test 30 | public void testSanityCheck() { 31 | createFolder("foobar"); 32 | assertFolderExistenceWithRegex("foo.*"); 33 | assertFolderExistence("foobar"); 34 | removeFolder("foobar"); 35 | } 36 | 37 | @Test 38 | public void testContainers() { 39 | containerHelper("jboss4x", "jboss4x@4.2.3", "jboss-4.2.3.GA.zip"); 40 | containerHelper("jboss5x", "jboss5x", "jboss-5.1.0.GA.zip"); 41 | containerHelper("jboss6x", "jboss6x@6.1.0", "jboss6x-6.1.0.zip"); 42 | containerHelper("tomcat6x", "tomcat6x@6.0.32", 43 | "apache-tomcat-6.0.32.zip"); 44 | containerHelper("tomcat7x", "tomcat7x@6.0.20", 45 | "apache-tomcat-7.0.20.zip"); 46 | } 47 | 48 | @Test 49 | public void testLocalPut() { 50 | assertEquals( 51 | "Fetch the package from the Internet", 52 | Barn.SUCCESS, 53 | callFarmAppMainWithRepo("repo_eraseme", "put", "tomcat6x", 54 | "apache-tomcat-6.0.33.zip")); 55 | } 56 | 57 | @Test 58 | public void testRemotePut() { 59 | assertEquals( 60 | "Fetch the package from the Internet", 61 | Barn.SUCCESS, 62 | callFarmAppMainWithRepo( 63 | "repo_eraseme", 64 | "put", 65 | "tomcat6x", 66 | "http://mirrors.axint.net/apache/tomcat/tomcat-6/v6.0.33/bin/apache-tomcat-6.0.33.zip")); 67 | assertEquals( 68 | "Fetch the package from the Internet", 69 | Barn.SUCCESS, 70 | callFarmAppMainWithRepo( 71 | "repo_eraseme", 72 | "install", 73 | "tomcat6x")); 74 | } 75 | 76 | private void containerHelper(String name, String nameVersion, 77 | String zipFileName) { 78 | assertEquals("As the repo is new, nothing must be found here", 79 | FarmApp.ANIMAL_NOT_FOUND_ERROR, 80 | callFarmAppMainWithRepo("repo_eraseme", "install", name)); 81 | 82 | assertEquals( 83 | String.format("Adding [%s] to the repo", name), 84 | Barn.SUCCESS, 85 | callFarmAppMainWithRepo("repo_eraseme", "put", nameVersion, 86 | zipFileName)); 87 | 88 | assertEquals( 89 | String.format("Now I should retrieve [%s] successfully", name), 90 | Barn.SUCCESS, 91 | callFarmAppMainWithRepo("repo_eraseme", "install", name)); 92 | 93 | assertFolderExistence(name); 94 | } 95 | 96 | // @Test 97 | // public void testMule() { 98 | // 99 | // callFarmAppMain("alias", "mule-ee-distribution-standalone-mmc", 100 | // "mule-ee-distribution-standalone-mmc:::"); 101 | // 102 | // callFarmAppMain("breed", "mule-ee-distribution-standalone-mmc"); 103 | // assertFolderExistence("mule-ee-distribution-standalone-mmc"); 104 | // 105 | // callFarmAppMain("herd", "mmc-server"); 106 | // assertFileExistenceWithRegex("mmc-server.*\\.war"); 107 | // 108 | // callFarmAppMain("herd", "mmc-mule-app"); 109 | // assertFileExistenceWithRegex("mmc-mule-app.*\\.zip"); 110 | // } 111 | 112 | @Test 113 | public void testList() { 114 | 115 | MockOutputStream stdout = MockOutputStream.createWireTap(System.out); 116 | MockOutputStream stderr = MockOutputStream.createWireTap(System.err); 117 | System.setErr(new PrintStream(stderr)); 118 | System.setOut(new PrintStream(stdout)); 119 | callFarmAppMainWithRepo("repo_eraseme", "list"); 120 | assertEquals("No results found.\n", stderr.getContent()); 121 | 122 | assertEquals( 123 | Barn.SUCCESS, 124 | callFarmAppMainWithRepo("repo_eraseme", "put", 125 | "jboss6x@6.1.0", "jboss6x-6.1.0.zip")); 126 | assertEquals( 127 | Barn.SUCCESS, 128 | callFarmAppMainWithRepo("repo_eraseme", "put", 129 | "tomcat7x@7.0.20", "apache-tomcat-7.0.20.zip")); 130 | 131 | stdout = MockOutputStream.createWireTap(System.out); 132 | System.setOut(new PrintStream(stdout)); 133 | callFarmAppMainWithRepo("repo_eraseme", "list"); 134 | assertEquals("Available animals:\ntomcat7x\njboss6x\n", 135 | stdout.getContent()); 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.mule.farm 7 | farm 8 | 0.0.1 9 | jar 10 | 11 | farm 12 | http://maven.apache.org 13 | 14 | 15 | UTF-8 16 | 1.12 17 | 3.0.3 18 | 1.0-beta-7 19 | 20 | 21 | 22 | 23 | junit 24 | junit 25 | 4.8.2 26 | test 27 | 28 | 29 | org.codehaus.cargo 30 | cargo-core-uberjar 31 | 1.1.2 32 | 33 | 34 | org.sonatype.aether 35 | aether-api 36 | ${aetherVersion} 37 | 38 | 39 | org.sonatype.aether 40 | aether-util 41 | ${aetherVersion} 42 | 43 | 44 | org.sonatype.aether 45 | aether-impl 46 | ${aetherVersion} 47 | 48 | 49 | org.sonatype.aether 50 | aether-connector-file 51 | ${aetherVersion} 52 | 53 | 54 | org.sonatype.aether 55 | aether-connector-asynchttpclient 56 | ${aetherVersion} 57 | 58 | 59 | org.sonatype.aether 60 | aether-connector-wagon 61 | ${aetherVersion} 62 | 63 | 64 | org.apache.maven 65 | maven-aether-provider 66 | ${mavenVersion} 67 | 68 | 69 | org.apache.maven.wagon 70 | wagon-http 71 | ${wagonVersion} 72 | 73 | 74 | org.apache.commons 75 | commons-lang3 76 | 3.0.1 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-jar-plugin 85 | 2.2 86 | 87 | 88 | 89 | org.apache.maven.plugins 90 | maven-assembly-plugin 91 | 2.2-beta-4 92 | 93 | 94 | jar-with-dependencies 95 | 96 | 97 | 98 | org.mule.farm.main.FarmApp 99 | 100 | 101 | 102 | 103 | 104 | package 105 | 106 | single 107 | 108 | 109 | 110 | 111 | 112 | org.codehaus.mojo 113 | appassembler-maven-plugin 114 | 1.1.1 115 | 116 | 117 | 118 | org.mule.farm.main.FarmApp 119 | farm 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | org.apache.maven.plugins 131 | maven-checkstyle-plugin 132 | 2.7 133 | 134 | checkstyle.xml 135 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /src/main/java/org/mule/farm/impl/FarmRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package org.mule.farm.impl; 2 | 3 | import static org.mule.farm.util.Util.copy; 4 | 5 | import java.io.File; 6 | import java.io.FileFilter; 7 | import java.io.FileOutputStream; 8 | import java.io.FilenameFilter; 9 | import java.io.IOException; 10 | import java.net.MalformedURLException; 11 | import java.net.URL; 12 | import java.nio.channels.Channels; 13 | import java.nio.channels.ReadableByteChannel; 14 | import java.util.ArrayList; 15 | import java.util.Arrays; 16 | import java.util.Collection; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | import java.util.concurrent.Callable; 20 | import java.util.concurrent.ExecutionException; 21 | import java.util.concurrent.ExecutorService; 22 | import java.util.concurrent.Executors; 23 | import java.util.concurrent.Future; 24 | 25 | import org.apache.commons.lang3.StringUtils; 26 | import org.apache.commons.lang3.Validate; 27 | import org.apache.maven.repository.internal.DefaultServiceLocator; 28 | import org.apache.maven.repository.internal.MavenRepositorySystemSession; 29 | import org.codehaus.cargo.container.ContainerType; 30 | import org.codehaus.cargo.container.InstalledLocalContainer; 31 | import org.codehaus.cargo.container.configuration.ConfigurationType; 32 | import org.codehaus.cargo.container.configuration.LocalConfiguration; 33 | import org.codehaus.cargo.container.installer.Installer; 34 | import org.codehaus.cargo.container.installer.ZipURLInstaller; 35 | import org.codehaus.cargo.generic.DefaultContainerFactory; 36 | import org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory; 37 | import org.codehaus.cargo.util.log.LogLevel; 38 | import org.codehaus.cargo.util.log.Logger; 39 | import org.codehaus.cargo.util.log.SimpleLogger; 40 | import org.mule.farm.api.Animal; 41 | import org.mule.farm.api.ArtifactNotRegisteredException; 42 | import org.mule.farm.api.FarmRepository; 43 | import org.sonatype.aether.RepositorySystem; 44 | import org.sonatype.aether.artifact.Artifact; 45 | import org.sonatype.aether.connector.wagon.WagonProvider; 46 | import org.sonatype.aether.connector.wagon.WagonRepositoryConnectorFactory; 47 | import org.sonatype.aether.installation.InstallRequest; 48 | import org.sonatype.aether.installation.InstallResult; 49 | import org.sonatype.aether.installation.InstallationException; 50 | import org.sonatype.aether.repository.LocalRepository; 51 | import org.sonatype.aether.repository.RemoteRepository; 52 | import org.sonatype.aether.resolution.ArtifactRequest; 53 | import org.sonatype.aether.resolution.ArtifactResolutionException; 54 | import org.sonatype.aether.resolution.ArtifactResult; 55 | import org.sonatype.aether.spi.connector.RepositoryConnectorFactory; 56 | import org.sonatype.aether.util.artifact.DefaultArtifact; 57 | 58 | public class FarmRepositoryImpl implements FarmRepository { 59 | 60 | public static void start(String path) { 61 | Logger logger = new SimpleLogger(); 62 | LocalConfiguration configuration = (LocalConfiguration) new DefaultConfigurationFactory() 63 | .createConfiguration("tomcat6x", ContainerType.INSTALLED, 64 | ConfigurationType.STANDALONE); 65 | configuration.setLogger(logger); 66 | InstalledLocalContainer container = (InstalledLocalContainer) new DefaultContainerFactory() 67 | .createContainer("tomcat6x", ContainerType.INSTALLED, 68 | configuration); 69 | container.setHome(path); 70 | container.start(); 71 | 72 | } 73 | 74 | public static RepositorySystem newRepositorySystem() { 75 | DefaultServiceLocator locator = new DefaultServiceLocator(); 76 | 77 | locator.setServices(WagonProvider.class, new ManualWagonProvider()); 78 | 79 | locator.addService(RepositoryConnectorFactory.class, 80 | WagonRepositoryConnectorFactory.class); 81 | 82 | return locator.getService(RepositorySystem.class); 83 | } 84 | 85 | public static Installer fetchRemote(String name, String url) 86 | throws MalformedURLException { 87 | 88 | Installer installer = new ZipURLInstaller( 89 | new URL( 90 | !(url.startsWith("http://") || url 91 | .startsWith("https://")) ? ("file://" + url) 92 | : url)); 93 | Logger logger = new SimpleLogger(); 94 | logger.setLevel(LogLevel.DEBUG); 95 | installer.setLogger(logger); 96 | 97 | installer.install(); 98 | 99 | return installer; 100 | } 101 | 102 | private final class NoHiddenFilesFilter implements FilenameFilter { 103 | @Override 104 | public boolean accept(File arg0, String arg1) { 105 | if (arg1.startsWith("_")) { 106 | return false; 107 | } 108 | return true; 109 | } 110 | } 111 | 112 | private final class DirectoryFilter implements FileFilter { 113 | @Override 114 | public boolean accept(File pathname) { 115 | if (pathname.isDirectory()) 116 | return true; 117 | return false; 118 | } 119 | } 120 | 121 | private RepositorySystem repoSystem = newRepositorySystem(); 122 | private MavenRepositorySystemSession session; 123 | private Map animals; 124 | private String workingDirectory; 125 | 126 | public static FarmRepositoryImpl createFarmRepository(String repoPath) { 127 | return new FarmRepositoryImpl(repoPath, "."); 128 | } 129 | 130 | private FarmRepositoryImpl(String repoPath, String workingDirectory) { 131 | Validate.notNull(repoPath); 132 | Validate.notNull(workingDirectory); 133 | 134 | this.workingDirectory = workingDirectory; 135 | session = new MavenRepositorySystemSession(); 136 | 137 | LocalRepository localRepo = new LocalRepository(repoPath); 138 | session.setLocalRepositoryManager(repoSystem 139 | .newLocalRepositoryManager(localRepo)); 140 | 141 | animals = new HashMap(); 142 | 143 | File animalsPath = new File(StringUtils.join(new String[] { 144 | localRepo.getBasedir().getAbsolutePath(), "org", "mule", 145 | "farm", "animals" }, File.separator)); 146 | 147 | animalsPath.mkdirs(); 148 | 149 | File[] animals = animalsPath.listFiles(new DirectoryFilter()); 150 | 151 | for (File animal : animals) { 152 | for (File version : animal.listFiles(new DirectoryFilter())) { 153 | for (File file : version.listFiles(new NoHiddenFilesFilter())) { 154 | 155 | String[] splittedPath = file.getAbsolutePath().split("/"); 156 | String[] artifactData = splittedPath[splittedPath.length - 1] 157 | .split("-"); 158 | String artifactId = artifactData[0]; 159 | String[] arrayWithVersionAndExtension = artifactData[1] 160 | .split("\\."); 161 | 162 | Artifact artifact = new DefaultArtifact( 163 | "org.mule.farm.animals", artifactId, 164 | parseArtifactType(arrayWithVersionAndExtension), 165 | parseArtifactVersion(arrayWithVersionAndExtension)); 166 | 167 | add(artifactId, 168 | AnimalImpl 169 | .createAnimalFromArtifact(retrieveArtifactWithRequest(artifact))); 170 | } 171 | } 172 | } 173 | 174 | } 175 | 176 | private String parseArtifactType(String[] arrayWithVersionAndExtension) { 177 | String artifactType = StringUtils.join(Arrays.copyOfRange( 178 | arrayWithVersionAndExtension, 179 | arrayWithVersionAndExtension.length - 1, 180 | arrayWithVersionAndExtension.length), ""); 181 | return artifactType; 182 | } 183 | 184 | private String parseArtifactVersion(String[] arrayWithVersionAndExtension) { 185 | String artifactVersion = StringUtils.join(Arrays.copyOfRange( 186 | arrayWithVersionAndExtension, 0, 187 | arrayWithVersionAndExtension.length - 1), "."); 188 | return artifactVersion; 189 | } 190 | 191 | private void add(String name, Animal animal) { 192 | animals.put(name, animal); 193 | } 194 | 195 | private String downloadAndGetFileUrl(String url) { 196 | ExecutorService pool = Executors.newFixedThreadPool(1); 197 | URL realUrl = null; 198 | try { 199 | realUrl = new URL(url); 200 | } catch (MalformedURLException e1) { 201 | throw new RuntimeException(e1); 202 | } 203 | final ReadableByteChannel rbc; 204 | final File tmp; 205 | 206 | try { 207 | rbc = Channels.newChannel(realUrl.openStream()); 208 | tmp = File.createTempFile("farmdownload", null); 209 | tmp.deleteOnExit(); 210 | final FileOutputStream fos = new FileOutputStream(tmp); 211 | Future f = pool.submit(new Callable() { 212 | 213 | @Override 214 | public String call() { 215 | try { 216 | fos.getChannel().transferFrom(rbc, 0, 1 << 24); 217 | } catch (IOException e) { 218 | throw new RuntimeException(e); 219 | } 220 | 221 | return tmp.getAbsolutePath(); 222 | } 223 | }); 224 | 225 | System.err.print("Downloading"); 226 | while (!f.isDone()) { 227 | System.err.print("."); 228 | try { 229 | Thread.sleep(1000); 230 | } catch (InterruptedException e) { 231 | } 232 | } 233 | System.err.println(" done"); 234 | return f.get(); 235 | } catch (IOException e) { 236 | throw new RuntimeException(e); 237 | } catch (InterruptedException e) { 238 | throw new RuntimeException(e); 239 | } catch (ExecutionException e) { 240 | throw new RuntimeException(e); 241 | } 242 | } 243 | 244 | private Animal addAndInstall(String name, String url, Animal animal) { 245 | animals.put(name, animal); 246 | 247 | if (url.startsWith("http://") || url.startsWith("https://")) { 248 | url = downloadAndGetFileUrl(url); 249 | } 250 | 251 | Artifact jarArtifact = animal.getArtifact(); 252 | jarArtifact = jarArtifact.setFile(new File(url)); 253 | 254 | InstallRequest installRequest = new InstallRequest(); 255 | installRequest.addArtifact(jarArtifact); 256 | 257 | InstallResult installResult = null; 258 | 259 | try { 260 | installResult = repoSystem.install(session, installRequest); 261 | } catch (InstallationException e) { 262 | e.printStackTrace(); 263 | throw new RuntimeException(); 264 | } 265 | Collection artifacts = installResult.getArtifacts(); 266 | if (artifacts.isEmpty()) { 267 | throw new RuntimeException(); 268 | } 269 | 270 | return AnimalImpl.createAnimalFromArtifact(artifacts.iterator().next()); 271 | } 272 | 273 | private Artifact doHerd(String alias) throws ArtifactNotRegisteredException { 274 | Animal animal = animals.get(alias); 275 | 276 | if (animal == null) { 277 | throw new ArtifactNotRegisteredException(); 278 | } 279 | 280 | Artifact artifact = animal.getArtifact(); 281 | 282 | return retrieveArtifactWithRequest(artifact); 283 | } 284 | 285 | private Artifact retrieveArtifactWithRequest(Artifact artifact) { 286 | ArtifactRequest artifactRequest = new ArtifactRequest(); 287 | 288 | artifactRequest.setArtifact(artifact); 289 | artifactRequest 290 | .addRepository(new RemoteRepository("mule", "default", 291 | "http://dev.ee.mulesource.com/repository/content/repositories/snapshots")); 292 | 293 | try { 294 | ArtifactResult artifactResult = repoSystem.resolveArtifact(session, 295 | artifactRequest); 296 | artifact = artifactResult.getArtifact(); 297 | } catch (ArtifactResolutionException e) { 298 | e.printStackTrace(); 299 | throw new RuntimeException(); 300 | } 301 | 302 | return artifact; 303 | } 304 | 305 | /* 306 | * (non-Javadoc) 307 | * 308 | * @see org.mule.farm.main.FarmRepository#breed(java.lang.String) 309 | */ 310 | @Override 311 | public Animal install(String alias) throws ArtifactNotRegisteredException { 312 | Artifact artifact = get(alias).getArtifact(); 313 | 314 | try { 315 | fetchRemote(artifact.getArtifactId(), artifact.getFile().toString()); 316 | } catch (MalformedURLException e) { 317 | e.printStackTrace(); 318 | throw new RuntimeException(); 319 | } 320 | 321 | return AnimalImpl.createAnimalFromArtifact(artifact); 322 | } 323 | 324 | /* 325 | * (non-Javadoc) 326 | * 327 | * @see org.mule.farm.main.FarmRepository#get(java.lang.String) 328 | */ 329 | @Override 330 | public Animal get(String alias) throws ArtifactNotRegisteredException { 331 | Artifact artifact = doHerd(alias); 332 | 333 | String path = artifact.getFile().getPath(); 334 | String[] splittedPath = path.split(File.separator); 335 | 336 | copy(artifact.getFile().toString(), workingDirectory + File.separator 337 | + splittedPath[splittedPath.length - 1]); 338 | 339 | return AnimalImpl.createAnimalFromArtifact(artifact); 340 | } 341 | 342 | /* 343 | * (non-Javadoc) 344 | * 345 | * @see org.mule.farm.main.FarmRepository#summon(java.lang.String, 346 | * java.lang.String, java.lang.String) 347 | */ 348 | @Override 349 | public Animal put(String alias, String version, String url) { 350 | return addAndInstall(alias, url, 351 | AnimalImpl.createAnimalFromArtifact(new DefaultArtifact( 352 | "org.mule.farm.animals", alias, "zip", version))); 353 | } 354 | 355 | /* 356 | * (non-Javadoc) 357 | * 358 | * @see org.mule.farm.main.FarmRepository#list() 359 | */ 360 | @Override 361 | public Collection list() { 362 | return animals.size() == 0 ? new ArrayList() : animals.values(); 363 | } 364 | 365 | } --------------------------------------------------------------------------------