This repository has been archived by the owner on Apr 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
570 additions
and
439 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/PhantomJs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.github.klieber.phantomjs; | ||
|
||
import com.github.klieber.phantomjs.locate.LocatorFactory; | ||
import com.github.klieber.phantomjs.locate.PhantomJsLocatorOptions; | ||
import com.github.klieber.phantomjs.locate.RepositoryDetails; | ||
import org.eclipse.aether.RepositorySystem; | ||
import org.eclipse.aether.RepositorySystemSession; | ||
import org.eclipse.aether.repository.RemoteRepository; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Named | ||
public class PhantomJs { | ||
|
||
private final LocatorFactory locatorFactory; | ||
|
||
@Inject | ||
public PhantomJs(LocatorFactory locatorFactory) { | ||
this.locatorFactory = locatorFactory; | ||
} | ||
|
||
public Builder options(PhantomJsLocatorOptions options) { | ||
return new Builder(locatorFactory, options); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private final LocatorFactory locatorFactory; | ||
private final PhantomJsLocatorOptions options; | ||
private final List<RemoteRepository> remoteRepositories; | ||
|
||
private RepositorySystem repositorySystem; | ||
private RepositorySystemSession repositorySystemSession; | ||
|
||
private Builder(LocatorFactory locatorFactory, | ||
PhantomJsLocatorOptions options) { | ||
this.locatorFactory = locatorFactory; | ||
this.options = options; | ||
this.remoteRepositories = new ArrayList<RemoteRepository>(); | ||
} | ||
|
||
public Builder repositorySystem(RepositorySystem repositorySystem) { | ||
this.repositorySystem = repositorySystem; | ||
return this; | ||
} | ||
|
||
public Builder repositorySystemSession(RepositorySystemSession repositorySystemSession) { | ||
this.repositorySystemSession = repositorySystemSession; | ||
return this; | ||
} | ||
|
||
public Builder remoteRepository(RemoteRepository remoteRepository) { | ||
this.remoteRepositories.add(remoteRepository); | ||
return this; | ||
} | ||
|
||
public Builder remoteRepositories(List<RemoteRepository> remoteRepositories) { | ||
this.remoteRepositories.addAll(remoteRepositories); | ||
return this; | ||
} | ||
|
||
public String locate() { | ||
RepositoryDetails repositoryDetails = new RepositoryDetails( | ||
this.repositorySystem, | ||
this.repositorySystemSession, | ||
this.remoteRepositories | ||
); | ||
|
||
return locatorFactory.getLocator(options, repositoryDetails).locate(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/cache/ArchiveCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.github.klieber.phantomjs.cache; | ||
|
||
import com.github.klieber.phantomjs.archive.PhantomJSArchive; | ||
import com.github.klieber.phantomjs.util.ArtifactBuilder; | ||
import org.eclipse.aether.RepositorySystemSession; | ||
import org.eclipse.aether.artifact.Artifact; | ||
import org.eclipse.aether.repository.LocalRepositoryManager; | ||
|
||
import java.io.File; | ||
|
||
public class ArchiveCache { | ||
|
||
private final ArtifactBuilder artifactBuilder; | ||
private final RepositorySystemSession repositorySystemSession; | ||
|
||
public ArchiveCache(ArtifactBuilder artifactBuilder, | ||
RepositorySystemSession repositorySystemSession) { | ||
this.artifactBuilder = artifactBuilder; | ||
this.repositorySystemSession = repositorySystemSession; | ||
} | ||
|
||
public File getFile(PhantomJSArchive phantomJSArchive) { | ||
Artifact artifact = artifactBuilder.createArtifact(phantomJSArchive); | ||
LocalRepositoryManager manager = repositorySystemSession.getLocalRepositoryManager(); | ||
return new File(manager.getRepository().getBasedir(), manager.getPathForLocalArtifact(artifact)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...omjs-maven-core/src/main/java/com/github/klieber/phantomjs/cache/ArchiveCacheFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.github.klieber.phantomjs.cache; | ||
|
||
import com.github.klieber.phantomjs.util.ArtifactBuilder; | ||
import org.eclipse.aether.RepositorySystemSession; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
@Named | ||
public class ArchiveCacheFactory { | ||
|
||
private final ArtifactBuilder artifactBuilder; | ||
|
||
@Inject | ||
public ArchiveCacheFactory(ArtifactBuilder artifactBuilder) { | ||
this.artifactBuilder = artifactBuilder; | ||
} | ||
|
||
public ArchiveCache create(RepositorySystemSession repositorySystemSession) { | ||
return new ArchiveCache(artifactBuilder, repositorySystemSession); | ||
} | ||
} |
56 changes: 0 additions & 56 deletions
56
phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/cache/CachedArtifact.java
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/cache/CachedFile.java
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/cache/CachedFileFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.klieber.phantomjs.cache; | ||
|
||
import com.github.klieber.phantomjs.archive.PhantomJSArchive; | ||
import com.github.klieber.phantomjs.util.ArtifactBuilder; | ||
import org.eclipse.aether.RepositorySystemSession; | ||
import org.eclipse.aether.artifact.Artifact; | ||
import org.eclipse.aether.repository.LocalRepositoryManager; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import java.io.File; | ||
|
||
@Named | ||
public class CachedFileFactory { | ||
|
||
private final ArtifactBuilder artifactBuilder; | ||
|
||
@Inject | ||
public CachedFileFactory(ArtifactBuilder artifactBuilder) { | ||
this.artifactBuilder = artifactBuilder; | ||
} | ||
|
||
public File create(PhantomJSArchive phantomJSArchive, RepositorySystemSession repositorySystemSession) { | ||
Artifact artifact = artifactBuilder.createArtifact(phantomJSArchive); | ||
LocalRepositoryManager manager = repositorySystemSession.getLocalRepositoryManager(); | ||
return new File(manager.getRepository().getBasedir(), manager.getPathForLocalArtifact(artifact)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...mjs-maven-core/src/main/java/com/github/klieber/phantomjs/download/DownloaderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.github.klieber.phantomjs.download; | ||
|
||
import com.github.klieber.phantomjs.cache.ArchiveCache; | ||
import com.github.klieber.phantomjs.cache.ArchiveCacheFactory; | ||
import com.github.klieber.phantomjs.locate.PhantomJsLocatorOptions; | ||
import com.github.klieber.phantomjs.locate.RepositoryDetails; | ||
import com.github.klieber.phantomjs.util.ArtifactBuilder; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
@Named | ||
public class DownloaderFactory { | ||
|
||
private final ArtifactBuilder artifactBuilder; | ||
private final ArchiveCacheFactory archiveCacheFactory; | ||
|
||
@Inject | ||
public DownloaderFactory(ArtifactBuilder artifactBuilder, | ||
ArchiveCacheFactory archiveCacheFactory) { | ||
this.archiveCacheFactory = archiveCacheFactory; | ||
this.artifactBuilder = artifactBuilder; | ||
} | ||
|
||
public Downloader getDownloader(PhantomJsLocatorOptions options, | ||
RepositoryDetails repositoryDetails) { | ||
return isRepositorySource(options) ? | ||
createRepositoryDownloader(repositoryDetails) : createWebDownloader(repositoryDetails); | ||
} | ||
|
||
private boolean isRepositorySource(PhantomJsLocatorOptions options) { | ||
return PhantomJsLocatorOptions.Source.REPOSITORY.equals(options.getSource()); | ||
} | ||
|
||
private Downloader createRepositoryDownloader(RepositoryDetails repositoryDetails) { | ||
return new RepositoryDownloader(artifactBuilder, repositoryDetails); | ||
} | ||
|
||
private Downloader createWebDownloader(RepositoryDetails repositoryDetails) { | ||
ArchiveCache archiveCache = archiveCacheFactory.create(repositoryDetails.getRepositorySystemSession()); | ||
return new WebDownloader(archiveCache); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.