@@ -0,0 +1,3446 @@
+package ahlers.phantom.embedded;%0A%0Aimport de.flapdoodle.embed.process.config.store.FileSet;%0Aimport de.flapdoodle.embed.process.config.store.FileType;%0Aimport de.flapdoodle.embed.process.config.store.IPackageResolver;%0Aimport de.flapdoodle.embed.process.distribution.ArchiveType;%0Aimport de.flapdoodle.embed.process.distribution.Distribution;%0A%0Aimport static de.flapdoodle.embed.process.distribution.ArchiveType.TBZ2;%0Aimport static de.flapdoodle.embed.process.distribution.ArchiveType.ZIP;%0Aimport static de.flapdoodle.embed.process.distribution.Platform.Linux;%0A%0A/**%0A * Uses %7B%7Benum%7D%7D singleton pattern described by %3Cem%3EItem 3%3C/em%3E from %3Cem%3EEffective Java%3C/em%3E.%0A *%0A * @author %5B%5Bmailto:michael@ahlers.consulting Michael Ahlers%5D%5D%0A */%0Apublic enum PhantomPackageResolver%0A        implements IPackageResolver %7B%0A%0A    INSTANCE;%0A%0A    public static PhantomPackageResolver getInstance() %7B%0A        return INSTANCE;%0A    %7D%0A%0A    @Override%0A    public ArchiveType getArchiveType(final Distribution distribution) %7B%0A        switch (distribution.getPlatform()) %7B%0A            case Linux:%0A                return TBZ2;%0A            case OS_X:%0A            case Windows:%0A                return ZIP;%0A            default:%0A                throw new UnsupportedPlatformException(distribution);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public String getPath(final Distribution distribution) %7B%0A        final String version = distribution.getVersion().asInDownloadPath();%0A%0A        final String classifier;%0A%0A        switch (distribution.getPlatform()) %7B%0A            case Linux:%0A                classifier = %22linux%22;%0A                break;%0A            case OS_X:%0A                classifier = %22macosx%22;%0A                break;%0A            case Windows:%0A                classifier = %22windows%22;%0A                break;%0A            default:%0A                throw new UnsupportedPlatformException(distribution);%0A        %7D%0A%0A        final String bitsize;%0A%0A        if (Linux == distribution.getPlatform()) %7B%0A            switch (distribution.getBitsize()) %7B%0A                case B32:%0A                    bitsize = %22i686%22;%0A                    break;%0A                case B64:%0A                    bitsize = %22x86_64%22;%0A                    break;%0A%0A                default:%0A                    throw new UnsupportedBitsizeException(distribution);%0A%0A            %7D%0A        %7D else %7B%0A            bitsize = null;%0A        %7D%0A%0A        final String extension;%0A%0A        switch (getArchiveType(distribution)) %7B%0A            case TBZ2:%0A                extension = %22tar.bz2%22;%0A                break;%0A            case ZIP:%0A                extension = %22zip%22;%0A                break;%0A            default:%0A                throw new UnsupportedArchiveException(distribution, getArchiveType(distribution));%0A        %7D%0A%0A        return String.format(%22phantomjs-%25s-%25s%25s.%25s%22, version, classifier, null == bitsize ? %22%22 : %22-%22 + bitsize, extension);%0A    %7D%0A%0A    @Override%0A    public FileSet getFileSet(final Distribution distribution) %7B%0A        final FileSet.Builder builder = FileSet.builder();%0A%0A        switch (distribution.getPlatform()) %7B%0A            case Linux:%0A            case OS_X:%0A                builder.addEntry(FileType.Executable, %22phantomjs%22);%0A                break;%0A            case Windows:%0A                builder.addEntry(FileType.Executable, %22phantomjs.exe%22);%0A                break;%0A            default:%0A                throw new UnsupportedPlatformException(distribution);%0A        %7D%0A%0A        return builder.build();%0A    %7D%0A%7D%0A

Resolve distribution detail to a specific archive and file set