Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace downloadJar with downloadJarFromURL #1685

Open
jan-vcapgemini opened this issue Apr 11, 2023 · 0 comments
Open

Replace downloadJar with downloadJarFromURL #1685

jan-vcapgemini opened this issue Apr 11, 2023 · 0 comments

Comments

@jan-vcapgemini
Copy link
Collaborator

jan-vcapgemini commented Apr 11, 2023

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,

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

No branches or pull requests

1 participant