2
0
Fork 0
mirror of https://github.com/ethauvin/rife2.git synced 2025-05-01 19:08:12 -07:00

Added bld.downloadExtensionSources and bld.downloadExtensionJavadoc wrapper properties

This commit is contained in:
Geert Bevin 2023-04-02 17:16:27 -04:00
parent cb5f22933f
commit a14473f567
2 changed files with 62 additions and 14 deletions

View file

@ -43,6 +43,8 @@ public class Wrapper {
static final String PROPERTY_REPOSITORIES = "bld.repositories"; static final String PROPERTY_REPOSITORIES = "bld.repositories";
static final String PROPERTY_EXTENSION_PREFIX = "bld.extension"; static final String PROPERTY_EXTENSION_PREFIX = "bld.extension";
static final String PROPERTY_EXTENSIONS = "bld.extensions"; static final String PROPERTY_EXTENSIONS = "bld.extensions";
static final String PROPERTY_DOWNLOAD_EXTENSION_SOURCES = "bld.downloadExtensionSources";
static final String PROPERTY_DOWNLOAD_EXTENSION_JAVADOC = "bld.downloadExtensionJavadoc";
static final File RIFE2_USER_DIR = new File(System.getProperty("user.home"), ".rife2"); static final File RIFE2_USER_DIR = new File(System.getProperty("user.home"), ".rife2");
static final File DISTRIBUTIONS_DIR = new File(RIFE2_USER_DIR, "dist"); static final File DISTRIBUTIONS_DIR = new File(RIFE2_USER_DIR, "dist");
@ -52,6 +54,8 @@ public class Wrapper {
private File wrapperPropertiesFile_ = null; private File wrapperPropertiesFile_ = null;
private final Set<String> repositories_ = new LinkedHashSet<>(); private final Set<String> repositories_ = new LinkedHashSet<>();
private final Set<String> extensions_ = new LinkedHashSet<>(); private final Set<String> extensions_ = new LinkedHashSet<>();
private boolean downloadExtensionSources_ = false;
private boolean downloadExtensionJavadoc_ = false;
private final byte[] buffer_ = new byte[1024]; private final byte[] buffer_ = new byte[1024];
private WrapperClassLoader classloader_; private WrapperClassLoader classloader_;
@ -141,13 +145,24 @@ public class Wrapper {
throw new IOException(e); throw new IOException(e);
} }
} else { } else {
wrapperProperties_.put(PROPERTY_REPOSITORIES, MAVEN_CENTRAL); var properties_blueprint = """
wrapperProperties_.put(PROPERTY_EXTENSIONS, ""); bld.downloadExtensionJavadoc=false
wrapperProperties_.put(PROPERTY_DOWNLOAD_LOCATION, ""); bld.downloadExtensionSources=true
wrapperProperties_.put(PROPERTY_VERSION, version); bld.extensions=
bld.repositories=${repository}
rife2.downloadLocation=
rife2.version=${version}
"""
.replace("${repository}", MAVEN_CENTRAL)
.replace("${version}", version);
Files.createDirectories(file.getAbsoluteFile().toPath().getParent()); Files.createDirectories(file.getAbsoluteFile().toPath().getParent());
Files.deleteIfExists(file.toPath()); Files.deleteIfExists(file.toPath());
wrapperProperties_.store(new FileWriter(file), null); try {
FileUtils.writeString(properties_blueprint, file);
} catch (FileUtilsErrorException e) {
throw new IOException(e);
}
} }
} }
@ -307,6 +322,9 @@ public class Wrapper {
} }
} }
} }
// check whether extension sources or javadoc should be downloaded
downloadExtensionSources_ = Boolean.parseBoolean(wrapperProperties_.getProperty(PROPERTY_DOWNLOAD_EXTENSION_SOURCES, "false"));
downloadExtensionJavadoc_ = Boolean.parseBoolean(wrapperProperties_.getProperty(PROPERTY_DOWNLOAD_EXTENSION_JAVADOC, "false"));
} }
private String getWrapperVersion() private String getWrapperVersion()
@ -417,9 +435,11 @@ public class Wrapper {
try { try {
var resolver_class = classloader_.loadClass("rife.bld.wrapper.WrapperExtensionResolver"); var resolver_class = classloader_.loadClass("rife.bld.wrapper.WrapperExtensionResolver");
var constructor = resolver_class.getConstructor(File.class, File.class, File.class, Collection.class, Collection.class); var constructor = resolver_class.getConstructor(File.class, File.class, File.class, Collection.class, Collection.class, boolean.class, boolean.class);
var update_method = resolver_class.getDeclaredMethod("updateExtensions"); var update_method = resolver_class.getDeclaredMethod("updateExtensions");
var resolver = constructor.newInstance(currentDir_, new File(wrapperPropertiesFile_.getAbsolutePath() + ".hash"), libBldDirectory(), repositories_, extensions_); var resolver = constructor.newInstance(currentDir_, new File(wrapperPropertiesFile_.getAbsolutePath() + ".hash"), libBldDirectory(),
repositories_, extensions_,
downloadExtensionSources_, downloadExtensionJavadoc_);
update_method.invoke(resolver); update_method.invoke(resolver);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
throw new RuntimeException(e.getCause()); throw new RuntimeException(e.getCause());

View file

@ -16,6 +16,9 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.*; import java.util.*;
import static rife.bld.dependencies.Dependency.CLASSIFIER_JAVADOC;
import static rife.bld.dependencies.Dependency.CLASSIFIER_SOURCES;
/** /**
* Resolves, downloads and purges the bld extension dependencies. * Resolves, downloads and purges the bld extension dependencies.
* <p> * <p>
@ -30,10 +33,14 @@ public class WrapperExtensionResolver {
private final File destinationDirectory_; private final File destinationDirectory_;
private final List<Repository> repositories_ = new ArrayList<>(); private final List<Repository> repositories_ = new ArrayList<>();
private final DependencySet dependencies_ = new DependencySet(); private final DependencySet dependencies_ = new DependencySet();
private final boolean downloadSources_;
private final boolean downloadJavadoc_;
private boolean headerPrinted_ = false; private boolean headerPrinted_ = false;
public WrapperExtensionResolver(File currentDir, File hashFile, File destinationDirectory, Collection<String> repositories, Collection<String> extensions) { public WrapperExtensionResolver(File currentDir, File hashFile, File destinationDirectory,
Collection<String> repositories, Collection<String> extensions,
boolean downloadSources, boolean downloadJavadoc) {
var properties = BuildExecutor.setupProperties(currentDir); var properties = BuildExecutor.setupProperties(currentDir);
Repository.resolveMavenLocal(properties); Repository.resolveMavenLocal(properties);
@ -55,12 +62,14 @@ public class WrapperExtensionResolver {
} }
} }
dependencies_.addAll(extensions.stream().map(Dependency::parse).toList()); dependencies_.addAll(extensions.stream().map(Dependency::parse).toList());
fingerPrintHash_ = createHash(repositories_.stream().map(Objects::toString).toList(), extensions); downloadSources_ = downloadSources;
downloadJavadoc_ = downloadJavadoc;
fingerPrintHash_ = createHash(repositories_.stream().map(Objects::toString).toList(), extensions, downloadSources, downloadJavadoc);
} }
private String createHash(Collection<String> repositories, Collection<String> extensions) { private String createHash(Collection<String> repositories, Collection<String> extensions, boolean downloadSources, boolean downloadJavadoc) {
try { try {
var fingerprint = String.join("\n", repositories) + "\n" + String.join("\n", extensions); var fingerprint = String.join("\n", repositories) + "\n" + String.join("\n", extensions) + "\n" + downloadSources + "\n" + downloadJavadoc;
var digest = MessageDigest.getInstance("SHA-1"); var digest = MessageDigest.getInstance("SHA-1");
digest.update(fingerprint.getBytes(StandardCharsets.UTF_8)); digest.update(fingerprint.getBytes(StandardCharsets.UTF_8));
return StringUtils.encodeHexLower(digest.digest()); return StringUtils.encodeHexLower(digest.digest());
@ -124,11 +133,24 @@ public class WrapperExtensionResolver {
ensurePrintedHeader(); ensurePrintedHeader();
dependencies.removeIf(dependency -> dependency.baseDependency().equals(new Dependency("com.uwyn.rife2", "rife2"))); dependencies.removeIf(dependency -> dependency.baseDependency().equals(new Dependency("com.uwyn.rife2", "rife2")));
dependencies.transferIntoDirectory(repositories_, destinationDirectory_);
var additional_classifiers = new String[0];
if (downloadSources_ || downloadJavadoc_) {
var classifiers = new ArrayList<String>();
if (downloadSources_) classifiers.add(CLASSIFIER_SOURCES);
if (downloadJavadoc_) classifiers.add(CLASSIFIER_JAVADOC);
additional_classifiers = classifiers.toArray(new String[0]);
}
dependencies.transferIntoDirectory(repositories_, destinationDirectory_, additional_classifiers);
for (var dependency : dependencies) { for (var dependency : dependencies) {
for (var location : new DependencyResolver(repositories_, dependency).getTransferLocations()) { addTransferLocations(filenames, dependency);
filenames.add(location.substring(location.lastIndexOf("/") + 1)); if (downloadSources_) {
addTransferLocations(filenames, dependency.withClassifier(CLASSIFIER_SOURCES));
}
if (downloadJavadoc_) {
addTransferLocations(filenames, dependency.withClassifier(CLASSIFIER_JAVADOC));
} }
} }
} }
@ -136,6 +158,12 @@ public class WrapperExtensionResolver {
return filenames; return filenames;
} }
private void addTransferLocations(HashSet<String> filenames, Dependency dependency) {
for (var location : new DependencyResolver(repositories_, dependency).getTransferLocations()) {
filenames.add(location.substring(location.lastIndexOf("/") + 1));
}
}
private void purgeExtensionDependencies(Set<String> filenames) { private void purgeExtensionDependencies(Set<String> filenames) {
for (var file : destinationDirectory_.listFiles()) { for (var file : destinationDirectory_.listFiles()) {
if (file.getName().startsWith(Wrapper.WRAPPER_PREFIX)) { if (file.getName().startsWith(Wrapper.WRAPPER_PREFIX)) {