├── .editorconfig ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── deploy.sh ├── docker-compose.yml ├── phantomjs-maven-core ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── klieber │ │ │ └── phantomjs │ │ │ ├── PhantomJsException.java │ │ │ ├── archive │ │ │ ├── AbstractArchive.java │ │ │ ├── Archive.java │ │ │ ├── ArchiveFactory.java │ │ │ ├── CustomBaseUrlArchive.java │ │ │ ├── TemplatedArchive.java │ │ │ ├── UnsupportedPlatformException.java │ │ │ └── mapping │ │ │ │ ├── ArchiveFormat.java │ │ │ │ ├── ArchiveMapping.java │ │ │ │ ├── ArchiveMappings.java │ │ │ │ ├── ArchiveSpec.java │ │ │ │ └── OperatingSystemSpec.java │ │ │ ├── cache │ │ │ ├── ArchiveCache.java │ │ │ └── ArchiveCacheFactory.java │ │ │ ├── download │ │ │ ├── DownloadException.java │ │ │ ├── Downloader.java │ │ │ ├── DownloaderFactory.java │ │ │ ├── RepositoryDownloader.java │ │ │ └── WebDownloader.java │ │ │ ├── exec │ │ │ ├── ExecutionException.java │ │ │ ├── PhantomJsExecutor.java │ │ │ └── PhantomJsProcessBuilder.java │ │ │ ├── extract │ │ │ ├── ArchiveExtractor.java │ │ │ └── ExtractionException.java │ │ │ ├── install │ │ │ ├── InstallationException.java │ │ │ ├── Installer.java │ │ │ ├── InstallerFactory.java │ │ │ └── PhantomJsInstaller.java │ │ │ ├── resolve │ │ │ ├── ArchiveResolver.java │ │ │ ├── CompositeResolver.java │ │ │ ├── PathResolver.java │ │ │ ├── PhantomJsResolver.java │ │ │ ├── PhantomJsResolverOptions.java │ │ │ ├── RepositoryDetails.java │ │ │ ├── Resolver.java │ │ │ └── ResolverFactory.java │ │ │ ├── sys │ │ │ ├── LinuxProperties.java │ │ │ ├── SystemProperties.java │ │ │ └── os │ │ │ │ ├── OperatingSystem.java │ │ │ │ └── OperatingSystemFactory.java │ │ │ └── util │ │ │ ├── ArtifactBuilder.java │ │ │ └── VersionUtil.java │ └── resources │ │ └── archive-mapping.yaml │ └── test │ ├── config │ └── test-archive.tar.gz │ ├── java │ └── com │ │ └── github │ │ └── klieber │ │ └── phantomjs │ │ ├── archive │ │ ├── AbstractArchiveTest.java │ │ ├── ArchiveFactoryTest.java │ │ ├── CustomBaseUrlArchiveTest.java │ │ ├── TemplatedArchiveTest.java │ │ └── mapping │ │ │ ├── ArchiveFormatTest.java │ │ │ └── ArchiveSpecTest.java │ │ ├── cache │ │ └── ArchiveCacheTest.java │ │ ├── download │ │ ├── DownloaderFactoryTest.java │ │ ├── RepositoryDownloaderTest.java │ │ └── WebDownloaderTest.java │ │ ├── exec │ │ ├── PhantomJsExecutorTest.java │ │ └── PhantomJsProcessBuilderTest.java │ │ ├── extract │ │ └── ArchiveExtractorTest.java │ │ ├── install │ │ └── PhantomJsInstallerTest.java │ │ ├── resolve │ │ ├── ArchiveResolverTest.java │ │ ├── CompositeResolverTest.java │ │ ├── PathResolverTest.java │ │ ├── PhantomJsResolverTest.java │ │ ├── RepositoryDetailsTest.java │ │ └── ResolverFactoryTest.java │ │ ├── sys │ │ ├── LinuxPropertiesTest.java │ │ ├── SystemPropertiesTest.java │ │ └── os │ │ │ └── OperatingSystemFactoryTest.java │ │ ├── test │ │ └── MockPhantomJsBinary.java │ │ └── util │ │ ├── ArtifactBuilderTest.java │ │ └── VersionUtilTest.java │ └── resources │ └── test-linux.properties ├── phantomjs-maven-plugin ├── pom.xml └── src │ ├── it │ ├── download-from-repository │ │ ├── hello.js │ │ ├── pom.xml │ │ ├── prebuild.groovy │ │ └── verify.groovy │ ├── download-from-url │ │ ├── hello.js │ │ ├── pom.xml │ │ ├── prebuild.groovy │ │ └── verify.groovy │ ├── exec-abnormal-exit-code │ │ ├── badscript.js │ │ ├── invoker.properties │ │ ├── pom.xml │ │ └── verify.groovy │ ├── exec-with-args │ │ ├── hello.js │ │ ├── pom.xml │ │ └── verify.groovy │ ├── exec-with-command-line-options │ │ ├── hello.js │ │ ├── pom.xml │ │ └── verify.groovy │ ├── exec-with-config-file │ │ ├── config.json │ │ ├── index.html │ │ ├── pom.xml │ │ ├── store-cookie.js │ │ └── verify.groovy │ ├── settings.xml │ ├── simple-it │ │ ├── hello.js │ │ ├── pom.xml │ │ └── verify.groovy │ ├── with-integration-tests │ │ ├── pom.xml │ │ ├── src │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── example │ │ │ │ └── ExampleTest.java │ │ └── verify.groovy │ └── with-jasmine-maven-plugin-it │ │ ├── pom.xml │ │ ├── src │ │ ├── main │ │ │ └── javascript │ │ │ │ └── HelloWorld.js │ │ └── test │ │ │ └── javascript │ │ │ └── HelloWorldSpec.js │ │ └── verify.groovy │ ├── main │ └── java │ │ └── com │ │ └── github │ │ └── klieber │ │ └── phantomjs │ │ └── mojo │ │ ├── AbstractPhantomJsMojo.java │ │ ├── ExecPhantomJsMojo.java │ │ └── InstallPhantomJsMojo.java │ ├── site │ ├── markdown │ │ └── index.md.vm │ ├── resources │ │ ├── .nojekyll │ │ └── googleaf8abcbec6fb6df5.html │ └── site.xml │ └── test │ └── java │ └── com │ └── github │ └── klieber │ └── phantomjs │ └── mojo │ ├── AbstractPhantomJsMojoTest.java │ ├── ExecPhantomJsMojoTest.java │ └── InstallPhantomJsMojoTest.java └── pom.xml /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | charset = utf-8 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .project 3 | .metadata 4 | bin/** 5 | tmp/** 6 | tmp/**/* 7 | *.tmp 8 | *.bak 9 | *.swp 10 | *~.nib 11 | local.properties 12 | .classpath 13 | .settings/ 14 | .loadpath 15 | .externalToolBuilders/ 16 | *.iml 17 | *.ipr 18 | *.iws 19 | .idea/ 20 | jacoco.exec 21 | *.orig 22 | *.versionsBackup 23 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | addons: 4 | sonarqube: 5 | organization: "klieber-github" 6 | token: 7 | secure: "NIWa7GR42liyZIu0Uooa8NpkKk64tVl/8Vj7IWqcrCnhx90vfmTd1YCYbyqwJ6xcUFjZKBvJJOAcBvFSuV7S1wRIYPDEmC8GPG8Nm22SactoooDRkmaEqlF5jvsJudppn+zRhfV0bBDKiokIltHK9sk/HqqoFt71dsrzCRsGUV8=" 8 | jdk: 9 | - oraclejdk8 10 | script: mvn verify sonar:sonar -Prun-its 11 | after_success: 12 | - mvn clean prepare-package jacoco:report coveralls:report 13 | cache: 14 | directories: 15 | - '$HOME/.m2/repository' 16 | - '$HOME/.sonar/cache' 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 - 2017, Kyle Lieber 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! "$1" ]; then 4 | echo 'please provide the version' 5 | exit 1; 6 | fi 7 | 8 | mkdir -p target/binary-deployer 9 | cd target/binary-deployer 10 | 11 | groupId=com.github.klieber 12 | artifactId=phantomjs 13 | version=$1 14 | 15 | baseUrl="https://bitbucket.org/ariya/phantomjs/downloads" 16 | #baseUrl="https://phantomjs.googlecode.com/files" 17 | 18 | sonatypeUrl="https://oss.sonatype.org/service/local/staging/deploy/maven2/" 19 | repoId=ossrh 20 | 21 | deploy() { 22 | classifier=$1 23 | extension=$2 24 | filename="$artifactId-$version-$classifier.$extension" 25 | echo "deploying $baseUrl/$filename" 26 | 27 | wget "$baseUrl/$filename" && mvn gpg:sign-and-deploy-file -Durl=$sonatypeUrl -DrepositoryId=$repoId -Dfile=$filename -DgroupId=$groupId -DartifactId=$artifactId -Dversion=$version -Dpackaging=$extension -Dclassifier=$classifier -DgeneratePom=false 28 | } 29 | 30 | deploy "windows" "zip" 31 | deploy "macosx" "zip" 32 | deploy "linux-x86_64" "tar.bz2" 33 | deploy "linux-i686" "tar.bz2" 34 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | maven: 4 | image: maven:3.3.9-jdk-8 5 | command: mvn clean verify 6 | working_dir: /usr/src/project 7 | volumes: 8 | - .:/usr/src/project 9 | - mvn-home:/root/.m2 10 | stdin_open: true 11 | tty: true 12 | volumes: 13 | mvn-home: 14 | -------------------------------------------------------------------------------- /phantomjs-maven-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.github.klieber 6 | phantomjs-maven 7 | 0.8-SNAPSHOT 8 | 9 | 10 | phantomjs-maven-core 11 | 12 | PhantomJS Maven Core 13 | A library for downloading, installing, and executing phantomjs. 14 | 15 | 16 | 17 | org.apache.maven 18 | maven-core 19 | 20 | 21 | org.codehaus.plexus 22 | plexus-utils 23 | 24 | 25 | org.eclipse.aether 26 | aether-api 27 | 28 | 29 | org.eclipse.aether 30 | aether-util 31 | 32 | 33 | de.schlichtherle.truezip 34 | truezip-driver-zip 35 | 36 | 37 | de.schlichtherle.truezip 38 | truezip-driver-tar 39 | 40 | 41 | de.schlichtherle.truezip 42 | truezip-file 43 | 44 | 45 | org.slf4j 46 | slf4j-api 47 | 48 | 49 | com.fasterxml.jackson.dataformat 50 | jackson-dataformat-yaml 51 | 52 | 53 | com.fasterxml.jackson.core 54 | jackson-annotations 55 | 56 | 57 | com.fasterxml.jackson.core 58 | jackson-databind 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/PhantomJsException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs; 27 | 28 | public class PhantomJsException extends Exception { 29 | 30 | public PhantomJsException(String message) { 31 | super(message); 32 | } 33 | 34 | public PhantomJsException(String message, Throwable cause) { 35 | super(message, cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/AbstractArchive.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive; 27 | 28 | public abstract class AbstractArchive implements Archive { 29 | 30 | protected abstract String getBaseUrl(); 31 | 32 | @Override 33 | public final String getUrl() { 34 | String baseUrl = this.getBaseUrl(); 35 | StringBuilder url = new StringBuilder(); 36 | url.append(baseUrl); 37 | if (!baseUrl.endsWith("/")) { 38 | url.append('/'); 39 | } 40 | url.append(this.getArchiveName()); 41 | return url.toString(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/Archive.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive; 27 | 28 | public interface Archive { 29 | String getUrl(); 30 | String getExtension(); 31 | String getArchiveName(); 32 | String getPathToExecutable(); 33 | String getVersion(); 34 | String getClassifier(); 35 | } 36 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/ArchiveFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive; 27 | 28 | import com.fasterxml.jackson.databind.ObjectMapper; 29 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; 30 | import com.github.klieber.phantomjs.archive.mapping.ArchiveMapping; 31 | import com.github.klieber.phantomjs.archive.mapping.ArchiveMappings; 32 | import com.github.klieber.phantomjs.resolve.PhantomJsResolverOptions; 33 | import com.github.klieber.phantomjs.sys.os.OperatingSystem; 34 | import com.github.klieber.phantomjs.sys.os.OperatingSystemFactory; 35 | import org.slf4j.Logger; 36 | import org.slf4j.LoggerFactory; 37 | 38 | import javax.inject.Inject; 39 | import javax.inject.Named; 40 | import java.io.IOException; 41 | import java.net.URL; 42 | 43 | @Named 44 | public class ArchiveFactory { 45 | 46 | private static final Logger LOGGER = LoggerFactory.getLogger(ArchiveFactory.class); 47 | 48 | private final OperatingSystemFactory operatingSystemFactory; 49 | 50 | @Inject 51 | public ArchiveFactory(OperatingSystemFactory operatingSystemFactory) { 52 | this.operatingSystemFactory = operatingSystemFactory; 53 | } 54 | 55 | public Archive create(PhantomJsResolverOptions options) { 56 | return create(options.getVersion(), options.getBaseUrl()); 57 | } 58 | 59 | public Archive create(String version, String baseUrl) { 60 | Archive archive = create(version); 61 | 62 | if (baseUrl != null) { 63 | archive = new CustomBaseUrlArchive(archive, baseUrl); 64 | } 65 | 66 | return archive; 67 | } 68 | 69 | public Archive create(String version) { 70 | 71 | OperatingSystem operatingSystem = this.operatingSystemFactory.create(); 72 | 73 | Archive archive = null; 74 | 75 | ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); 76 | URL resource = ArchiveFactory.class.getResource("/archive-mapping.yaml"); 77 | try { 78 | ArchiveMappings archiveMappings = mapper.readValue(resource, ArchiveMappings.class); 79 | for (ArchiveMapping archiveMapping : archiveMappings.getMappings()) { 80 | if (archiveMapping.getSpec().matches(version, operatingSystem)) { 81 | archive = new TemplatedArchive(archiveMapping.getFormat(), version); 82 | break; 83 | } 84 | } 85 | } catch (IOException e) { 86 | LOGGER.error("Unable to read archive-mapping.yaml", e); 87 | } 88 | if (archive == null) { 89 | throw new UnsupportedPlatformException(operatingSystem); 90 | } 91 | return archive; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/CustomBaseUrlArchive.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive; 27 | 28 | public class CustomBaseUrlArchive extends AbstractArchive { 29 | 30 | private final Archive delegate; 31 | private final String baseUrl; 32 | 33 | public CustomBaseUrlArchive(Archive delegate, String baseUrl) { 34 | this.delegate = delegate; 35 | this.baseUrl = baseUrl; 36 | } 37 | 38 | @Override 39 | protected String getBaseUrl() { 40 | return this.baseUrl; 41 | } 42 | 43 | @Override 44 | public String getExtension() { 45 | return delegate.getExtension(); 46 | } 47 | 48 | @Override 49 | public String getArchiveName() { 50 | return delegate.getArchiveName(); 51 | } 52 | 53 | @Override 54 | public String getPathToExecutable() { 55 | return delegate.getPathToExecutable(); 56 | } 57 | 58 | @Override 59 | public String getVersion() { 60 | return delegate.getVersion(); 61 | } 62 | 63 | @Override 64 | public String getClassifier() { 65 | return delegate.getClassifier(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/TemplatedArchive.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive; 27 | 28 | import com.github.klieber.phantomjs.archive.mapping.ArchiveFormat; 29 | 30 | public class TemplatedArchive extends AbstractArchive { 31 | 32 | private final ArchiveFormat archiveFormat; 33 | private final String version; 34 | 35 | public TemplatedArchive(ArchiveFormat archiveFormat, 36 | String version) { 37 | this.archiveFormat = archiveFormat; 38 | this.version = version; 39 | } 40 | 41 | @Override 42 | public String getBaseUrl() { 43 | return applyTemplate(this.archiveFormat.getBaseUrlTemplate()); 44 | } 45 | 46 | @Override 47 | public String getExtension() { 48 | return this.archiveFormat.getExtension(); 49 | } 50 | 51 | @Override 52 | public String getArchiveName() { 53 | return applyTemplate(this.archiveFormat.getFileTemplate()); 54 | } 55 | 56 | @Override 57 | public String getPathToExecutable() { 58 | return applyTemplate(this.archiveFormat.getExecutableTemplate()); 59 | } 60 | 61 | @Override 62 | public String getVersion() { 63 | return version; 64 | } 65 | 66 | @Override 67 | public String getClassifier() { 68 | return this.archiveFormat.getClassifier(); 69 | } 70 | 71 | private String applyTemplate(String template) { 72 | return template 73 | .replaceAll("\\{version}", this.version) 74 | .replaceAll("\\{classifier}", this.archiveFormat.getClassifier()) 75 | .replaceAll("\\{extension}", this.archiveFormat.getExtension()); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/UnsupportedPlatformException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive; 27 | 28 | import com.github.klieber.phantomjs.sys.os.OperatingSystem; 29 | 30 | public class UnsupportedPlatformException extends RuntimeException { 31 | 32 | private static final String MESSAGE = "Unsupported platform: %s"; 33 | 34 | public UnsupportedPlatformException(OperatingSystem operatingSystem) { 35 | super(String.format(MESSAGE, operatingSystem)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/mapping/ArchiveFormat.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive.mapping; 27 | 28 | import com.fasterxml.jackson.annotation.JsonCreator; 29 | import com.fasterxml.jackson.annotation.JsonProperty; 30 | 31 | public class ArchiveFormat { 32 | 33 | private final String baseUrlTemplate; 34 | private final String fileTemplate; 35 | private final String executableTemplate; 36 | private final String classifier; 37 | private final String extension; 38 | 39 | @JsonCreator 40 | public ArchiveFormat(@JsonProperty("baseUrlTemplate") String baseUrlTemplate, 41 | @JsonProperty("fileTemplate") String fileTemplate, 42 | @JsonProperty("executableTemplate") String executableTemplate, 43 | @JsonProperty("classifier") String classifier, 44 | @JsonProperty("extension") String extension) { 45 | this.baseUrlTemplate = baseUrlTemplate; 46 | this.fileTemplate = fileTemplate; 47 | this.executableTemplate = executableTemplate; 48 | this.classifier = classifier; 49 | this.extension = extension; 50 | } 51 | 52 | public String getBaseUrlTemplate() { 53 | return baseUrlTemplate; 54 | } 55 | 56 | public String getFileTemplate() { 57 | return fileTemplate; 58 | } 59 | 60 | public String getExecutableTemplate() { 61 | return executableTemplate; 62 | } 63 | 64 | public String getClassifier() { 65 | return classifier; 66 | } 67 | 68 | public String getExtension() { 69 | return extension; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/mapping/ArchiveMapping.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive.mapping; 27 | 28 | import com.fasterxml.jackson.annotation.JsonCreator; 29 | import com.fasterxml.jackson.annotation.JsonProperty; 30 | 31 | public class ArchiveMapping { 32 | 33 | private final ArchiveSpec spec; 34 | private final ArchiveFormat format; 35 | 36 | @JsonCreator 37 | public ArchiveMapping(@JsonProperty("spec") ArchiveSpec spec, 38 | @JsonProperty("archive") ArchiveFormat format) { 39 | this.spec = spec; 40 | this.format = format; 41 | } 42 | 43 | public ArchiveSpec getSpec() { 44 | return spec; 45 | } 46 | 47 | public ArchiveFormat getFormat() { 48 | return format; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/mapping/ArchiveMappings.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive.mapping; 27 | 28 | import com.fasterxml.jackson.annotation.JsonCreator; 29 | 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | 33 | public class ArchiveMappings { 34 | 35 | private final List mappings; 36 | 37 | @JsonCreator 38 | public ArchiveMappings() { 39 | this.mappings = new ArrayList(); 40 | } 41 | 42 | public List getMappings() { 43 | return mappings; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/mapping/ArchiveSpec.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive.mapping; 27 | 28 | import com.fasterxml.jackson.annotation.JsonCreator; 29 | import com.fasterxml.jackson.annotation.JsonProperty; 30 | import com.github.klieber.phantomjs.sys.os.OperatingSystem; 31 | import com.github.klieber.phantomjs.util.VersionUtil; 32 | 33 | public class ArchiveSpec { 34 | 35 | private final String versionSpec; 36 | private final OperatingSystemSpec operatingSystemSpec; 37 | 38 | @JsonCreator 39 | public ArchiveSpec(@JsonProperty("version") String versionSpec, 40 | @JsonProperty("operatingSystem") OperatingSystemSpec operatingSystemSpec) { 41 | this.versionSpec = versionSpec; 42 | this.operatingSystemSpec = operatingSystemSpec; 43 | } 44 | 45 | public String getVersionSpec() { 46 | return versionSpec; 47 | } 48 | 49 | public OperatingSystemSpec getOperatingSystemSpec() { 50 | return operatingSystemSpec; 51 | } 52 | 53 | public boolean matches(String version, OperatingSystem operatingSystem) { 54 | return VersionUtil.isWithin(versionNumberOnly(version), this.versionSpec) && 55 | this.operatingSystemSpec.matches(operatingSystem); 56 | } 57 | 58 | private String versionNumberOnly(String version) { 59 | return version.replaceAll("[^0-9.]", ""); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/mapping/OperatingSystemSpec.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive.mapping; 27 | 28 | import com.fasterxml.jackson.annotation.JsonCreator; 29 | import com.fasterxml.jackson.annotation.JsonProperty; 30 | import com.github.klieber.phantomjs.sys.os.OperatingSystem; 31 | import com.github.klieber.phantomjs.util.VersionUtil; 32 | 33 | public class OperatingSystemSpec extends OperatingSystem { 34 | 35 | @JsonCreator 36 | public OperatingSystemSpec(@JsonProperty("name") String name, 37 | @JsonProperty("architecture") String architecture, 38 | @JsonProperty("version") String version, 39 | @JsonProperty("distribution") String distribution, 40 | @JsonProperty("distributionVersion") String distributionVersion) { 41 | super(name, architecture, version, distribution, distributionVersion); 42 | } 43 | 44 | public boolean matches(OperatingSystem operatingSystem) { 45 | return 46 | contains(operatingSystem.getName(), this.getName()) && 47 | withinVersion(operatingSystem.getVersion(), this.getVersion()) && 48 | contains(operatingSystem.getArchitecture(), this.getArchitecture()) && 49 | contains(operatingSystem.getDistribution(), this.getDistribution()) && 50 | withinVersion(operatingSystem.getDistributionVersion(), this.getDistributionVersion()); 51 | } 52 | 53 | private boolean contains(String actualValue, String partialValue) { 54 | return partialValue == null || 55 | (actualValue != null && actualValue.toLowerCase().contains(partialValue.toLowerCase())); 56 | } 57 | 58 | private boolean withinVersion(String version, String versionSpec) { 59 | return versionSpec == null || 60 | (version != null && VersionUtil.isWithin(version, versionSpec)); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/cache/ArchiveCache.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.cache; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import com.github.klieber.phantomjs.util.ArtifactBuilder; 30 | import org.eclipse.aether.RepositorySystemSession; 31 | import org.eclipse.aether.artifact.Artifact; 32 | import org.eclipse.aether.repository.LocalRepositoryManager; 33 | 34 | import java.io.File; 35 | 36 | public class ArchiveCache { 37 | 38 | private final ArtifactBuilder artifactBuilder; 39 | private final RepositorySystemSession repositorySystemSession; 40 | 41 | public ArchiveCache(ArtifactBuilder artifactBuilder, 42 | RepositorySystemSession repositorySystemSession) { 43 | this.artifactBuilder = artifactBuilder; 44 | this.repositorySystemSession = repositorySystemSession; 45 | } 46 | 47 | public File getFile(Archive archive) { 48 | Artifact artifact = artifactBuilder.createArtifact(archive); 49 | LocalRepositoryManager manager = repositorySystemSession.getLocalRepositoryManager(); 50 | return new File(manager.getRepository().getBasedir(), manager.getPathForLocalArtifact(artifact)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/cache/ArchiveCacheFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.cache; 27 | 28 | import com.github.klieber.phantomjs.util.ArtifactBuilder; 29 | import org.eclipse.aether.RepositorySystemSession; 30 | 31 | import javax.inject.Inject; 32 | import javax.inject.Named; 33 | 34 | @Named 35 | public class ArchiveCacheFactory { 36 | 37 | private final ArtifactBuilder artifactBuilder; 38 | 39 | @Inject 40 | public ArchiveCacheFactory(ArtifactBuilder artifactBuilder) { 41 | this.artifactBuilder = artifactBuilder; 42 | } 43 | 44 | public ArchiveCache create(RepositorySystemSession repositorySystemSession) { 45 | return new ArchiveCache(artifactBuilder, repositorySystemSession); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/download/DownloadException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.download; 27 | 28 | import com.github.klieber.phantomjs.PhantomJsException; 29 | 30 | public class DownloadException extends PhantomJsException { 31 | 32 | public DownloadException(String message) { 33 | super(message); 34 | } 35 | 36 | public DownloadException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/download/Downloader.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.download; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | 30 | import java.io.File; 31 | 32 | public interface Downloader { 33 | File download(Archive archive) throws DownloadException; 34 | } 35 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/download/DownloaderFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.download; 27 | 28 | import com.github.klieber.phantomjs.cache.ArchiveCache; 29 | import com.github.klieber.phantomjs.cache.ArchiveCacheFactory; 30 | import com.github.klieber.phantomjs.resolve.PhantomJsResolverOptions; 31 | import com.github.klieber.phantomjs.resolve.RepositoryDetails; 32 | import com.github.klieber.phantomjs.util.ArtifactBuilder; 33 | 34 | import javax.inject.Inject; 35 | import javax.inject.Named; 36 | 37 | @Named 38 | public class DownloaderFactory { 39 | 40 | private final ArtifactBuilder artifactBuilder; 41 | private final ArchiveCacheFactory archiveCacheFactory; 42 | 43 | @Inject 44 | public DownloaderFactory(ArtifactBuilder artifactBuilder, 45 | ArchiveCacheFactory archiveCacheFactory) { 46 | this.archiveCacheFactory = archiveCacheFactory; 47 | this.artifactBuilder = artifactBuilder; 48 | } 49 | 50 | public Downloader create(PhantomJsResolverOptions options, 51 | RepositoryDetails repositoryDetails) { 52 | return isRepositorySource(options) ? 53 | createRepositoryDownloader(repositoryDetails) : createWebDownloader(repositoryDetails); 54 | } 55 | 56 | private boolean isRepositorySource(PhantomJsResolverOptions options) { 57 | return PhantomJsResolverOptions.Source.REPOSITORY.equals(options.getSource()); 58 | } 59 | 60 | private Downloader createRepositoryDownloader(RepositoryDetails repositoryDetails) { 61 | return new RepositoryDownloader(artifactBuilder, repositoryDetails); 62 | } 63 | 64 | private Downloader createWebDownloader(RepositoryDetails repositoryDetails) { 65 | return new WebDownloader(createArchiveCache(repositoryDetails)); 66 | } 67 | 68 | private ArchiveCache createArchiveCache(RepositoryDetails repositoryDetails) { 69 | return archiveCacheFactory.create(repositoryDetails.getRepositorySystemSession()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/download/RepositoryDownloader.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.download; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import com.github.klieber.phantomjs.resolve.RepositoryDetails; 30 | import com.github.klieber.phantomjs.util.ArtifactBuilder; 31 | import org.eclipse.aether.resolution.ArtifactRequest; 32 | import org.eclipse.aether.resolution.ArtifactResolutionException; 33 | import org.eclipse.aether.resolution.ArtifactResult; 34 | import org.slf4j.Logger; 35 | import org.slf4j.LoggerFactory; 36 | 37 | import java.io.File; 38 | 39 | public class RepositoryDownloader implements Downloader { 40 | 41 | private static final Logger LOGGER = LoggerFactory.getLogger(RepositoryDownloader.class); 42 | 43 | private final static String UNABLE_TO_RESOLVE = "Unable to resolve artifact."; 44 | 45 | private final static String RESOLVED_ARTIFACT = "Resolved artifact {} from {}"; 46 | 47 | private final ArtifactBuilder artifactBuilder; 48 | private final RepositoryDetails repositoryDetails; 49 | 50 | public RepositoryDownloader(ArtifactBuilder artifactBuilder, 51 | RepositoryDetails repositoryDetails) { 52 | this.artifactBuilder = artifactBuilder; 53 | this.repositoryDetails = repositoryDetails; 54 | } 55 | 56 | @Override 57 | public File download(Archive archive) throws DownloadException { 58 | ArtifactResult result = resolveArtifact(createRequest(archive)); 59 | File artifact = result.getArtifact().getFile(); 60 | LOGGER.info(RESOLVED_ARTIFACT, artifact, result.getRepository()); 61 | return artifact; 62 | } 63 | 64 | private ArtifactRequest createRequest(Archive archive) { 65 | ArtifactRequest request = new ArtifactRequest(); 66 | request.setArtifact(artifactBuilder.createArtifact(archive)); 67 | request.setRepositories(repositoryDetails.getRemoteRepositories()); 68 | return request; 69 | } 70 | 71 | private ArtifactResult resolveArtifact(ArtifactRequest artifactRequest) throws DownloadException { 72 | try { 73 | return repositoryDetails.getRepositorySystem().resolveArtifact( 74 | repositoryDetails.getRepositorySystemSession(), 75 | artifactRequest 76 | ); 77 | } catch (ArtifactResolutionException e) { 78 | throw new DownloadException(UNABLE_TO_RESOLVE, e); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/download/WebDownloader.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.download; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import com.github.klieber.phantomjs.cache.ArchiveCache; 30 | import com.google.common.annotations.VisibleForTesting; 31 | import org.codehaus.plexus.util.FileUtils; 32 | import org.slf4j.Logger; 33 | import org.slf4j.LoggerFactory; 34 | 35 | import java.io.File; 36 | import java.io.IOException; 37 | import java.net.URL; 38 | 39 | public class WebDownloader implements Downloader { 40 | 41 | private static final Logger LOGGER = LoggerFactory.getLogger(WebDownloader.class); 42 | 43 | private static final String DOWNLOADING = "Downloading archive from {}"; 44 | private static final String UNABLE_TO_DOWNLOAD = "Unable to download archive from "; 45 | 46 | private final ArchiveCache archiveCache; 47 | 48 | public WebDownloader(ArchiveCache archiveCache) { 49 | this.archiveCache = archiveCache; 50 | } 51 | 52 | @Override 53 | public File download(Archive archive) throws DownloadException { 54 | File target = archiveCache.getFile(archive); 55 | if (!target.exists()) { 56 | String url = archive.getUrl(); 57 | try { 58 | URL downloadLocation = new URL(url); 59 | 60 | LOGGER.info(DOWNLOADING, url); 61 | copyURLToFile(downloadLocation, target); 62 | 63 | if (target.length() <= 0) { 64 | throw new DownloadException(UNABLE_TO_DOWNLOAD+url); 65 | } 66 | } catch (IOException e) { 67 | throw new DownloadException(UNABLE_TO_DOWNLOAD+url, e); 68 | } 69 | } 70 | return target; 71 | } 72 | 73 | @VisibleForTesting 74 | void copyURLToFile(URL url, File file) throws IOException { 75 | FileUtils.copyURLToFile(url, file); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/exec/ExecutionException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.exec; 27 | 28 | import com.github.klieber.phantomjs.PhantomJsException; 29 | 30 | public class ExecutionException extends PhantomJsException { 31 | 32 | public ExecutionException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/exec/PhantomJsExecutor.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.exec; 27 | 28 | import javax.inject.Named; 29 | import java.io.InputStream; 30 | import java.io.PrintStream; 31 | import java.util.Scanner; 32 | 33 | @Named 34 | public class PhantomJsExecutor { 35 | 36 | private static final String UNABLE_TO_EXECUTE = "Unable to execute phantomjs process"; 37 | 38 | public int execute(PhantomJsProcessBuilder runner) throws ExecutionException { 39 | try { 40 | Process process = runner.start(); 41 | inheritIO(process.getInputStream(), System.out); 42 | inheritIO(process.getErrorStream(), System.err); 43 | return process.waitFor(); 44 | } catch (InterruptedException e) { 45 | throw new ExecutionException(UNABLE_TO_EXECUTE, e); 46 | } 47 | } 48 | 49 | 50 | private static void inheritIO(final InputStream src, final PrintStream dest) { 51 | new Thread( 52 | new Runnable() { 53 | public void run() { 54 | Scanner sc = new Scanner(src); 55 | while (sc.hasNextLine()) { 56 | dest.println(sc.nextLine()); 57 | } 58 | } 59 | } 60 | ).start(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/extract/ArchiveExtractor.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.extract; 27 | 28 | import de.schlichtherle.truezip.file.TFile; 29 | import de.schlichtherle.truezip.file.TVFS; 30 | import de.schlichtherle.truezip.fs.FsSyncException; 31 | import org.slf4j.Logger; 32 | import org.slf4j.LoggerFactory; 33 | 34 | import javax.inject.Named; 35 | import java.io.File; 36 | import java.io.IOException; 37 | 38 | @Named 39 | public class ArchiveExtractor { 40 | 41 | private static final Logger LOGGER = LoggerFactory.getLogger(ArchiveExtractor.class); 42 | 43 | private static final String UNABLE_TO_EXTRACT = "Unable to extract member from %s"; 44 | private static final String UNABLE_TO_UNMOUNT = "Unable to unmount file system after extracting"; 45 | private static final String EXTRACTING = "Extracting {} to {}"; 46 | 47 | public void extract(File archive, String member, File extractTo) throws ExtractionException { 48 | try { 49 | TFile tfile = new TFile(archive, member); 50 | LOGGER.info(EXTRACTING, tfile.getAbsolutePath(), extractTo.getAbsolutePath()); 51 | if (extractTo.getParentFile().exists() || extractTo.getParentFile().mkdirs()) { 52 | tfile.cp(extractTo); 53 | } 54 | } catch (IOException e) { 55 | throw new ExtractionException(String.format(UNABLE_TO_EXTRACT, archive), e); 56 | } finally { 57 | unmountArchive(); 58 | } 59 | } 60 | 61 | private void unmountArchive() { 62 | try { 63 | TVFS.umount(); 64 | } 65 | catch (FsSyncException e) { 66 | LOGGER.error(UNABLE_TO_UNMOUNT, e); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/extract/ExtractionException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.extract; 27 | 28 | import com.github.klieber.phantomjs.PhantomJsException; 29 | 30 | public class ExtractionException extends PhantomJsException { 31 | 32 | public ExtractionException(String message, Throwable cause) { 33 | super(message,cause); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/install/InstallationException.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.install; 27 | 28 | import com.github.klieber.phantomjs.PhantomJsException; 29 | 30 | public class InstallationException extends PhantomJsException { 31 | 32 | public InstallationException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/install/Installer.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.install; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | 30 | public interface Installer { 31 | String install(Archive archive) throws InstallationException; 32 | } 33 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/install/InstallerFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.install; 27 | 28 | import com.github.klieber.phantomjs.download.Downloader; 29 | import com.github.klieber.phantomjs.download.DownloaderFactory; 30 | import com.github.klieber.phantomjs.extract.ArchiveExtractor; 31 | import com.github.klieber.phantomjs.resolve.PhantomJsResolverOptions; 32 | import com.github.klieber.phantomjs.resolve.RepositoryDetails; 33 | 34 | import javax.inject.Inject; 35 | import javax.inject.Named; 36 | 37 | @Named 38 | public class InstallerFactory { 39 | 40 | private final ArchiveExtractor archiveExtractor; 41 | private final DownloaderFactory downloaderFactory; 42 | 43 | @Inject 44 | public InstallerFactory(ArchiveExtractor archiveExtractor, 45 | DownloaderFactory downloaderFactory) { 46 | this.archiveExtractor = archiveExtractor; 47 | this.downloaderFactory = downloaderFactory; 48 | } 49 | 50 | public Installer create(PhantomJsResolverOptions options, 51 | RepositoryDetails repositoryDetails) { 52 | Downloader downloader = downloaderFactory.create(options, repositoryDetails); 53 | return new PhantomJsInstaller(downloader, archiveExtractor, options.getOutputDirectory()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/install/PhantomJsInstaller.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.install; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import com.github.klieber.phantomjs.download.DownloadException; 30 | import com.github.klieber.phantomjs.download.Downloader; 31 | import com.github.klieber.phantomjs.extract.ExtractionException; 32 | import com.github.klieber.phantomjs.extract.ArchiveExtractor; 33 | 34 | import java.io.File; 35 | 36 | public class PhantomJsInstaller implements Installer { 37 | 38 | private static final String UNABLE_TO_INSTALL = "Unable to install phantomjs."; 39 | 40 | private final Downloader downloader; 41 | private final ArchiveExtractor extractor; 42 | private final File outputDirectory; 43 | 44 | public PhantomJsInstaller(Downloader downloader, ArchiveExtractor extractor, File outputDirectory) { 45 | this.downloader = downloader; 46 | this.extractor = extractor; 47 | this.outputDirectory = outputDirectory; 48 | } 49 | 50 | @Override 51 | public String install(Archive archive) throws InstallationException { 52 | String executable = archive.getPathToExecutable(); 53 | 54 | File extractTo = new File(outputDirectory, executable); 55 | 56 | if (!extractTo.exists()) { 57 | downloadAndExtract(archive, executable, extractTo); 58 | } 59 | return extractTo.getAbsolutePath(); 60 | } 61 | 62 | private void downloadAndExtract(Archive executableArchive, 63 | String executable, 64 | File extractTo) throws InstallationException { 65 | try { 66 | File archive = downloader.download(executableArchive); 67 | extractor.extract(archive, executable, extractTo); 68 | extractTo.setExecutable(true); 69 | } catch(DownloadException | ExtractionException e) { 70 | throw new InstallationException(UNABLE_TO_INSTALL, e); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/resolve/ArchiveResolver.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import com.github.klieber.phantomjs.install.InstallationException; 30 | import com.github.klieber.phantomjs.install.Installer; 31 | import org.slf4j.Logger; 32 | import org.slf4j.LoggerFactory; 33 | 34 | public class ArchiveResolver implements Resolver { 35 | 36 | private static final Logger LOGGER = LoggerFactory.getLogger(ArchiveResolver.class); 37 | 38 | private final Installer installer; 39 | private final Archive archive; 40 | 41 | public ArchiveResolver(Installer installer, Archive archive) { 42 | this.installer = installer; 43 | this.archive = archive; 44 | } 45 | 46 | @Override 47 | public String resolve() { 48 | String location = null; 49 | try { 50 | location = installer.install(archive); 51 | } catch(InstallationException e) { 52 | LOGGER.error("Unable to resolve phantomjs binary",e); 53 | } 54 | return location; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/resolve/CompositeResolver.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | public class CompositeResolver implements Resolver { 32 | 33 | private final List resolvers; 34 | 35 | public CompositeResolver(List resolvers) { 36 | this.resolvers = new ArrayList(resolvers); 37 | } 38 | 39 | @Override 40 | public String resolve() { 41 | String result = null; 42 | 43 | for (Resolver resolver : resolvers) { 44 | result = resolver.resolve(); 45 | if (result != null) { 46 | break; 47 | } 48 | } 49 | 50 | return result; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/resolve/PhantomJsResolver.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import org.eclipse.aether.RepositorySystem; 29 | import org.eclipse.aether.RepositorySystemSession; 30 | import org.eclipse.aether.repository.RemoteRepository; 31 | 32 | import javax.inject.Inject; 33 | import javax.inject.Named; 34 | import java.util.ArrayList; 35 | import java.util.List; 36 | 37 | @Named 38 | public class PhantomJsResolver { 39 | 40 | private final ResolverFactory resolverFactory; 41 | 42 | @Inject 43 | public PhantomJsResolver(ResolverFactory resolverFactory) { 44 | this.resolverFactory = resolverFactory; 45 | } 46 | 47 | public Builder options(PhantomJsResolverOptions options) { 48 | return new Builder(resolverFactory, options); 49 | } 50 | 51 | public static class Builder { 52 | 53 | private final ResolverFactory resolverFactory; 54 | private final PhantomJsResolverOptions options; 55 | private final List remoteRepositories; 56 | 57 | private RepositorySystem repositorySystem; 58 | private RepositorySystemSession repositorySystemSession; 59 | 60 | private Builder(ResolverFactory resolverFactory, 61 | PhantomJsResolverOptions options) { 62 | this.resolverFactory = resolverFactory; 63 | this.options = options; 64 | this.remoteRepositories = new ArrayList<>(); 65 | } 66 | 67 | public Builder repositorySystem(RepositorySystem repositorySystem) { 68 | this.repositorySystem = repositorySystem; 69 | return this; 70 | } 71 | 72 | public Builder repositorySystemSession(RepositorySystemSession repositorySystemSession) { 73 | this.repositorySystemSession = repositorySystemSession; 74 | return this; 75 | } 76 | 77 | public Builder remoteRepositories(List remoteRepositories) { 78 | this.remoteRepositories.addAll(remoteRepositories); 79 | return this; 80 | } 81 | 82 | public String resolve() { 83 | return resolverFactory.create(options, createRepositoryDetails()).resolve(); 84 | } 85 | 86 | private RepositoryDetails createRepositoryDetails() { 87 | return new RepositoryDetails( 88 | this.repositorySystem, 89 | this.repositorySystemSession, 90 | this.remoteRepositories 91 | ); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/resolve/PhantomJsResolverOptions.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import java.io.File; 29 | 30 | public interface PhantomJsResolverOptions { 31 | 32 | enum Source { 33 | URL, 34 | REPOSITORY 35 | } 36 | 37 | Source getSource(); 38 | String getVersion(); 39 | boolean isCheckSystemPath(); 40 | String getEnforceVersion(); 41 | String getBaseUrl(); 42 | File getOutputDirectory(); 43 | } 44 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/resolve/RepositoryDetails.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import org.eclipse.aether.RepositorySystem; 29 | import org.eclipse.aether.RepositorySystemSession; 30 | import org.eclipse.aether.repository.RemoteRepository; 31 | 32 | import java.util.List; 33 | 34 | public class RepositoryDetails { 35 | 36 | private final RepositorySystem repositorySystem; 37 | private final RepositorySystemSession repositorySystemSession; 38 | private final List remoteRepositories; 39 | 40 | public RepositoryDetails(RepositorySystem repositorySystem, 41 | RepositorySystemSession repositorySystemSession, 42 | List remoteRepositories) { 43 | this.repositorySystem = repositorySystem; 44 | this.repositorySystemSession = repositorySystemSession; 45 | this.remoteRepositories = remoteRepositories; 46 | } 47 | 48 | public RepositorySystem getRepositorySystem() { 49 | return repositorySystem; 50 | } 51 | 52 | public RepositorySystemSession getRepositorySystemSession() { 53 | return repositorySystemSession; 54 | } 55 | 56 | public List getRemoteRepositories() { 57 | return remoteRepositories; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/resolve/Resolver.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | public interface Resolver { 29 | String resolve(); 30 | } 31 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/resolve/ResolverFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import com.github.klieber.phantomjs.archive.ArchiveFactory; 30 | import com.github.klieber.phantomjs.install.Installer; 31 | import com.github.klieber.phantomjs.install.InstallerFactory; 32 | import com.github.klieber.phantomjs.sys.SystemProperties; 33 | import com.github.klieber.phantomjs.util.VersionUtil; 34 | 35 | import javax.inject.Inject; 36 | import javax.inject.Named; 37 | import java.util.ArrayList; 38 | import java.util.List; 39 | 40 | @Named 41 | public class ResolverFactory { 42 | 43 | private final InstallerFactory installerFactory; 44 | private final ArchiveFactory archiveFactory; 45 | private final SystemProperties systemProperties; 46 | 47 | @Inject 48 | public ResolverFactory(InstallerFactory installerFactory, 49 | ArchiveFactory archiveFactory, 50 | SystemProperties systemProperties) { 51 | this.installerFactory = installerFactory; 52 | this.archiveFactory = archiveFactory; 53 | this.systemProperties = systemProperties; 54 | } 55 | 56 | public Resolver create(PhantomJsResolverOptions options, 57 | RepositoryDetails repositoryDetails) { 58 | List resolvers = new ArrayList(); 59 | if (options.isCheckSystemPath()) { 60 | resolvers.add(this.createPathResolver(options)); 61 | } 62 | if (repositoryDetails != null) { 63 | resolvers.add(this.createArchiveResolver(options, repositoryDetails)); 64 | } 65 | return new CompositeResolver(resolvers); 66 | } 67 | 68 | private Resolver createPathResolver(PhantomJsResolverOptions options) { 69 | return createPathResolver(getVersionSpec(options)); 70 | } 71 | 72 | private Resolver createArchiveResolver(PhantomJsResolverOptions options, 73 | RepositoryDetails repositoryDetails) { 74 | Archive archive = archiveFactory.create(options); 75 | Installer installer = installerFactory.create(options, repositoryDetails); 76 | return new ArchiveResolver(installer, archive); 77 | } 78 | 79 | private Resolver createPathResolver(String versionSpec) { 80 | return new PathResolver(systemProperties, versionSpec); 81 | } 82 | 83 | private String getVersionSpec(PhantomJsResolverOptions options) { 84 | return VersionUtil.getVersionSpec(options.getVersion(), options.getEnforceVersion()); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/sys/LinuxProperties.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.sys; 27 | 28 | import org.slf4j.Logger; 29 | import org.slf4j.LoggerFactory; 30 | 31 | import javax.inject.Named; 32 | import java.io.File; 33 | import java.io.FileInputStream; 34 | import java.io.IOException; 35 | import java.util.Properties; 36 | 37 | @Named 38 | public class LinuxProperties { 39 | 40 | private static final Logger LOGGER = LoggerFactory.getLogger(LinuxProperties.class); 41 | 42 | private static final String OS_RELEASE_PROPERTIES_FILE = "/etc/os-release"; 43 | private static final String DISTRIBUTION_NAME = "ID"; 44 | private static final String DISTRIBUTION_VERSION_ID = "VERSION_ID"; 45 | 46 | private final File file; 47 | 48 | private Properties linuxProperties; 49 | 50 | public LinuxProperties() { 51 | this(new File(OS_RELEASE_PROPERTIES_FILE)); 52 | } 53 | 54 | LinuxProperties(File file) { 55 | this.file = file; 56 | this.linuxProperties = null; 57 | } 58 | 59 | public String getDistribution() { 60 | return getProperty(DISTRIBUTION_NAME); 61 | } 62 | 63 | public String getDistributionVersion() { 64 | return getProperty(DISTRIBUTION_VERSION_ID); 65 | } 66 | 67 | private String getProperty(String name) { 68 | String property = getLinuxProperties().getProperty(name); 69 | return property != null ? property.replaceAll("^\"(.*)\"$", "$1").toLowerCase() : null; 70 | } 71 | 72 | private Properties getLinuxProperties() { 73 | if (linuxProperties == null) { 74 | linuxProperties = readProperties(); 75 | } 76 | return linuxProperties; 77 | } 78 | 79 | private Properties readProperties() { 80 | Properties properties = new Properties(); 81 | try { 82 | if (this.file.exists() && this.file.canRead()) { 83 | FileInputStream in = new FileInputStream(this.file); 84 | properties.load(in); 85 | in.close(); 86 | } 87 | } catch (IOException e) { 88 | LOGGER.trace("unable to read linux os linuxProperties", e); 89 | } 90 | return properties; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/sys/SystemProperties.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.sys; 27 | 28 | import javax.inject.Named; 29 | import java.io.File; 30 | import java.util.Arrays; 31 | import java.util.Collections; 32 | import java.util.List; 33 | 34 | @Named 35 | public class SystemProperties { 36 | 37 | private static final String OS_NAME = "os.name"; 38 | private static final String OS_VERSION = "os.version"; 39 | private static final String OS_ARCH = "os.arch"; 40 | private static final String ENV_PATH = "PATH"; 41 | 42 | public String getOsName() { 43 | return getSystemProperty(OS_NAME); 44 | } 45 | 46 | public String getOsVersion() { 47 | return getSystemProperty(OS_VERSION); 48 | } 49 | 50 | public String getOsArch() { 51 | return getSystemProperty(OS_ARCH); 52 | } 53 | 54 | public List getPath() { 55 | String systemPath = System.getenv(ENV_PATH); 56 | return systemPath != null ? Arrays.asList(systemPath.split(File.pathSeparator)) : Collections.emptyList(); 57 | } 58 | 59 | private String getSystemProperty(String name) { 60 | String property = System.getProperty(name); 61 | return property != null ? property.toLowerCase() : null; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/sys/os/OperatingSystem.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.sys.os; 27 | 28 | public class OperatingSystem { 29 | 30 | private final String name; 31 | private final String architecture; 32 | private final String version; 33 | private final String distribution; 34 | private final String distributionVersion; 35 | 36 | public OperatingSystem(String name, 37 | String architecture, 38 | String version) { 39 | this(name, architecture, version, null, null); 40 | } 41 | 42 | public OperatingSystem(String name, 43 | String architecture, 44 | String version, 45 | String distribution, 46 | String distributionVersion) { 47 | this.name = name; 48 | this.architecture = architecture; 49 | this.version = version; 50 | this.distribution = distribution; 51 | this.distributionVersion = distributionVersion; 52 | } 53 | 54 | public String getName() { 55 | return this.name; 56 | } 57 | 58 | public String getArchitecture() { 59 | return this.architecture; 60 | } 61 | 62 | public String getVersion() { 63 | return this.version; 64 | } 65 | 66 | public String getDistribution() { 67 | return this.distribution; 68 | } 69 | 70 | public String getDistributionVersion() { 71 | return this.distributionVersion; 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return "OperatingSystem{" + 77 | "name='" + name + '\'' + 78 | ", architecture='" + architecture + '\'' + 79 | ", version='" + version + '\'' + 80 | ", distribution='" + distribution + '\'' + 81 | ", distributionVersion='" + distributionVersion + '\'' + 82 | '}'; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/sys/os/OperatingSystemFactory.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.sys.os; 27 | 28 | import com.github.klieber.phantomjs.sys.LinuxProperties; 29 | import com.github.klieber.phantomjs.sys.SystemProperties; 30 | 31 | import javax.inject.Inject; 32 | import javax.inject.Named; 33 | 34 | @Named 35 | public class OperatingSystemFactory { 36 | 37 | private SystemProperties systemProperties; 38 | private LinuxProperties linuxProperties; 39 | 40 | @Inject 41 | public OperatingSystemFactory(SystemProperties systemProperties, 42 | LinuxProperties linuxProperties) { 43 | this.systemProperties = systemProperties; 44 | this.linuxProperties = linuxProperties; 45 | } 46 | 47 | public OperatingSystem create() { 48 | String name = systemProperties.getOsName(); 49 | String architecture = getArchitecture(); 50 | String version = systemProperties.getOsVersion(); 51 | 52 | return isLinux(name) ? createLinuxOS(name, architecture, version) : createOS(name, architecture, version); 53 | } 54 | 55 | private String getArchitecture() { 56 | String arch = systemProperties.getOsArch(); 57 | String architecture = null; 58 | if (arch != null) { 59 | architecture = arch.contains("64") ? "x86_64" : "i686"; 60 | } 61 | return architecture; 62 | } 63 | 64 | private boolean isLinux(String name) { 65 | return name.contains("nux"); 66 | } 67 | 68 | private OperatingSystem createOS(String name, 69 | String architecture, 70 | String version) { 71 | return new OperatingSystem( 72 | name, 73 | architecture, 74 | version 75 | ); 76 | } 77 | 78 | private OperatingSystem createLinuxOS(String name, 79 | String architecture, 80 | String version) { 81 | String distribution = linuxProperties.getDistribution(); 82 | String distributionVersion = linuxProperties.getDistributionVersion(); 83 | 84 | return new OperatingSystem( 85 | name, 86 | architecture, 87 | version, 88 | distribution, 89 | distributionVersion 90 | ); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/util/ArtifactBuilder.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.util; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import org.eclipse.aether.artifact.Artifact; 30 | import org.eclipse.aether.artifact.DefaultArtifact; 31 | 32 | import javax.inject.Named; 33 | 34 | @Named 35 | public class ArtifactBuilder { 36 | 37 | public static final String GROUP_ID = "com.github.klieber"; 38 | public static final String ARTIFACT_ID = "phantomjs"; 39 | 40 | public Artifact createArtifact(String groupId, String artifactId, Archive archive) { 41 | return new DefaultArtifact( 42 | groupId, 43 | artifactId, 44 | archive.getClassifier(), 45 | archive.getExtension(), 46 | archive.getVersion() 47 | ); 48 | } 49 | 50 | public Artifact createArtifact(Archive archive) { 51 | return createArtifact(GROUP_ID, ARTIFACT_ID, archive); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/util/VersionUtil.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.util; 27 | 28 | import org.apache.maven.artifact.versioning.ArtifactVersion; 29 | import org.apache.maven.artifact.versioning.DefaultArtifactVersion; 30 | import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; 31 | import org.apache.maven.artifact.versioning.VersionRange; 32 | import org.slf4j.Logger; 33 | import org.slf4j.LoggerFactory; 34 | 35 | public final class VersionUtil { 36 | 37 | private static final Logger LOGGER = LoggerFactory.getLogger(VersionUtil.class); 38 | 39 | private static final String VERSION_NOT_IN_RANGE = "Version {} is not within requested range: {}"; 40 | private static final String INVALID_VERSION_SPECIFICATION = "Invalid version specification: {}"; 41 | private static final String MATCH_ALL = "[0,]"; 42 | 43 | private VersionUtil() { 44 | 45 | } 46 | 47 | public static String getVersionSpec(String version, String enforceVersion) { 48 | String spec = enforceVersion; 49 | if (enforceVersion == null || Boolean.parseBoolean(enforceVersion)) { 50 | spec = '[' + version + ']'; 51 | } else if (Boolean.FALSE.toString().equalsIgnoreCase(enforceVersion)) { 52 | spec = MATCH_ALL; 53 | } else if (!VersionUtil.isWithin(version, enforceVersion)) { 54 | LOGGER.warn(VERSION_NOT_IN_RANGE, version, enforceVersion); 55 | } 56 | return spec; 57 | } 58 | 59 | public static boolean isWithin(String version, String versionSpec) { 60 | boolean within = false; 61 | try { 62 | within = VersionUtil.isWithin(version, VersionRange.createFromVersionSpec(versionSpec)); 63 | } catch (InvalidVersionSpecificationException e) { 64 | LOGGER.warn(INVALID_VERSION_SPECIFICATION, versionSpec); 65 | } 66 | return within; 67 | } 68 | 69 | private static boolean isWithin(String version, VersionRange versionRange) { 70 | ArtifactVersion artifactVersion = new DefaultArtifactVersion(version); 71 | boolean within = false; 72 | if (versionRange != null) { 73 | ArtifactVersion recommendedVersion = versionRange.getRecommendedVersion(); 74 | // treat recommended version as minimum version 75 | within = recommendedVersion != null ? 76 | VersionUtil.isLessThanOrEqualTo(recommendedVersion, artifactVersion) : 77 | versionRange.containsVersion(artifactVersion); 78 | } 79 | return within; 80 | } 81 | 82 | private static boolean isLessThanOrEqualTo(ArtifactVersion versionA, ArtifactVersion versionB) { 83 | return !VersionUtil.isGreaterThan(versionA, versionB); 84 | } 85 | 86 | private static boolean isGreaterThan(ArtifactVersion versionA, ArtifactVersion versionB) { 87 | return compare(versionA, versionB) > 0; 88 | } 89 | 90 | private static int compare(ArtifactVersion versionA, ArtifactVersion versionB) { 91 | if (versionA == versionB) { 92 | return 0; 93 | } 94 | if (versionA == null) { 95 | return -1; 96 | } 97 | if (versionB == null) { 98 | return 1; 99 | } 100 | return versionA.compareTo(versionB); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/config/test-archive.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klieber/phantomjs-maven-plugin/7ec6526a23289bf883048b54985c2c08942ad0a3/phantomjs-maven-core/src/test/config/test-archive.tar.gz -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/archive/AbstractArchiveTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive; 27 | 28 | import org.junit.Test; 29 | 30 | import static org.assertj.core.api.Assertions.assertThat; 31 | 32 | public class AbstractArchiveTest { 33 | 34 | private static final String BASE_URL = "http://example.org/files"; 35 | private static final String ARCHIVE_NAME = "phantomjs-2.0.zip"; 36 | 37 | private static final String FULL_URL = BASE_URL + '/' + ARCHIVE_NAME; 38 | 39 | @Test 40 | public void getUrlWithNoSlashAtEndOfBaseUrl() { 41 | AbstractArchive archive = new MockArchive(BASE_URL, ARCHIVE_NAME); 42 | assertThat(archive.getUrl()).isEqualTo(FULL_URL); 43 | } 44 | 45 | @Test 46 | public void getUrlWithSlashAtEndOfBaseUrl() { 47 | AbstractArchive archive = new MockArchive(BASE_URL+'/', ARCHIVE_NAME); 48 | assertThat(archive.getUrl()).isEqualTo(FULL_URL); 49 | } 50 | 51 | static class MockArchive extends AbstractArchive { 52 | 53 | private final String baseUrl; 54 | private final String archiveName; 55 | 56 | public MockArchive(String baseUrl, String archiveName) { 57 | 58 | this.baseUrl = baseUrl; 59 | this.archiveName = archiveName; 60 | } 61 | 62 | @Override 63 | protected String getBaseUrl() { 64 | return baseUrl; 65 | } 66 | 67 | @Override 68 | public String getExtension() { 69 | return null; 70 | } 71 | 72 | @Override 73 | public String getArchiveName() { 74 | return archiveName; 75 | } 76 | 77 | @Override 78 | public String getPathToExecutable() { 79 | return null; 80 | } 81 | 82 | @Override 83 | public String getVersion() { 84 | return null; 85 | } 86 | 87 | @Override 88 | public String getClassifier() { 89 | return null; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/archive/CustomBaseUrlArchiveTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive; 27 | 28 | import org.junit.Before; 29 | import org.junit.Test; 30 | import org.junit.runner.RunWith; 31 | import org.mockito.Mock; 32 | import org.mockito.junit.MockitoJUnitRunner; 33 | 34 | import static org.assertj.core.api.Assertions.assertThat; 35 | import static org.mockito.Mockito.never; 36 | import static org.mockito.Mockito.verify; 37 | import static org.mockito.Mockito.when; 38 | 39 | @RunWith(MockitoJUnitRunner.class) 40 | public class CustomBaseUrlArchiveTest { 41 | 42 | private static final String BASE_URL = "http://example.org/files"; 43 | private static final String ARCHIVE_NAME = "archive-name"; 44 | private static final String CLASSIFIER = "classifier"; 45 | private static final String EXTENSION = "ext"; 46 | private static final String PATH_TO_EXECUTABLE = "bin/phantomjs"; 47 | private static final String VERSION = "2.0.0"; 48 | 49 | @Mock 50 | private Archive delegate; 51 | 52 | private CustomBaseUrlArchive archive; 53 | 54 | @Before 55 | public void before() { 56 | archive = new CustomBaseUrlArchive(delegate, BASE_URL); 57 | } 58 | 59 | @Test 60 | public void testGetArchiveName() { 61 | when(delegate.getArchiveName()).thenReturn(ARCHIVE_NAME); 62 | assertThat(archive.getArchiveName()).isEqualTo(ARCHIVE_NAME); 63 | } 64 | 65 | @Test 66 | public void testGetClassifier() { 67 | when(delegate.getClassifier()).thenReturn(CLASSIFIER); 68 | assertThat(archive.getClassifier()).isEqualTo(CLASSIFIER); 69 | } 70 | 71 | @Test 72 | public void testGetExtension() { 73 | when(delegate.getExtension()).thenReturn(EXTENSION); 74 | assertThat(archive.getExtension()).isEqualTo(EXTENSION); 75 | } 76 | 77 | @Test 78 | public void testGetPathToExecutable() { 79 | when(delegate.getPathToExecutable()).thenReturn(PATH_TO_EXECUTABLE); 80 | assertThat(archive.getPathToExecutable()).isEqualTo(PATH_TO_EXECUTABLE); 81 | } 82 | 83 | @Test 84 | public void testGetVersion() { 85 | when(delegate.getVersion()).thenReturn(VERSION); 86 | assertThat(archive.getVersion()).isEqualTo(VERSION); 87 | } 88 | 89 | @Test 90 | public void testGetBaseUrl() { 91 | assertThat(archive.getBaseUrl()).isEqualTo(BASE_URL); 92 | } 93 | 94 | @Test 95 | public void testGetUrl() { 96 | when(delegate.getArchiveName()).thenReturn(ARCHIVE_NAME); 97 | assertThat(archive.getUrl()).isEqualTo(BASE_URL+'/'+ARCHIVE_NAME); 98 | verify(delegate, never()).getUrl(); 99 | 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/archive/mapping/ArchiveFormatTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive.mapping; 27 | 28 | import org.junit.Before; 29 | import org.junit.Test; 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; 32 | 33 | public class ArchiveFormatTest { 34 | 35 | private static final String BASE_URL_TEMPLATE = "http://example.org/files"; 36 | private static final String FILE_TEMPLATE = "archive-name"; 37 | private static final String EXECUTABLE_TEMPLATE = "archive-{version}/bin/executable"; 38 | private static final String CLASSIFIER = "macos"; 39 | private static final String EXTENSION = "tar.gz"; 40 | 41 | private ArchiveFormat archiveFormat; 42 | 43 | @Before 44 | public void before() { 45 | archiveFormat = new ArchiveFormat( 46 | BASE_URL_TEMPLATE, 47 | FILE_TEMPLATE, 48 | EXECUTABLE_TEMPLATE, 49 | CLASSIFIER, 50 | EXTENSION 51 | ); 52 | } 53 | 54 | @Test 55 | public void getBaseUrlTemplate() { 56 | assertThat(archiveFormat.getBaseUrlTemplate()).isEqualTo(BASE_URL_TEMPLATE); 57 | } 58 | 59 | @Test 60 | public void getFileTemplate() { 61 | assertThat(archiveFormat.getFileTemplate()).isEqualTo(FILE_TEMPLATE); 62 | } 63 | 64 | @Test 65 | public void getExecutableTemplate() { 66 | assertThat(archiveFormat.getExecutableTemplate()).isEqualTo(EXECUTABLE_TEMPLATE); 67 | } 68 | 69 | @Test 70 | public void getClassifier() { 71 | assertThat(archiveFormat.getClassifier()).isEqualTo(CLASSIFIER); 72 | } 73 | 74 | @Test 75 | public void getExtension() { 76 | assertThat(archiveFormat.getExtension()).isEqualTo(EXTENSION); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/archive/mapping/ArchiveSpecTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.archive.mapping; 27 | 28 | import com.github.klieber.phantomjs.sys.os.OperatingSystem; 29 | import org.junit.Before; 30 | import org.junit.Test; 31 | import org.junit.runner.RunWith; 32 | import org.mockito.Mock; 33 | import org.mockito.junit.MockitoJUnitRunner; 34 | 35 | import static org.assertj.core.api.Assertions.assertThat; 36 | import static org.mockito.Mockito.when; 37 | 38 | @RunWith(MockitoJUnitRunner.class) 39 | public class ArchiveSpecTest { 40 | 41 | private static final String VERSION_SPEC = "[2.0,2.5]"; 42 | 43 | @Mock 44 | private OperatingSystemSpec operatingSystemSpec; 45 | 46 | @Mock 47 | private OperatingSystem operatingSystem; 48 | 49 | private ArchiveSpec archiveSpec; 50 | 51 | @Before 52 | public void before() { 53 | archiveSpec = new ArchiveSpec(VERSION_SPEC, operatingSystemSpec); 54 | } 55 | 56 | @Test 57 | public void testGetVersionSpec() { 58 | assertThat(archiveSpec.getVersionSpec()).isEqualTo(VERSION_SPEC); 59 | } 60 | 61 | @Test 62 | public void testGetOperatingSystemSpec() { 63 | assertThat(archiveSpec.getOperatingSystemSpec()).isEqualTo(operatingSystemSpec); 64 | } 65 | 66 | @Test 67 | public void testMatches_OsAndVersionMatches() { 68 | when(operatingSystemSpec.matches(operatingSystem)).thenReturn(true); 69 | assertThat(archiveSpec.matches("2.0", operatingSystem)).isTrue(); 70 | } 71 | 72 | @Test 73 | public void testMatches_OnlyVersionMatches() { 74 | assertThat(archiveSpec.matches("2.0", operatingSystem)).isFalse(); 75 | } 76 | 77 | @Test 78 | public void testMatches_NoMatches() { 79 | assertThat(archiveSpec.matches("1.5", operatingSystem)).isFalse(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/cache/ArchiveCacheTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.cache; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import com.github.klieber.phantomjs.util.ArtifactBuilder; 30 | import org.eclipse.aether.RepositorySystemSession; 31 | import org.eclipse.aether.artifact.Artifact; 32 | import org.eclipse.aether.repository.LocalRepository; 33 | import org.eclipse.aether.repository.LocalRepositoryManager; 34 | import org.junit.Before; 35 | import org.junit.Test; 36 | import org.junit.runner.RunWith; 37 | import org.mockito.Mock; 38 | import org.mockito.junit.MockitoJUnitRunner; 39 | 40 | import java.io.File; 41 | 42 | import static org.assertj.core.api.Assertions.assertThat; 43 | import static org.mockito.Mockito.when; 44 | 45 | @RunWith(MockitoJUnitRunner.class) 46 | public class ArchiveCacheTest { 47 | 48 | private static final String REPOSITORY_PATH = System.getProperty("java.io.tmpdir"); 49 | private static final String ARTIFACT_PATH = "a/b/artifact-1.2.jar"; 50 | 51 | private static final File BASEDIR = new File(REPOSITORY_PATH); 52 | 53 | @Mock 54 | private Archive archive; 55 | 56 | @Mock 57 | private RepositorySystemSession repositorySystemSession; 58 | 59 | @Mock 60 | private LocalRepositoryManager localRepositoryManager; 61 | 62 | @Mock 63 | private ArtifactBuilder artifactBuilder; 64 | 65 | @Mock 66 | private Artifact artifact; 67 | 68 | private ArchiveCache archiveCache; 69 | 70 | @Before 71 | public void before() { 72 | archiveCache = new ArchiveCacheFactory(artifactBuilder).create(repositorySystemSession); 73 | } 74 | 75 | @Test 76 | public void testGetFile() { 77 | when(artifactBuilder.createArtifact(archive)).thenReturn(artifact); 78 | 79 | when(repositorySystemSession.getLocalRepositoryManager()).thenReturn(localRepositoryManager); 80 | when(localRepositoryManager.getRepository()).thenReturn(new LocalRepository(BASEDIR)); 81 | when(localRepositoryManager.getPathForLocalArtifact(artifact)).thenReturn(ARTIFACT_PATH); 82 | 83 | File cachedFile = archiveCache.getFile(archive); 84 | 85 | assertThat(cachedFile.getAbsolutePath()).isEqualTo(new File(REPOSITORY_PATH, ARTIFACT_PATH).getPath()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/download/DownloaderFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.download; 27 | 28 | import com.github.klieber.phantomjs.cache.ArchiveCacheFactory; 29 | import com.github.klieber.phantomjs.resolve.PhantomJsResolverOptions; 30 | import com.github.klieber.phantomjs.resolve.RepositoryDetails; 31 | import com.github.klieber.phantomjs.util.ArtifactBuilder; 32 | import org.junit.Test; 33 | import org.junit.runner.RunWith; 34 | import org.mockito.InjectMocks; 35 | import org.mockito.Mock; 36 | import org.mockito.junit.MockitoJUnitRunner; 37 | 38 | import static org.assertj.core.api.Assertions.assertThat; 39 | import static org.mockito.Mockito.when; 40 | 41 | @RunWith(MockitoJUnitRunner.class) 42 | public class DownloaderFactoryTest { 43 | 44 | @Mock 45 | private ArtifactBuilder artifactBuilder; 46 | 47 | @Mock 48 | private ArchiveCacheFactory archiveCacheFactory; 49 | 50 | @Mock 51 | private PhantomJsResolverOptions options; 52 | 53 | @Mock 54 | private RepositoryDetails repositoryDetails; 55 | 56 | @InjectMocks 57 | private DownloaderFactory downloaderFactory; 58 | 59 | @Test 60 | public void testGetDownloader_RepositoryDownloader() { 61 | when(options.getSource()).thenReturn(PhantomJsResolverOptions.Source.REPOSITORY); 62 | assertThat(downloaderFactory.create(options, repositoryDetails)).isInstanceOf(RepositoryDownloader.class); 63 | } 64 | 65 | @Test 66 | public void testGetDownloader_WebDownloader() { 67 | when(options.getSource()).thenReturn(PhantomJsResolverOptions.Source.URL); 68 | assertThat(downloaderFactory.create(options, repositoryDetails)).isInstanceOf(WebDownloader.class); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/download/WebDownloaderTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.download; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import com.github.klieber.phantomjs.cache.ArchiveCache; 30 | import org.junit.Before; 31 | import org.junit.Test; 32 | import org.junit.runner.RunWith; 33 | import org.mockito.InjectMocks; 34 | import org.mockito.Mock; 35 | import org.mockito.junit.MockitoJUnitRunner; 36 | 37 | import java.io.File; 38 | import java.io.IOException; 39 | import java.net.URL; 40 | 41 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 42 | import static org.mockito.Matchers.any; 43 | import static org.mockito.Matchers.eq; 44 | import static org.mockito.Mockito.doNothing; 45 | import static org.mockito.Mockito.doThrow; 46 | import static org.mockito.Mockito.spy; 47 | import static org.mockito.Mockito.verify; 48 | import static org.mockito.Mockito.when; 49 | 50 | @RunWith(MockitoJUnitRunner.class) 51 | public class WebDownloaderTest { 52 | 53 | private static final String FILE_PATH = "file.zip"; 54 | private static final String DOWNLOAD_URL = "http://example.org/" + FILE_PATH; 55 | 56 | @Mock 57 | private Archive archive; 58 | 59 | @Mock 60 | private ArchiveCache archiveCache; 61 | 62 | @Mock 63 | private File file; 64 | 65 | @InjectMocks 66 | private WebDownloader downloader; 67 | 68 | @Before 69 | public void before() { 70 | when(archiveCache.getFile(archive)).thenReturn(file); 71 | downloader = spy(new WebDownloader(archiveCache)); 72 | } 73 | 74 | @Test 75 | public void shouldDownload() throws Exception { 76 | when(archive.getUrl()).thenReturn(DOWNLOAD_URL); 77 | when(file.length()).thenReturn(100L); 78 | 79 | doNothing().when(downloader).copyURLToFile(any(URL.class), eq(file)); 80 | 81 | downloader.download(archive); 82 | 83 | verify(downloader).copyURLToFile(any(URL.class), eq(file)); 84 | } 85 | 86 | @Test 87 | public void shouldFailDueToEmptyFile() throws Exception { 88 | when(archive.getUrl()).thenReturn(DOWNLOAD_URL); 89 | when(file.length()).thenReturn(0L); 90 | doNothing().when(downloader).copyURLToFile(any(URL.class), eq(file)); 91 | assertThatThrownBy(() -> downloader.download(archive)).isInstanceOf(DownloadException.class); 92 | } 93 | 94 | @Test 95 | public void shouldFailDueToIOException() throws Exception { 96 | when(archive.getUrl()).thenReturn(DOWNLOAD_URL); 97 | doThrow(new IOException()).when(downloader).copyURLToFile(any(URL.class), eq(file)); 98 | assertThatThrownBy(() -> downloader.download(archive)).isInstanceOf(DownloadException.class); 99 | } 100 | 101 | @Test 102 | public void shouldFailDueToMalformedUrl() throws Exception { 103 | when(archive.getUrl()).thenReturn("invalid-base-url"); 104 | assertThatThrownBy(() -> downloader.download(archive)).isInstanceOf(DownloadException.class); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/exec/PhantomJsExecutorTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.exec; 27 | 28 | import org.junit.Test; 29 | import org.junit.runner.RunWith; 30 | import org.mockito.InjectMocks; 31 | import org.mockito.Mock; 32 | import org.mockito.junit.MockitoJUnitRunner; 33 | 34 | import java.io.InputStream; 35 | 36 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 37 | import static org.mockito.Mockito.doThrow; 38 | import static org.mockito.Mockito.verify; 39 | import static org.mockito.Mockito.when; 40 | 41 | @RunWith(MockitoJUnitRunner.class) 42 | public class PhantomJsExecutorTest { 43 | 44 | @Mock 45 | private PhantomJsProcessBuilder builder; 46 | 47 | @Mock 48 | private Process process; 49 | 50 | @Mock 51 | private InputStream inputStream; 52 | 53 | @Mock 54 | private InputStream errorStream; 55 | 56 | @InjectMocks 57 | private PhantomJsExecutor executor; 58 | 59 | @Test 60 | public void testStart() throws Exception { 61 | when(builder.start()).thenReturn(process); 62 | when(process.getInputStream()).thenReturn(inputStream); 63 | when(process.getErrorStream()).thenReturn(errorStream); 64 | 65 | executor.execute(builder); 66 | 67 | verify(process).waitFor(); 68 | } 69 | 70 | @Test 71 | public void testCanHandleInterruption() throws Exception { 72 | when(builder.start()).thenReturn(process); 73 | when(process.getInputStream()).thenReturn(inputStream); 74 | when(process.getErrorStream()).thenReturn(errorStream); 75 | 76 | doThrow(InterruptedException.class).when(process).waitFor(); 77 | 78 | assertThatThrownBy(() -> executor.execute(builder)).isInstanceOf(ExecutionException.class); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/exec/PhantomJsProcessBuilderTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.exec; 27 | 28 | import org.junit.Before; 29 | import org.junit.Test; 30 | import org.junit.runner.RunWith; 31 | import org.mockito.Mock; 32 | import org.mockito.junit.MockitoJUnitRunner; 33 | 34 | import java.io.File; 35 | 36 | import static org.assertj.core.api.Assertions.assertThat; 37 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 38 | import static org.mockito.Mockito.spy; 39 | import static org.mockito.Mockito.when; 40 | 41 | @RunWith(MockitoJUnitRunner.class) 42 | public class PhantomJsProcessBuilderTest { 43 | 44 | private static final String BINARY = "phantomjs"; 45 | 46 | private static final String COMMAND_LINE = "-a -b -c"; 47 | 48 | @Mock 49 | private File file; 50 | 51 | private PhantomJsProcessBuilder builder; 52 | 53 | @Before 54 | public void before() { 55 | builder = spy(new PhantomJsProcessBuilder(BINARY)); 56 | } 57 | 58 | @Test 59 | public void testStart() throws Exception { 60 | assertThat(builder.start()).isNotNull(); 61 | } 62 | 63 | @Test 64 | public void testStartWithConfigFile() throws Exception { 65 | when(file.exists()).thenReturn(true); 66 | assertThat(builder.configFile(file)).isSameAs(builder); 67 | assertThat(builder.start()).isNotNull(); 68 | } 69 | 70 | @Test 71 | public void testStartWithMissingConfigFile() throws Exception { 72 | when(file.exists()).thenReturn(false); 73 | assertThat(builder.configFile(file)).isSameAs(builder); 74 | assertThat(builder.start()).isNotNull(); 75 | } 76 | 77 | @Test 78 | public void testStartCanHandleException() throws Exception { 79 | //noinspection unchecked 80 | when(builder.getCommandLineOptions(COMMAND_LINE)).thenThrow(ExecutionException.class); 81 | 82 | assertThatThrownBy(() -> builder.commandLineOptions(COMMAND_LINE).start()) 83 | .isInstanceOf(ExecutionException.class); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/extract/ArchiveExtractorTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.extract; 27 | 28 | import org.junit.After; 29 | import org.junit.Before; 30 | import org.junit.Test; 31 | import org.junit.runner.RunWith; 32 | import org.mockito.Mock; 33 | import org.mockito.junit.MockitoJUnitRunner; 34 | 35 | import java.io.File; 36 | 37 | import static org.assertj.core.api.Assertions.assertThat; 38 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 39 | import static org.mockito.Mockito.mock; 40 | import static org.mockito.Mockito.never; 41 | import static org.mockito.Mockito.verify; 42 | import static org.mockito.Mockito.when; 43 | 44 | @RunWith(MockitoJUnitRunner.class) 45 | public class ArchiveExtractorTest { 46 | 47 | private static final String PROJECT_ROOT = System.getProperty("user.dir"); 48 | 49 | private static final String PATH_TO_EXECUTABLE = "bin/phantomjs"; 50 | private static final String ARCHIVE_PATH = PROJECT_ROOT + "/src/test/config/test-archive.tar.gz"; 51 | private static final String EXTRACT_TO_PATH = PROJECT_ROOT + "/target/temp/phantomjs"; 52 | 53 | private File archive; 54 | 55 | private File extractTo; 56 | 57 | @Mock 58 | private File extractToParent; 59 | 60 | private ArchiveExtractor extractor; 61 | 62 | @Before 63 | public void before() { 64 | extractor = new ArchiveExtractor(); 65 | archive = new File(ARCHIVE_PATH); 66 | extractTo = new File(EXTRACT_TO_PATH); 67 | } 68 | 69 | @After 70 | public void after() { 71 | if (extractTo != null && extractTo.exists()) { 72 | extractTo.delete(); 73 | } 74 | } 75 | 76 | @Test 77 | public void shouldExtract() throws Exception { 78 | extractor.extract(archive, PATH_TO_EXECUTABLE, extractTo); 79 | assertThat(extractTo.exists()).isTrue(); 80 | } 81 | 82 | @Test 83 | public void shouldNotExtract() throws Exception { 84 | extractTo = mock(File.class); 85 | 86 | when(extractTo.getParentFile()).thenReturn(extractToParent); 87 | when(extractTo.getAbsolutePath()).thenReturn(EXTRACT_TO_PATH); 88 | when(extractToParent.mkdirs()).thenReturn(false); 89 | 90 | extractor.extract(archive, PATH_TO_EXECUTABLE, extractTo); 91 | 92 | verify(extractTo, never()).setExecutable(true); 93 | } 94 | 95 | @Test 96 | public void shouldFailToExtract() throws Exception { 97 | File invalidFile = new File(PROJECT_ROOT + "/target/doesnotexist"); 98 | assertThatThrownBy(() -> extractor.extract(invalidFile, PATH_TO_EXECUTABLE, extractTo)) 99 | .isInstanceOf(ExtractionException.class); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/resolve/ArchiveResolverTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import com.github.klieber.phantomjs.install.InstallationException; 30 | import com.github.klieber.phantomjs.install.Installer; 31 | import org.junit.Before; 32 | import org.junit.Test; 33 | import org.junit.runner.RunWith; 34 | import org.mockito.Mock; 35 | import org.mockito.junit.MockitoJUnitRunner; 36 | 37 | import static org.assertj.core.api.Assertions.assertThat; 38 | import static org.mockito.Mockito.when; 39 | 40 | @RunWith(MockitoJUnitRunner.class) 41 | public class ArchiveResolverTest { 42 | 43 | private static final String LOCATION = "the-location"; 44 | 45 | @Mock 46 | private Archive archive; 47 | 48 | @Mock 49 | private Installer installer; 50 | 51 | private ArchiveResolver locator; 52 | 53 | @Before 54 | public void before() { 55 | locator = new ArchiveResolver(installer, archive); 56 | } 57 | 58 | @Test 59 | public void shouldLocate() throws Exception { 60 | when(installer.install(archive)).thenReturn(LOCATION); 61 | assertThat(locator.resolve()).isEqualTo(LOCATION); 62 | } 63 | 64 | @Test 65 | public void testLocateShouldHandleException() throws Exception { 66 | when(installer.install(archive)).thenThrow(new InstallationException("error", new RuntimeException())); 67 | assertThat(locator.resolve()).isNull(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/resolve/CompositeResolverTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import org.junit.Before; 29 | import org.junit.Test; 30 | import org.junit.runner.RunWith; 31 | import org.mockito.Mock; 32 | import org.mockito.junit.MockitoJUnitRunner; 33 | 34 | import java.util.Arrays; 35 | 36 | import static org.assertj.core.api.Assertions.assertThat; 37 | import static org.mockito.Mockito.verify; 38 | import static org.mockito.Mockito.verifyNoMoreInteractions; 39 | import static org.mockito.Mockito.when; 40 | 41 | @RunWith(MockitoJUnitRunner.class) 42 | public class CompositeResolverTest { 43 | 44 | private static final String LOCATION_A = "/opt/phantomjs/bin/phantomjs"; 45 | private static final String LOCATION_B = "/usr/bin/phantomjs"; 46 | 47 | @Mock 48 | private Resolver resolverA; 49 | 50 | @Mock 51 | private Resolver resolverB; 52 | 53 | private CompositeResolver compositeLocator; 54 | 55 | @Before 56 | public void before() { 57 | compositeLocator = new CompositeResolver(Arrays.asList(resolverA, resolverB)); 58 | } 59 | 60 | @Test 61 | public void shouldLocateLocationA() throws Exception { 62 | when(resolverA.resolve()).thenReturn(LOCATION_A); 63 | assertThat(compositeLocator.resolve()).isEqualTo(LOCATION_A); 64 | verifyNoMoreInteractions(resolverB); 65 | } 66 | 67 | @Test 68 | public void shouldLocateLocationB() throws Exception { 69 | when(resolverB.resolve()).thenReturn(LOCATION_B); 70 | assertThat(compositeLocator.resolve()).isEqualTo(LOCATION_B); 71 | verify(resolverA).resolve(); 72 | } 73 | 74 | @Test 75 | public void shouldNotLocateAnything() throws Exception { 76 | assertThat(compositeLocator.resolve()).isNull(); 77 | verify(resolverA).resolve(); 78 | verify(resolverB).resolve(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/resolve/PathResolverTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import com.github.klieber.phantomjs.sys.SystemProperties; 29 | import com.github.klieber.phantomjs.test.MockPhantomJsBinary; 30 | import org.junit.Before; 31 | import org.junit.ClassRule; 32 | import org.junit.Test; 33 | import org.junit.runner.RunWith; 34 | import org.mockito.Mock; 35 | import org.mockito.junit.MockitoJUnitRunner; 36 | 37 | import java.util.Collections; 38 | 39 | import static org.assertj.core.api.Assertions.assertThat; 40 | import static org.junit.Assume.assumeTrue; 41 | import static org.mockito.Mockito.when; 42 | 43 | @RunWith(MockitoJUnitRunner.class) 44 | public class PathResolverTest { 45 | 46 | private static final String VERSION = "1.9.0"; 47 | 48 | @ClassRule 49 | public static final MockPhantomJsBinary phantomJsBinary = new MockPhantomJsBinary(VERSION); 50 | 51 | @Mock 52 | private SystemProperties systemProperties; 53 | 54 | @Before 55 | public void before() { 56 | assumeUnixOs(); 57 | } 58 | 59 | @Test 60 | public void testShouldNotResolve() { 61 | when(systemProperties.getPath()).thenReturn(Collections.singletonList("/tmp")); 62 | assertThat(getResolver(VERSION).resolve()).isNull(); 63 | } 64 | 65 | @Test 66 | public void testShouldResolveBin() { 67 | when(systemProperties.getPath()).thenReturn(Collections.singletonList(phantomJsBinary.get().getParent())); 68 | assertThat(getResolver(VERSION).resolve()).isEqualTo(phantomJsBinary.get().getAbsolutePath()); 69 | } 70 | 71 | @Test 72 | public void testShouldResolveBinWrongVersion() { 73 | when(systemProperties.getPath()).thenReturn(Collections.singletonList(phantomJsBinary.get().getParent())); 74 | assertThat(getResolver("1.9.2").resolve()).isNull(); 75 | } 76 | 77 | private PathResolver getResolver(String version) { 78 | return new PathResolver(systemProperties, version); 79 | } 80 | 81 | private void assumeUnixOs() { 82 | String os = System.getProperty("os.name").toLowerCase(); 83 | assumeTrue(os.contains("nux") || os.contains("mac")); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/resolve/PhantomJsResolverTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import org.eclipse.aether.RepositorySystem; 29 | import org.eclipse.aether.RepositorySystemSession; 30 | import org.eclipse.aether.repository.RemoteRepository; 31 | import org.junit.Test; 32 | import org.junit.runner.RunWith; 33 | import org.mockito.InjectMocks; 34 | import org.mockito.Mock; 35 | import org.mockito.junit.MockitoJUnitRunner; 36 | 37 | import java.util.ArrayList; 38 | 39 | import static org.assertj.core.api.Assertions.assertThat; 40 | import static org.mockito.ArgumentMatchers.any; 41 | import static org.mockito.ArgumentMatchers.eq; 42 | import static org.mockito.Mockito.when; 43 | 44 | @RunWith(MockitoJUnitRunner.class) 45 | public class PhantomJsResolverTest { 46 | 47 | private static final String MOCK_EXECUTABLE_PATH = "/usr/bin/phantomjs"; 48 | 49 | @Mock 50 | private ResolverFactory resolverFactory; 51 | 52 | @Mock 53 | private Resolver resolver; 54 | 55 | @Mock 56 | private PhantomJsResolverOptions options; 57 | 58 | @Mock 59 | private RepositorySystem repositorySystem; 60 | 61 | @Mock 62 | private RepositorySystemSession repositorySystemSession; 63 | 64 | @InjectMocks 65 | private PhantomJsResolver phantomJsResolver; 66 | 67 | @Test 68 | public void testResolve() { 69 | when(resolverFactory.create(eq(options), any(RepositoryDetails.class))).thenReturn(resolver); 70 | when(resolver.resolve()).thenReturn(MOCK_EXECUTABLE_PATH); 71 | 72 | String executable = phantomJsResolver.options(options) 73 | .repositorySystem(repositorySystem) 74 | .repositorySystemSession(repositorySystemSession) 75 | .remoteRepositories(new ArrayList()) 76 | .resolve(); 77 | 78 | assertThat(executable).isEqualTo(MOCK_EXECUTABLE_PATH); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/resolve/RepositoryDetailsTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import com.github.klieber.phantomjs.resolve.RepositoryDetails; 29 | import org.eclipse.aether.RepositorySystem; 30 | import org.eclipse.aether.RepositorySystemSession; 31 | import org.eclipse.aether.repository.RemoteRepository; 32 | import org.junit.Before; 33 | import org.junit.Test; 34 | import org.junit.runner.RunWith; 35 | import org.mockito.InjectMocks; 36 | import org.mockito.Mock; 37 | import org.mockito.junit.MockitoJUnitRunner; 38 | 39 | import java.util.ArrayList; 40 | import java.util.List; 41 | 42 | import static org.assertj.core.api.Assertions.assertThat; 43 | 44 | @RunWith(MockitoJUnitRunner.class) 45 | public class RepositoryDetailsTest { 46 | 47 | @Mock 48 | private RepositorySystem repositorySystem; 49 | 50 | @Mock 51 | private RepositorySystemSession repositorySystemSession; 52 | 53 | private List remoteRepositories = new ArrayList<>(); 54 | 55 | @InjectMocks 56 | private RepositoryDetails repositoryDetails; 57 | 58 | @Before 59 | public void before() { 60 | repositoryDetails = new RepositoryDetails(repositorySystem, repositorySystemSession, remoteRepositories); 61 | } 62 | 63 | @Test 64 | public void testRepositorySystem() { 65 | assertThat(repositoryDetails.getRepositorySystem()).isSameAs(repositorySystem); 66 | } 67 | 68 | @Test 69 | public void testRepositorySystemSession() { 70 | assertThat(repositoryDetails.getRepositorySystemSession()).isSameAs(repositorySystemSession); 71 | } 72 | 73 | @Test 74 | public void testRemoteRepository() { 75 | assertThat(repositoryDetails.getRemoteRepositories()).isEqualTo(remoteRepositories); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/resolve/ResolverFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.resolve; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import com.github.klieber.phantomjs.archive.ArchiveFactory; 30 | import com.github.klieber.phantomjs.install.Installer; 31 | import com.github.klieber.phantomjs.install.InstallerFactory; 32 | import com.github.klieber.phantomjs.sys.SystemProperties; 33 | import com.github.klieber.phantomjs.test.MockPhantomJsBinary; 34 | import org.junit.ClassRule; 35 | import org.junit.Test; 36 | import org.junit.runner.RunWith; 37 | import org.mockito.InjectMocks; 38 | import org.mockito.Mock; 39 | import org.mockito.junit.MockitoJUnitRunner; 40 | 41 | import java.util.Collections; 42 | 43 | import static org.assertj.core.api.Assertions.assertThat; 44 | import static org.junit.Assume.assumeTrue; 45 | import static org.mockito.Mockito.when; 46 | 47 | @RunWith(MockitoJUnitRunner.class) 48 | public class ResolverFactoryTest { 49 | 50 | private static final String VERSION = "2.0.0"; 51 | 52 | @ClassRule 53 | public static final MockPhantomJsBinary phantomJsBinary = new MockPhantomJsBinary(VERSION); 54 | 55 | @Mock 56 | private InstallerFactory installerFactory; 57 | 58 | @Mock 59 | private Installer installer; 60 | 61 | @Mock 62 | private ArchiveFactory archiveFactory; 63 | 64 | @Mock 65 | private Archive archive; 66 | 67 | @Mock 68 | private SystemProperties systemProperties; 69 | 70 | @Mock 71 | private PhantomJsResolverOptions options; 72 | 73 | @Mock 74 | private RepositoryDetails repositoryDetails; 75 | 76 | @InjectMocks 77 | private ResolverFactory resolverFactory; 78 | 79 | @Test 80 | public void testGetLocator() { 81 | Resolver resolver = resolverFactory.create(options, repositoryDetails); 82 | assertThat(resolver).isInstanceOf(CompositeResolver.class); 83 | } 84 | 85 | @Test 86 | public void testCreate_PathResolver() { 87 | assumeUnixOs(); 88 | 89 | when(systemProperties.getPath()).thenReturn(Collections.singletonList(phantomJsBinary.get().getParent())); 90 | 91 | when(options.isCheckSystemPath()).thenReturn(true); 92 | when(options.getVersion()).thenReturn(VERSION); 93 | when(options.getEnforceVersion()).thenReturn("true"); 94 | Resolver resolver = resolverFactory.create(options, repositoryDetails); 95 | assertThat(resolver).isInstanceOf(CompositeResolver.class); 96 | String path = resolver.resolve(); 97 | } 98 | 99 | @Test 100 | public void testGetArchiveLocator() { 101 | when(options.isCheckSystemPath()).thenReturn(false); 102 | when(archiveFactory.create(options)).thenReturn(archive); 103 | when(installerFactory.create(options, repositoryDetails)).thenReturn(installer); 104 | 105 | Resolver resolver = resolverFactory.create(options, repositoryDetails); 106 | assertThat(resolver).isInstanceOf(CompositeResolver.class); 107 | String path = resolver.resolve(); 108 | } 109 | 110 | private void assumeUnixOs() { 111 | String os = System.getProperty("os.name").toLowerCase(); 112 | assumeTrue(os.contains("nux") || os.contains("mac")); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/sys/LinuxPropertiesTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.sys; 27 | 28 | import org.junit.Test; 29 | 30 | import java.io.File; 31 | import java.net.URL; 32 | 33 | import static org.assertj.core.api.Assertions.assertThat; 34 | 35 | public class LinuxPropertiesTest { 36 | 37 | private LinuxProperties linuxProperties = new LinuxProperties(createMockFile()); 38 | 39 | @Test 40 | public void testGetDistribution() { 41 | assertThat(linuxProperties.getDistribution()).isEqualTo("ubuntu"); 42 | } 43 | 44 | @Test 45 | public void testGetDistributionVersion() { 46 | assertThat(linuxProperties.getDistributionVersion()).isEqualTo("16.04"); 47 | } 48 | 49 | private static File createMockFile() { 50 | URL resource = LinuxPropertiesTest.class.getResource("/test-linux.properties"); 51 | return new File(resource.getFile()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/sys/SystemPropertiesTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.sys; 27 | 28 | import org.junit.Test; 29 | 30 | import static org.assertj.core.api.Assertions.assertThat; 31 | 32 | public class SystemPropertiesTest { 33 | 34 | private SystemProperties systemProperties = new SystemProperties(); 35 | 36 | @Test 37 | public void getOsName() { 38 | String original = System.getProperty("os.name"); 39 | System.setProperty("os.name", "MacOs"); 40 | assertThat(systemProperties.getOsName()).isEqualTo("macos"); 41 | System.setProperty("os.name", original); 42 | } 43 | 44 | @Test 45 | public void getOsVersion() { 46 | String original = System.getProperty("os.version"); 47 | System.setProperty("os.version", "10"); 48 | assertThat(systemProperties.getOsVersion()).isEqualTo("10"); 49 | System.setProperty("os.version", original); 50 | } 51 | 52 | @Test 53 | public void getOsArch() { 54 | String original = System.getProperty("os.arch"); 55 | System.setProperty("os.arch", "x64"); 56 | assertThat(systemProperties.getOsArch()).isEqualTo("x64"); 57 | System.setProperty("os.arch", original); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/sys/os/OperatingSystemFactoryTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.sys.os; 27 | 28 | import com.github.klieber.phantomjs.sys.LinuxProperties; 29 | import com.github.klieber.phantomjs.sys.SystemProperties; 30 | import org.junit.Test; 31 | import org.junit.runner.RunWith; 32 | import org.mockito.InjectMocks; 33 | import org.mockito.Mock; 34 | import org.mockito.junit.MockitoJUnitRunner; 35 | 36 | import static org.assertj.core.api.Assertions.assertThat; 37 | import static org.mockito.Mockito.when; 38 | 39 | @RunWith(MockitoJUnitRunner.class) 40 | public class OperatingSystemFactoryTest { 41 | 42 | @Mock 43 | private SystemProperties systemProperties; 44 | 45 | @Mock 46 | private LinuxProperties linuxProperties; 47 | 48 | @InjectMocks 49 | private OperatingSystemFactory operatingSystemFactory; 50 | 51 | @Test 52 | public void testCreateMacOperatingSystem() { 53 | OperatingSystem operatingSystem = createMockOs("macos", "10", "x86_64"); 54 | assertThat(operatingSystem.getName()).isEqualTo("macos"); 55 | assertThat(operatingSystem.getVersion()).isEqualTo("10"); 56 | assertThat(operatingSystem.getArchitecture()).isEqualTo("x86_64"); 57 | assertThat(operatingSystem.getDistribution()).isNull(); 58 | assertThat(operatingSystem.getDistributionVersion()).isNull(); 59 | } 60 | 61 | @Test 62 | public void testCreateWinOperatingSystem() { 63 | OperatingSystem operatingSystem = createMockOs("win", "7", "x64"); 64 | assertThat(operatingSystem.getName()).isEqualTo("win"); 65 | assertThat(operatingSystem.getVersion()).isEqualTo("7"); 66 | assertThat(operatingSystem.getArchitecture()).isEqualTo("x86_64"); 67 | assertThat(operatingSystem.getDistribution()).isNull(); 68 | assertThat(operatingSystem.getDistributionVersion()).isNull(); 69 | } 70 | 71 | 72 | @Test 73 | public void testCreateLinuxOperatingSystem() { 74 | when(linuxProperties.getDistribution()).thenReturn("ubuntu"); 75 | when(linuxProperties.getDistributionVersion()).thenReturn("16.04"); 76 | 77 | OperatingSystem operatingSystem = createMockOs("linux", "4", "i686"); 78 | assertThat(operatingSystem.getName()).isEqualTo("linux"); 79 | assertThat(operatingSystem.getVersion()).isEqualTo("4"); 80 | assertThat(operatingSystem.getArchitecture()).isEqualTo("i686"); 81 | assertThat(operatingSystem.getDistribution()).isEqualTo("ubuntu"); 82 | assertThat(operatingSystem.getDistributionVersion()).isEqualTo("16.04"); 83 | } 84 | 85 | private OperatingSystem createMockOs(String name, String version, String arch) { 86 | when(systemProperties.getOsName()).thenReturn(name); 87 | when(systemProperties.getOsVersion()).thenReturn(version); 88 | when(systemProperties.getOsArch()).thenReturn(arch); 89 | return operatingSystemFactory.create(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/test/MockPhantomJsBinary.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.test; 27 | 28 | import org.junit.rules.ExternalResource; 29 | 30 | import java.io.File; 31 | import java.io.PrintWriter; 32 | 33 | public class MockPhantomJsBinary extends ExternalResource { 34 | 35 | private static final String DEFAULT_TARGET_FOLDER = System.getProperty("user.dir")+"/target/"; 36 | private static final String PHANTOMJS_FILE_NAME = "phantomjs"; 37 | 38 | private final File phantomJsBinary; 39 | private final String version; 40 | 41 | public MockPhantomJsBinary(String version) { 42 | this(DEFAULT_TARGET_FOLDER, version); 43 | } 44 | 45 | public MockPhantomJsBinary(String targetFolder, String version) { 46 | this(new File(targetFolder, PHANTOMJS_FILE_NAME), version); 47 | } 48 | 49 | public MockPhantomJsBinary(File phantomJsBinary, String version) { 50 | this.phantomJsBinary = phantomJsBinary; 51 | this.version = version; 52 | } 53 | 54 | @Override 55 | protected void before() throws Throwable { 56 | PrintWriter writer = new PrintWriter(this.phantomJsBinary); 57 | writer.println("#!/bin/sh"); 58 | writer.println("echo "+this.version); 59 | writer.close(); 60 | this.phantomJsBinary.setExecutable(true); 61 | } 62 | 63 | @Override 64 | protected void after() { 65 | if (this.phantomJsBinary.exists()) { 66 | this.phantomJsBinary.delete(); 67 | } 68 | } 69 | 70 | public File get() { 71 | return this.phantomJsBinary; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/util/ArtifactBuilderTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Core 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.util; 27 | 28 | import com.github.klieber.phantomjs.archive.Archive; 29 | import org.eclipse.aether.artifact.Artifact; 30 | import org.junit.Before; 31 | import org.junit.Test; 32 | import org.junit.runner.RunWith; 33 | import org.mockito.Mock; 34 | import org.mockito.junit.MockitoJUnitRunner; 35 | 36 | import static org.assertj.core.api.Assertions.assertThat; 37 | import static org.mockito.Mockito.when; 38 | 39 | @RunWith(MockitoJUnitRunner.class) 40 | public class ArtifactBuilderTest { 41 | 42 | @Mock 43 | private Archive archive; 44 | 45 | private ArtifactBuilder builder = new ArtifactBuilder(); 46 | 47 | private static final String CUSTOM_GROUP_ID = "org.example"; 48 | private static final String CUSTOM_ARTIFACT_ID = "example"; 49 | 50 | private static final String CLASSIFIER = "linux"; 51 | private static final String EXTENSION = "zip"; 52 | private static final String VERSION = "1.0.0"; 53 | 54 | @Before 55 | public void before() { 56 | when(archive.getClassifier()).thenReturn(CLASSIFIER); 57 | when(archive.getExtension()).thenReturn(EXTENSION); 58 | when(archive.getVersion()).thenReturn(VERSION); 59 | } 60 | 61 | @Test 62 | public void shouldCreateArtifactWithDefaults() { 63 | verifyArtifact( 64 | builder.createArtifact(archive), 65 | ArtifactBuilder.GROUP_ID, 66 | ArtifactBuilder.ARTIFACT_ID 67 | ); 68 | } 69 | 70 | @Test 71 | public void shouldCreateArtifactWithCustom() { 72 | verifyArtifact( 73 | builder.createArtifact(CUSTOM_GROUP_ID, CUSTOM_ARTIFACT_ID, archive), 74 | CUSTOM_GROUP_ID, 75 | CUSTOM_ARTIFACT_ID 76 | ); 77 | } 78 | 79 | private void verifyArtifact(Artifact artifact, String groupId, String artifactId) { 80 | assertThat(artifact.getGroupId()).isEqualTo(groupId); 81 | assertThat(artifact.getArtifactId()).isEqualTo(artifactId); 82 | assertThat(artifact.getClassifier()).isEqualTo(CLASSIFIER); 83 | assertThat(artifact.getExtension()).isEqualTo(EXTENSION); 84 | assertThat(artifact.getVersion()).isEqualTo(VERSION); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /phantomjs-maven-core/src/test/resources/test-linux.properties: -------------------------------------------------------------------------------- 1 | ID=ubuntu 2 | VERSION_ID="16.04" 3 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/download-from-repository/hello.js: -------------------------------------------------------------------------------- 1 | console.log('Hello, world!'); 2 | phantom.exit(); -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/download-from-repository/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.github.klieber.it 7 | simple-it 8 | 1.0-SNAPSHOT 9 | 10 | A simple IT verifying the basic use case. 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 17 | 18 | 19 | 20 | @project.groupId@ 21 | @project.artifactId@ 22 | @project.version@ 23 | 24 | 2.1.1 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | @project.groupId@ 34 | @project.artifactId@ 35 | 36 | 37 | 38 | install 39 | exec 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/download-from-repository/prebuild.groovy: -------------------------------------------------------------------------------- 1 | import org.codehaus.plexus.util.FileUtils; 2 | 3 | FileUtils.forceDelete(new File(localRepositoryPath, "com/github/klieber/phantomjs")); 4 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/download-from-repository/verify.groovy: -------------------------------------------------------------------------------- 1 | import org.codehaus.plexus.util.FileUtils 2 | 3 | def platform = System.properties['os.name'].toLowerCase(); 4 | 5 | def expected = 'target/phantomjs-maven-plugin/phantomjs-2.1.1-'; 6 | 7 | if (platform.contains('win')) { 8 | expected += 'windows/phantomjs.exe'; 9 | } else if (platform.contains('mac')) { 10 | expected += 'macosx/bin/phantomjs'; 11 | } else if (platform.contains('nux')) { 12 | def arch = System.properties['os.arch'].contains('64') ? 'x86_64' : 'i686'; 13 | expected += 'linux-' + arch + '/bin/phantomjs'; 14 | } 15 | 16 | File binary = new File(basedir, expected); 17 | 18 | assert binary.isFile() 19 | assert binary.canExecute() 20 | 21 | String buildLog = FileUtils.fileRead(new File(basedir, 'build.log')); 22 | 23 | assert buildLog.contains('Downloading: https://repo.maven.apache.org/maven2/com/github/klieber/phantomjs') : 'phantomjs binaries were not downloaded from repository.'; 24 | assert buildLog.contains('Downloaded: https://repo.maven.apache.org/maven2/com/github/klieber/phantomjs') : 'phantomjs binaries were not downloaded from repository.'; 25 | assert buildLog.contains('Resolved artifact') : 'phantomjs binaries were not resolved.'; 26 | assert !buildLog.contains('phantomjs.binary.path=null') && !buildLog.contains('"phantomjs.binary.path":"null"') : "phantomjs.binary property was not properly set" 27 | assert buildLog.contains('Hello, world!'): 'phantomjs script execution failed.'; 28 | 29 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/download-from-url/hello.js: -------------------------------------------------------------------------------- 1 | console.log('Hello, world!'); 2 | phantom.exit(); -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/download-from-url/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.github.klieber.it 7 | simple-it 8 | 1.0-SNAPSHOT 9 | 10 | A simple IT verifying the basic use case. 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 17 | 18 | 19 | 20 | @project.groupId@ 21 | @project.artifactId@ 22 | @project.version@ 23 | 24 | 2.1.1 25 | false 26 | 27 | URL 28 | 29 | 30 | 31 | 32 | 33 | 34 | @project.groupId@ 35 | @project.artifactId@ 36 | 37 | 38 | 39 | install 40 | exec 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/download-from-url/prebuild.groovy: -------------------------------------------------------------------------------- 1 | import org.codehaus.plexus.util.FileUtils; 2 | 3 | FileUtils.forceDelete(new File(localRepositoryPath, "com/github/klieber/phantomjs")); 4 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/download-from-url/verify.groovy: -------------------------------------------------------------------------------- 1 | import org.codehaus.plexus.util.FileUtils 2 | 3 | def platform = System.properties['os.name'].toLowerCase(); 4 | 5 | def expected = 'target/phantomjs-maven-plugin/phantomjs-2.1.1-'; 6 | 7 | if (platform.contains('win')) { 8 | expected += 'windows/phantomjs.exe'; 9 | } else if (platform.contains('mac')) { 10 | expected += 'macosx/bin/phantomjs'; 11 | } else if (platform.contains('nux')) { 12 | def arch = System.properties['os.arch'].contains('64') ? 'x86_64' : 'i686'; 13 | expected += 'linux-' + arch + '/bin/phantomjs'; 14 | } 15 | 16 | File binary = new File(basedir, expected); 17 | 18 | assert binary.isFile() 19 | assert binary.canExecute() 20 | 21 | String buildLog = FileUtils.fileRead(new File(basedir, 'build.log')); 22 | 23 | assert buildLog.contains('Downloading archive') : 'phantomjs binaries were not downloaded.'; 24 | assert !buildLog.contains('phantomjs.binary.path=null') && !buildLog.contains('"phantomjs.binary.path":"null"') : "phantomjs.binary property was not properly set" 25 | assert buildLog.contains('Hello, world!'): 'phantomjs script execution failed.'; 26 | 27 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-abnormal-exit-code/badscript.js: -------------------------------------------------------------------------------- 1 | console.log('This script will exit with a non-zero code.'); 2 | phantom.exit(1); -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-abnormal-exit-code/invoker.properties: -------------------------------------------------------------------------------- 1 | invoker.buildResult = failure 2 | invoker.buildResult.2 = success 3 | invoker.profiles.2 = ignore-abnormal-exit -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-abnormal-exit-code/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.github.klieber.it 7 | simple-it 8 | 1.0-SNAPSHOT 9 | 10 | A simple IT verifying the basic use case. 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 17 | 18 | 19 | @project.groupId@ 20 | @project.artifactId@ 21 | @project.version@ 22 | 23 | 1.9.2 24 | false 25 | 26 | 27 | 28 | 29 | 30 | install 31 | exec 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | ignore-abnormal-exit 41 | 42 | 43 | 44 | 45 | @project.groupId@ 46 | @project.artifactId@ 47 | @project.version@ 48 | 49 | false 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-abnormal-exit-code/verify.groovy: -------------------------------------------------------------------------------- 1 | import org.codehaus.plexus.util.FileUtils 2 | 3 | String buildLog = FileUtils.fileRead(new File(basedir, 'build.log')); 4 | 5 | assert buildLog.contains('This script will exit with a non-zero code.'): 'phantomjs script execution failed.'; 6 | 7 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-with-args/hello.js: -------------------------------------------------------------------------------- 1 | var args = require('system').args; 2 | console.log('Hello, '+(args[1] ? args[1] : 'failed')+'!'); 3 | phantom.exit(); -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-with-args/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.github.klieber.it 7 | simple-it 8 | 1.0-SNAPSHOT 9 | 10 | A simple IT verifying the basic use case. 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 17 | 18 | 19 | @project.groupId@ 20 | @project.artifactId@ 21 | @project.version@ 22 | 23 | 2.1.1 24 | false 25 | 26 | 27 | Bob 28 | 29 | 30 | 31 | 32 | 33 | install 34 | exec 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-with-args/verify.groovy: -------------------------------------------------------------------------------- 1 | import org.codehaus.plexus.util.FileUtils 2 | 3 | String buildLog = FileUtils.fileRead(new File(basedir, 'build.log')); 4 | 5 | assert buildLog.contains('Hello, Bob!'): 'phantomjs script execution failed.'; 6 | 7 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-with-command-line-options/hello.js: -------------------------------------------------------------------------------- 1 | var args = require('system').args; 2 | console.log('Hello, '+(args[1] ? args[1] : 'failed')+'!'); 3 | phantom.exit(); -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-with-command-line-options/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.github.klieber.it 7 | simple-it 8 | 1.0-SNAPSHOT 9 | 10 | A simple IT verifying the basic use case. 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 17 | 18 | 19 | @project.groupId@ 20 | @project.artifactId@ 21 | @project.version@ 22 | 23 | 1.9.2 24 | false 25 | --debug=true 26 | 27 | 28 | Bob 29 | 30 | 31 | 32 | 33 | 34 | install 35 | exec 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-with-command-line-options/verify.groovy: -------------------------------------------------------------------------------- 1 | import org.codehaus.plexus.util.FileUtils 2 | 3 | String buildLog = FileUtils.fileRead(new File(basedir, 'build.log')); 4 | 5 | assert buildLog.contains('[DEBUG]'): 'phantomjs script execution failed.'; 6 | 7 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-with-config-file/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "cookiesFile" : "target/cookies.txt" 3 | } -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-with-config-file/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-with-config-file/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.github.klieber.it 7 | simple-it 8 | 1.0-SNAPSHOT 9 | 10 | A simple IT verifying the basic use case. 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 17 | 18 | 19 | @project.groupId@ 20 | @project.artifactId@ 21 | @project.version@ 22 | 23 | 1.9.2 24 | false 25 | config.json 26 | 27 | 28 | 29 | 30 | 31 | install 32 | exec 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-with-config-file/store-cookie.js: -------------------------------------------------------------------------------- 1 | var page = require('webpage').create(); 2 | page.open('index.html', function (status) { 3 | phantom.exit(); 4 | }); -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/exec-with-config-file/verify.groovy: -------------------------------------------------------------------------------- 1 | def platform = System.properties['os.name'].toLowerCase(); 2 | 3 | def expected = 'target/phantomjs-maven-plugin/phantomjs-1.9.2-'; 4 | 5 | if (platform.contains('win')) { 6 | expected += 'windows/phantomjs.exe'; 7 | } else if (platform.contains('mac')) { 8 | expected += 'macosx/bin/phantomjs'; 9 | } else if (platform.contains('nux')) { 10 | def arch = System.properties['os.arch'].contains('64') ? 'x86_64' : 'i686'; 11 | expected += 'linux-' + arch + '/bin/phantomjs'; 12 | } 13 | 14 | File binary = new File(basedir, expected); 15 | 16 | assert binary.isFile() 17 | assert binary.canExecute() 18 | 19 | File cookiesFile = new File(basedir, "target/cookies.txt"); 20 | 21 | assert cookiesFile.isFile() : 'phantomjs script execution failed.'; 22 | 23 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | 24 | 25 | it-repo 26 | 27 | true 28 | 29 | 30 | 31 | local.central 32 | @localRepositoryUrl@ 33 | 34 | true 35 | 36 | 37 | true 38 | 39 | 40 | 41 | 42 | 43 | local.central 44 | @localRepositoryUrl@ 45 | 46 | true 47 | 48 | 49 | true 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/simple-it/hello.js: -------------------------------------------------------------------------------- 1 | console.log('Hello, world!'); 2 | phantom.exit(); -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/simple-it/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.github.klieber.it 7 | simple-it 8 | 1.0-SNAPSHOT 9 | 10 | A simple IT verifying the basic use case. 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 17 | 18 | 19 | 20 | @project.groupId@ 21 | @project.artifactId@ 22 | @project.version@ 23 | 24 | 1.9.6 25 | false 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | @project.groupId@ 34 | @project.artifactId@ 35 | 36 | 37 | 38 | install 39 | exec 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/simple-it/verify.groovy: -------------------------------------------------------------------------------- 1 | import org.codehaus.plexus.util.FileUtils 2 | 3 | def platform = System.properties['os.name'].toLowerCase(); 4 | 5 | def expected = 'target/phantomjs-maven-plugin/phantomjs-1.9.6-'; 6 | 7 | if (platform.contains('win')) { 8 | expected += 'windows/phantomjs.exe'; 9 | } else if (platform.contains('mac')) { 10 | expected += 'macosx/bin/phantomjs'; 11 | } else if (platform.contains('nux')) { 12 | def arch = System.properties['os.arch'].contains('64') ? 'x86_64' : 'i686'; 13 | expected += 'linux-' + arch + '/bin/phantomjs'; 14 | } 15 | 16 | File binary = new File(basedir, expected); 17 | 18 | assert binary.isFile() 19 | assert binary.canExecute() 20 | 21 | String buildLog = FileUtils.fileRead(new File(basedir, 'build.log')); 22 | 23 | assert buildLog.contains('Hello, world!'): 'phantomjs script execution failed.'; 24 | 25 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/with-integration-tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.github.klieber.it 7 | with-integration-tests 8 | 1.0-SNAPSHOT 9 | 10 | Verify that the plugin integrates with jasmine-maven-plugin. 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 17 | 18 | junit 19 | junit 20 | 4.11 21 | test 22 | 23 | 24 | 25 | 26 | 27 | 28 | @project.groupId@ 29 | @project.artifactId@ 30 | @project.version@ 31 | 32 | 33 | install-phantomjs 34 | 35 | install 36 | 37 | 38 | 1.9.2 39 | false 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-surefire-plugin 47 | 2.16 48 | 49 | 50 | ${phantomjs.binary} 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/with-integration-tests/src/test/java/org/example/ExampleTest.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import org.junit.Test; 4 | 5 | import java.io.File; 6 | 7 | import static org.junit.Assert.assertNotNull; 8 | import static org.junit.Assert.assertTrue; 9 | 10 | public class ExampleTest { 11 | 12 | @Test 13 | public void shouldHavePhantomJsBinary() { 14 | String binary = System.getProperty("phantomjs.binary"); 15 | assertNotNull(binary); 16 | assertTrue(new File(binary).exists()); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/with-integration-tests/verify.groovy: -------------------------------------------------------------------------------- 1 | import org.codehaus.plexus.util.FileUtils; 2 | 3 | String buildLog = FileUtils.fileRead(new File(basedir, 'build.log')); 4 | 5 | assert !buildLog.contains('phantomjs.binary.path=null') && !buildLog.contains('"phantomjs.binary.path":"null"') : "phantomjs.binary property was not properly set" 6 | assert buildLog.contains('Tests run: 1, Failures: 0, Errors: 0, Skipped: 0') : 'junit tests failed to execute' 7 | assert buildLog.contains('BUILD SUCCESS') : 'build was not successful' 8 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/with-jasmine-maven-plugin-it/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.github.klieber.it 7 | with-jasmine-maven-plugin-it 8 | 1.0-SNAPSHOT 9 | 10 | Verify that the plugin integrates with jasmine-maven-plugin. 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 17 | 18 | 19 | @project.groupId@ 20 | @project.artifactId@ 21 | @project.version@ 22 | 23 | 24 | install-phantomjs 25 | 26 | install 27 | 28 | 29 | 1.9.2 30 | false 31 | 32 | 33 | 34 | 35 | 36 | com.github.searls 37 | jasmine-maven-plugin 38 | 1.3.1.2 39 | 40 | 41 | 42 | test 43 | 44 | 45 | 46 | 47 | org.openqa.selenium.phantomjs.PhantomJSDriver 48 | 49 | ${phantomjs.binary} 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/with-jasmine-maven-plugin-it/src/main/javascript/HelloWorld.js: -------------------------------------------------------------------------------- 1 | var HelloWorld = function() { 2 | this.greeting = function() { 3 | return "Hello, World"; 4 | }; 5 | }; -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/with-jasmine-maven-plugin-it/src/test/javascript/HelloWorldSpec.js: -------------------------------------------------------------------------------- 1 | describe('HelloWorld',function(){ 2 | 3 | it('should say hello',function(){ 4 | var helloWorld = new HelloWorld(); 5 | expect(helloWorld.greeting()).toBe("Hello, World"); 6 | }); 7 | 8 | }); -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/it/with-jasmine-maven-plugin-it/verify.groovy: -------------------------------------------------------------------------------- 1 | import org.codehaus.plexus.util.FileUtils; 2 | 3 | String buildLog = FileUtils.fileRead(new File(basedir, 'build.log')); 4 | 5 | assert !buildLog.contains('phantomjs.binary.path=null') && !buildLog.contains('"phantomjs.binary.path":"null"') : "phantomjs.binary property was not properly set" 6 | assert buildLog.contains('Results: 1 specs, 0 failures') : 'jasmine specs failed to execute' 7 | assert buildLog.contains('BUILD SUCCESS') : 'build was not successful' -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/main/java/com/github/klieber/phantomjs/mojo/AbstractPhantomJsMojo.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Plugin 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.mojo; 27 | 28 | import com.google.common.annotations.VisibleForTesting; 29 | import org.apache.maven.plugin.AbstractMojo; 30 | import org.apache.maven.plugin.MojoFailureException; 31 | import org.apache.maven.plugins.annotations.Parameter; 32 | import org.apache.maven.project.MavenProject; 33 | import org.codehaus.plexus.util.StringUtils; 34 | 35 | import javax.inject.Inject; 36 | 37 | /** 38 | * Abstract base class for phantomjs-maven-plugin mojos. 39 | */ 40 | public abstract class AbstractPhantomJsMojo extends AbstractMojo { 41 | 42 | /** 43 | * The name of the property that will contains the path to the binary. 44 | * 45 | * @since 0.1 46 | */ 47 | @Parameter( 48 | defaultValue = "phantomjs.binary", 49 | property = "phantomjs.propertyName", 50 | required = true 51 | ) 52 | private String propertyName; 53 | 54 | /** 55 | * The path to the phantomjs binary 56 | * 57 | * @since 0.2 58 | */ 59 | @Parameter( 60 | property = "phantomjs.binary" 61 | ) 62 | private String phantomJsBinary; 63 | 64 | /** 65 | * Skip the phantomjs-maven-plugin execution. 66 | * 67 | * @since 0.2 68 | */ 69 | @Parameter( 70 | defaultValue = "false", 71 | property = "phantomjs.skip", 72 | required = true 73 | ) 74 | private boolean skip; 75 | 76 | private final MavenProject mavenProject; 77 | 78 | @Inject 79 | public AbstractPhantomJsMojo(MavenProject mavenProject) { 80 | this.mavenProject = mavenProject; 81 | } 82 | 83 | public final void execute() throws MojoFailureException { 84 | if (!skip) { 85 | this.run(); 86 | } 87 | } 88 | 89 | protected abstract void run() throws MojoFailureException; 90 | 91 | protected MavenProject getMavenProject() { 92 | return this.mavenProject; 93 | } 94 | 95 | protected String getPhantomJsBinary() { 96 | if (StringUtils.isBlank(this.phantomJsBinary)) { 97 | this.phantomJsBinary = getPhantomJsBinaryProperty(); 98 | } 99 | return this.phantomJsBinary; 100 | } 101 | 102 | protected String getPhantomJsBinaryProperty() { 103 | return mavenProject.getProperties().getProperty(this.propertyName); 104 | } 105 | 106 | protected void setPhantomJsBinaryProperty(String binary) { 107 | mavenProject.getProperties().setProperty(this.propertyName, binary); 108 | } 109 | 110 | @VisibleForTesting 111 | void setPhantomJsBinary(String phantomJsBinary) { 112 | this.phantomJsBinary = phantomJsBinary; 113 | } 114 | 115 | @VisibleForTesting 116 | void setPropertyName(String propertyName) { 117 | this.propertyName = propertyName; 118 | } 119 | 120 | @VisibleForTesting 121 | void setSkip(boolean skip) { 122 | this.skip = skip; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/site/markdown/index.md.vm: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | This plugin is generally meant to be used with another plugin that requires 5 | the phantomjs binary. The plugin will download the binary and make it 6 | executable. Then it will set the property, `phantomjs.binary`, to the path 7 | to the binary. 8 | 9 | This example shows a typical usage with the [jasmine-maven-plugin](http://searls.github.io/jasmine-maven-plugin/). 10 | 11 | ``` 12 | 13 | ... 14 | 15 | 16 | 17 | ${project.groupId} 18 | ${project.artifactId} 19 | ${currentStableVersion} 20 | 21 | 22 | 23 | install 24 | 25 | 26 | 27 | 28 | 1.9.7 29 | 30 | 31 | 32 | com.github.searls 33 | jasmine-maven-plugin 34 | ${jasmine-maven-plugin.version} 35 | 36 | 37 | 38 | test 39 | 40 | 41 | 42 | 43 | org.openqa.selenium.phantomjs.PhantomJSDriver 44 | 45 | ${phantomjs.binary} 46 | 47 | 48 | 49 | ... 50 | 51 | 52 | ... 53 | 54 | ``` 55 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/site/resources/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klieber/phantomjs-maven-plugin/7ec6526a23289bf883048b54985c2c08942ad0a3/phantomjs-maven-plugin/src/site/resources/.nojekyll -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/site/resources/googleaf8abcbec6fb6df5.html: -------------------------------------------------------------------------------- 1 | google-site-verification: googleaf8abcbec6fb6df5.html -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | org.apache.maven.skins 6 | maven-fluido-skin 7 | 1.6 8 | 9 | 10 | 11 | 12 | klieber/phantomjs-maven-plugin 13 | right 14 | black 15 | 16 | 17 | phantomjs-maven-plugin 18 | thin-badge 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 27 | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 28 | m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 29 | })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 30 | 31 | ga('create', 'UA-52118741-1', 'kylelieber.com'); 32 | ga('send', 'pageview'); 33 | ]]> 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/test/java/com/github/klieber/phantomjs/mojo/AbstractPhantomJsMojoTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Plugin 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.mojo; 27 | 28 | import org.apache.maven.plugin.MojoFailureException; 29 | import org.apache.maven.project.MavenProject; 30 | import org.junit.Before; 31 | import org.junit.Test; 32 | import org.junit.runner.RunWith; 33 | import org.mockito.Mock; 34 | import org.mockito.junit.MockitoJUnitRunner; 35 | 36 | import java.util.Properties; 37 | 38 | import static org.assertj.core.api.Assertions.assertThat; 39 | import static org.mockito.Mockito.never; 40 | import static org.mockito.Mockito.spy; 41 | import static org.mockito.Mockito.times; 42 | import static org.mockito.Mockito.verify; 43 | import static org.mockito.Mockito.when; 44 | 45 | @RunWith(MockitoJUnitRunner.class) 46 | public class AbstractPhantomJsMojoTest { 47 | 48 | private static final String BINARY_PATH = "bin/phantomjs"; 49 | private static final String PROPERTY_NAME = "phantomjs.bin.path"; 50 | 51 | @Mock 52 | private MavenProject project; 53 | 54 | @Mock 55 | private Properties properties; 56 | 57 | private MockPhantomJsMojo mojo; 58 | 59 | @Before 60 | public void before() { 61 | mojo = spy(new MockPhantomJsMojo(project)); 62 | when(project.getProperties()).thenReturn(properties); 63 | } 64 | 65 | @Test 66 | public void testExecute() throws MojoFailureException { 67 | mojo.execute(); 68 | verify(mojo).run(); 69 | } 70 | 71 | @Test 72 | public void testSkipExecute() throws MojoFailureException { 73 | mojo.setSkip(true); 74 | mojo.execute(); 75 | verify(mojo, never()).run(); 76 | } 77 | 78 | @Test 79 | public void testGetMavenProject() throws MojoFailureException { 80 | assertThat(mojo.getMavenProject()).isSameAs(project); 81 | } 82 | 83 | @Test 84 | public void testGetPhantomJsBinary() { 85 | mojo.setPhantomJsBinary(BINARY_PATH); 86 | assertThat(mojo.getPhantomJsBinary()).isEqualTo(BINARY_PATH); 87 | } 88 | 89 | @Test 90 | public void testGetPhantomJsBinaryFromProject() { 91 | when(properties.getProperty(PROPERTY_NAME)).thenReturn(BINARY_PATH); 92 | mojo.setPropertyName(PROPERTY_NAME); 93 | assertThat(mojo.getPhantomJsBinary()).isEqualTo(BINARY_PATH); 94 | verify(project, times(1)).getProperties(); 95 | verify(properties, times(1)).getProperty(PROPERTY_NAME); 96 | } 97 | 98 | @Test 99 | public void testSetPhantomJsBinary() { 100 | mojo.setPropertyName(PROPERTY_NAME); 101 | mojo.setPhantomJsBinaryProperty(BINARY_PATH); 102 | verify(properties).setProperty(PROPERTY_NAME, BINARY_PATH); 103 | } 104 | 105 | static class MockPhantomJsMojo extends AbstractPhantomJsMojo { 106 | 107 | MockPhantomJsMojo(MavenProject mavenProject) { 108 | super(mavenProject); 109 | } 110 | 111 | @Override 112 | protected void run() { 113 | 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /phantomjs-maven-plugin/src/test/java/com/github/klieber/phantomjs/mojo/ExecPhantomJsMojoTest.java: -------------------------------------------------------------------------------- 1 | /*- 2 | * #%L 3 | * PhantomJS Maven Plugin 4 | * %% 5 | * Copyright (C) 2013 - 2017 Kyle Lieber 6 | * %% 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * #L% 25 | */ 26 | package com.github.klieber.phantomjs.mojo; 27 | 28 | import com.github.klieber.phantomjs.exec.ExecutionException; 29 | import com.github.klieber.phantomjs.exec.PhantomJsExecutor; 30 | import com.github.klieber.phantomjs.exec.PhantomJsProcessBuilder; 31 | import junit.framework.TestCase; 32 | import org.apache.maven.plugin.MojoFailureException; 33 | import org.apache.maven.project.MavenProject; 34 | import org.junit.Test; 35 | import org.junit.runner.RunWith; 36 | import org.mockito.InjectMocks; 37 | import org.mockito.Mock; 38 | import org.mockito.junit.MockitoJUnitRunner; 39 | 40 | import java.util.Properties; 41 | 42 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 43 | import static org.mockito.Matchers.isA; 44 | import static org.mockito.Mockito.when; 45 | 46 | @RunWith(MockitoJUnitRunner.class) 47 | public class ExecPhantomJsMojoTest extends TestCase { 48 | 49 | @Mock 50 | private MavenProject mavenProject; 51 | 52 | @Mock 53 | private PhantomJsExecutor executor; 54 | 55 | @Mock 56 | private Properties properties; 57 | 58 | @InjectMocks 59 | private ExecPhantomJsMojo mojo; 60 | 61 | @Test 62 | public void testRun() throws Exception { 63 | when(mavenProject.getProperties()).thenReturn(properties); 64 | when(executor.execute(isA(PhantomJsProcessBuilder.class))).thenReturn(0); 65 | mojo.setFailOnNonZeroExitCode(true); 66 | mojo.run(); 67 | } 68 | 69 | @Test 70 | public void testRunNoFailureOnNonZero() throws Exception { 71 | when(mavenProject.getProperties()).thenReturn(properties); 72 | when(executor.execute(isA(PhantomJsProcessBuilder.class))).thenReturn(1); 73 | mojo.setFailOnNonZeroExitCode(false); 74 | mojo.run(); 75 | } 76 | 77 | @Test 78 | public void testRunFailureOnNonZero() throws Exception { 79 | when(mavenProject.getProperties()).thenReturn(properties); 80 | when(executor.execute(isA(PhantomJsProcessBuilder.class))).thenReturn(1); 81 | mojo.setFailOnNonZeroExitCode(true); 82 | assertThatThrownBy(() -> mojo.run()) 83 | .isInstanceOf(MojoFailureException.class) 84 | .hasMessage("PhantomJS execution did not exit normally (code = 1)"); 85 | } 86 | 87 | @Test 88 | public void testRunFailureOnExecutionException() throws Exception { 89 | when(mavenProject.getProperties()).thenReturn(properties); 90 | when(executor.execute(isA(PhantomJsProcessBuilder.class))).thenThrow(ExecutionException.class); 91 | mojo.setFailOnNonZeroExitCode(true); 92 | assertThatThrownBy(() -> mojo.run()) 93 | .isInstanceOf(MojoFailureException.class) 94 | .hasMessage("Failed to execute PhantomJS command") 95 | .hasCauseInstanceOf(ExecutionException.class); 96 | } 97 | } 98 | --------------------------------------------------------------------------------