-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor repositories to be more abstract
- Loading branch information
Showing
7 changed files
with
157 additions
and
25 deletions.
There are no files selected for viewing
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
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
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
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
31 changes: 31 additions & 0 deletions
31
api/src/main/java/revxrsal/zapper/repository/LocalMavenRepository.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,31 @@ | ||
package revxrsal.zapper.repository; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import revxrsal.zapper.Dependency; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
|
||
/** | ||
* Represents the local maven repository | ||
*/ | ||
final class LocalMavenRepository implements Repository { | ||
|
||
private final @NotNull File directory; | ||
|
||
LocalMavenRepository(@NotNull File directory) { | ||
this.directory = directory; | ||
} | ||
|
||
@Override | ||
public @NotNull URL resolve(@NotNull Dependency dependency) throws Exception { | ||
String systemPath = dependency.getMavenPath().replace('/', File.separatorChar); | ||
File file = new File(directory, systemPath); | ||
return file.toURI().toURL(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return directory.toString(); | ||
} | ||
} |
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
100 changes: 100 additions & 0 deletions
100
api/src/main/java/revxrsal/zapper/repository/Repository.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,100 @@ | ||
package revxrsal.zapper.repository; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import revxrsal.zapper.Dependency; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
|
||
/** | ||
* Represents a repository that can resolve {@link revxrsal.zapper.Dependency dependencies} | ||
*/ | ||
public interface Repository { | ||
|
||
/** | ||
* Resolves the dependency URL that is downloaded. | ||
* | ||
* @param dependency Dependency to resolve | ||
* @return The URL to resolve | ||
* @throws Exception any exception that indicates that this repository could not | ||
* resolve the dependency | ||
*/ | ||
@NotNull URL resolve(@NotNull Dependency dependency) throws Exception; | ||
|
||
/** | ||
* Creates a Maven repository from the specified URL. | ||
* | ||
* @param url the URL of the repository | ||
* @return the configured Maven repository | ||
*/ | ||
static @NotNull Repository maven(@NotNull URL url) { | ||
return MavenRepository.maven(url.toString()); | ||
} | ||
|
||
/** | ||
* Creates a Maven repository from the specified URL string. | ||
* | ||
* @param url the URL of the repository as a string | ||
* @return the configured Maven repository | ||
*/ | ||
static @NotNull Repository maven(@NotNull String url) { | ||
return MavenRepository.maven(url); | ||
} | ||
|
||
/** | ||
* Returns a repository representing the local Maven directory (default: ~/.m2). | ||
* | ||
* @return the local Maven repository | ||
*/ | ||
static @NotNull Repository mavenLocal() { | ||
String userHome = System.getProperty("user.home"); | ||
File m2 = new File(userHome, ".m2"); | ||
return new LocalMavenRepository(m2); | ||
} | ||
|
||
/** | ||
* Returns a repository representing a custom local Maven directory. | ||
* | ||
* @param directory the local Maven directory | ||
* @return the local Maven repository | ||
*/ | ||
static @NotNull Repository mavenLocal(@NotNull File directory) { | ||
return new LocalMavenRepository(directory); | ||
} | ||
|
||
/** | ||
* Returns the Maven Central repository. | ||
* | ||
* @return the Maven Central repository | ||
*/ | ||
static @NotNull Repository mavenCentral() { | ||
return MavenRepository.mavenCentral(); | ||
} | ||
|
||
/** | ||
* Returns the JitPack repository. | ||
* | ||
* @return the JitPack repository | ||
*/ | ||
static @NotNull Repository jitpack() { | ||
return MavenRepository.jitpack(); | ||
} | ||
|
||
/** | ||
* Returns the PaperMC repository. | ||
* | ||
* @return the PaperMC repository | ||
*/ | ||
static @NotNull Repository paper() { | ||
return MavenRepository.paper(); | ||
} | ||
|
||
/** | ||
* Returns the Minecraft repository. | ||
* | ||
* @return the Minecraft repository | ||
*/ | ||
static @NotNull Repository minecraft() { | ||
return MavenRepository.minecraft(); | ||
} | ||
} |