Skip to content

Replace downloadJar with downloadJarFromURL #1685

Description

@jan-vcapgemini

All usages of downloadJar can be replaced with downloadJarFromURL. The old method downloadJar is way too adjusted to old monolithic templates and can be removed.
The old update command (download of monolithic template jars) will be removed anyway.

TemplatesJarUtil.downloadJar("com.devonfw.cobigen", "templates-devon4j", "3.0.0", false, templatesPath.toFile());
TemplatesJarUtil.downloadJar("com.devonfw.cobigen", "templates-devon4j", "3.0.0", true, templatesPath.toFile());

public static String downloadJar(String groupId, String artifactId, String version, boolean isDownloadSource,
File templatesDirectory) {
// By default the version should be latest
if (StringUtils.isEmpty(version)) {
version = "LATEST";
}
String mavenUrl = "https://repository.sonatype.org/service/local/artifact/maven/" + "redirect?r=central-proxy&g="
+ groupId + "&a=" + artifactId + "&v=" + version;
if (isDownloadSource) {
mavenUrl = mavenUrl + "&c=sources";
}
String fileName = "";
Path jarFilePath = getJarFile(isDownloadSource, templatesDirectory.toPath());
try {
if (jarFilePath == null || !Files.exists(jarFilePath)
|| isJarOutdated(jarFilePath.toFile(), mavenUrl, isDownloadSource, templatesDirectory)) {
HttpURLConnection conn = initializeConnection(mavenUrl);
try (InputStream inputStream = conn.getInputStream()) {
fileName = conn.getURL().getFile().substring(conn.getURL().getFile().lastIndexOf("/") + 1);
File file = new File(templatesDirectory.getPath() + File.separator + fileName);
Path targetPath = file.toPath();
if (!file.exists()) {
Files.copy(inputStream, targetPath, StandardCopyOption.REPLACE_EXISTING);
}
}
conn.disconnect();
} else {
fileName = jarFilePath.toFile().getPath()
.substring(jarFilePath.toFile().getPath().lastIndexOf(File.separator) + 1);
}
} catch (IOException e) {
throw new CobiGenRuntimeException("Could not download file from " + mavenUrl, e);
}
return fileName;
}

/**
* Downloads a jar from a given URL to template set downloaded directory
*
* @param downloadURL URl to download from
* @param templateSetDirectory directory where the template sets are located
* @return fileName Name of the file downloaded
*/
public static String downloadJarFromURL(String downloadURL, Path templateSetDirectory) {

Can be removed:

public static String downloadLatestDevon4jTemplates(boolean isDownloadSource, File templatesDirectory) {

Can be removed:

public static void downloadTemplatesByMavenCoordinates(Path templatesDirectory,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions