use of org.apache.maven.artifact.versioning.ComparableVersion in project jbpm by kiegroup.
the class DeploymentIdResolver method findLatest.
public static String findLatest(Collection<String> deploymentIds) {
List<ComparableVersion> comparableVersions = new ArrayList<ComparableVersion>();
Map<String, String> versionToIdentifier = new HashMap<String, String>();
for (String deploymentId : deploymentIds) {
GAVInfo gav = new GAVInfo(deploymentId);
comparableVersions.add(new ComparableVersion(gav.getVersion()));
versionToIdentifier.put(gav.getVersion(), deploymentId);
}
ComparableVersion latest = Collections.max(comparableVersions);
return versionToIdentifier.get(latest.toString());
}
use of org.apache.maven.artifact.versioning.ComparableVersion in project embulk by embulk.
the class EmbulkSelfUpdate method updateSelfWithExceptions.
private void updateSelfWithExceptions(final String runningVersionString, final String specifiedVersionString, final boolean isForced) throws IOException, URISyntaxException {
final Path jarPathJava = Paths.get(EmbulkSelfUpdate.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
if ((!Files.exists(jarPathJava)) || (!Files.isRegularFile(jarPathJava))) {
throw exceptionNoSingleJar();
}
final String targetVersionString;
if (specifiedVersionString != null) {
System.out.printf("Checking version %s...\n", specifiedVersionString);
targetVersionString = checkTargetVersion(specifiedVersionString);
if (targetVersionString == null) {
throw new RuntimeException(String.format("Specified version does not exist: %s", specifiedVersionString));
}
System.out.printf("Found version %s.\n", specifiedVersionString);
} else {
System.out.println("Checking the latest version...");
final ComparableVersion runningVersion = new ComparableVersion(runningVersionString);
targetVersionString = checkLatestVersion();
final ComparableVersion targetVersion = new ComparableVersion(targetVersionString);
if (targetVersion.compareTo(runningVersion) <= 0) {
System.out.printf("Already up-to-date. %s is the latest version.\n", runningVersion);
return;
}
System.out.printf("Found a newer version %s.\n", targetVersion);
}
if (!Files.isWritable(jarPathJava)) {
throw new RuntimeException(String.format("The existing %s is not writable. May need to sudo?", jarPathJava.toString()));
}
final URL downloadUrl = new URL(String.format("https://dl.bintray.com/embulk/maven/embulk-%s.jar", targetVersionString));
System.out.printf("Downloading %s ...\n", downloadUrl.toString());
Path jarPathTemp = Files.createTempFile("embulk-selfupdate", ".jar");
try {
final HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection();
try {
// Follow the redicrect from the Bintray URL.
connection.setInstanceFollowRedirects(true);
connection.setRequestMethod("GET");
connection.connect();
final int statusCode = connection.getResponseCode();
if (HttpURLConnection.HTTP_OK != statusCode) {
throw new FileNotFoundException(String.format("Unexpected HTTP status code: %d", statusCode));
}
InputStream input = connection.getInputStream();
// TODO(dmikurube): Confirm if it is okay to replace a temp file created by Files.createTempFile.
Files.copy(input, jarPathTemp, StandardCopyOption.REPLACE_EXISTING);
Files.setPosixFilePermissions(jarPathTemp, Files.getPosixFilePermissions(jarPathJava));
} finally {
connection.disconnect();
}
if (!isForced) {
// Check corruption
final String versionJarTemp;
try {
versionJarTemp = getJarVersion(jarPathTemp);
} catch (FileNotFoundException ex) {
throw new RuntimeException("Failed to check corruption. Downloaded version may include incompatible changes. Try the '-f' option to force updating without checking.", ex);
}
if (!versionJarTemp.equals(targetVersionString)) {
throw new RuntimeException(String.format("Downloaded version does not match: %s (downloaded) / %s (target)", versionJarTemp, targetVersionString));
}
}
Files.move(jarPathTemp, jarPathJava, StandardCopyOption.REPLACE_EXISTING);
} finally {
Files.deleteIfExists(jarPathTemp);
}
System.out.println(String.format("Updated to %s.", targetVersionString));
}
use of org.apache.maven.artifact.versioning.ComparableVersion in project meghanada-server by mopemope.
the class GradleProject method parseIdeaModule.
private void parseIdeaModule(final org.gradle.tooling.model.GradleProject gradleProject, final IdeaModule ideaModule) throws IOException {
if (isNull(this.output)) {
final String buildDir = gradleProject.getBuildDirectory().getCanonicalPath();
String build = Joiner.on(File.separator).join(buildDir, "classes", "main");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(buildDir, "classes", "java", "main");
}
this.output = this.normalize(build);
}
if (isNull(this.testOutput)) {
final String buildDir = gradleProject.getBuildDirectory().getCanonicalPath();
String build = Joiner.on(File.separator).join(buildDir, "classes", "test");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(buildDir, "classes", "java", "test");
}
this.testOutput = this.normalize(build);
}
final Set<ProjectDependency> dependencies = this.analyzeDependencies(ideaModule);
final Map<String, Set<File>> sources = this.searchProjectSources(ideaModule);
this.sources.addAll(sources.get("sources"));
this.resources.addAll(sources.get("resources"));
this.testSources.addAll(sources.get("testSources"));
this.testResources.addAll(sources.get("testResources"));
this.dependencies.addAll(dependencies);
// merge other project
if (this.sources.isEmpty()) {
final File file = new File(Joiner.on(File.separator).join("src", "main", "java")).getCanonicalFile();
this.sources.add(file);
}
if (this.testSources.isEmpty()) {
final File file = new File(Joiner.on(File.separator).join("src", "test", "java")).getCanonicalFile();
this.testSources.add(file);
}
if (isNull(this.output)) {
final String buildDir = new File(this.getProjectRoot(), "build").getCanonicalPath();
String build = Joiner.on(File.separator).join(buildDir, "classes", "main");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(buildDir, "classes", "java", "main");
}
this.output = this.normalize(build);
}
if (isNull(this.testOutput)) {
final String buildDir = new File(this.getProjectRoot(), "build").getCanonicalPath();
String build = Joiner.on(File.separator).join(buildDir, "classes", "test");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(buildDir, "classes", "java", "test");
}
this.testOutput = this.normalize(build);
}
log.debug("sources {}", this.sources);
log.debug("resources {}", this.resources);
log.debug("output {}", this.output);
log.debug("test sources {}", this.testSources);
log.debug("test resources {}", this.testResources);
log.debug("test output {}", this.testOutput);
for (final ProjectDependency projectDependency : this.getDependencies()) {
log.debug("{} {}", projectDependency.getScope(), projectDependency.getId());
}
}
use of org.apache.maven.artifact.versioning.ComparableVersion in project meghanada-server by mopemope.
the class GradleProject method parseProject.
@Override
public Project parseProject() throws ProjectParseException {
final ProjectConnection connection = getProjectConnection();
log.info("loading gradle project:{}", new File(this.projectRoot, Project.GRADLE_PROJECT_FILE));
try {
BuildEnvironment env = connection.getModel(BuildEnvironment.class);
String version = env.getGradle().getGradleVersion();
if (isNull(version)) {
version = GradleVersion.current().getVersion();
}
if (nonNull(version)) {
this.gradleVersion = new ComparableVersion(version);
}
final IdeaProject ideaProject = debugTimeItF("get idea project model elapsed={}", () -> connection.getModel(IdeaProject.class));
this.setCompileTarget(ideaProject);
log.trace("load root project path:{}", this.rootProject);
final DomainObjectSet<? extends IdeaModule> modules = ideaProject.getModules();
final List<? extends IdeaModule> mainModules = modules.parallelStream().filter(ideaModule -> {
final org.gradle.tooling.model.GradleProject gradleProject = ideaModule.getGradleProject();
final File moduleProjectRoot = gradleProject.getProjectDirectory();
final String name = ideaModule.getName();
log.trace("find sub-module name {} path {} ", name, moduleProjectRoot);
this.allModules.putIfAbsent(name, moduleProjectRoot);
return moduleProjectRoot.equals(this.getProjectRoot());
}).collect(Collectors.toList());
mainModules.forEach(wrapIOConsumer(this::parseIdeaModule));
// set default output
if (isNull(super.output)) {
String build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "main");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "java", "main");
}
super.output = this.normalize(build);
}
if (isNull(super.testOutput)) {
String build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "test");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "java", "test");
}
super.testOutput = this.normalize(build);
}
return this;
} catch (Exception e) {
throw new ProjectParseException(e);
} finally {
connection.close();
}
}
use of org.apache.maven.artifact.versioning.ComparableVersion in project MinecraftForge by MinecraftForge.
the class ModListScreen method updateCache.
private void updateCache() {
if (selected == null) {
this.configButton.active = false;
this.modInfo.clearInfo();
return;
}
IModInfo selectedMod = selected.getInfo();
this.configButton.active = ConfigGuiHandler.getGuiFactoryFor(selectedMod).isPresent();
List<String> lines = new ArrayList<>();
VersionChecker.CheckResult vercheck = VersionChecker.getResult(selectedMod);
@SuppressWarnings("resource") Pair<ResourceLocation, Size2i> logoData = selectedMod.getLogoFile().map(logoFile -> {
TextureManager tm = this.minecraft.getTextureManager();
final PathResourcePack resourcePack = ResourcePackLoader.getPackFor(selectedMod.getModId()).orElse(ResourcePackLoader.getPackFor("forge").orElseThrow(() -> new RuntimeException("Can't find forge, WHAT!")));
try {
NativeImage logo = null;
InputStream logoResource = resourcePack.getRootResource(logoFile);
if (logoResource != null)
logo = NativeImage.read(logoResource);
if (logo != null) {
return Pair.of(tm.register("modlogo", new DynamicTexture(logo) {
@Override
public void upload() {
this.bind();
NativeImage td = this.getPixels();
// Use custom "blur" value which controls texture filtering (nearest-neighbor vs linear)
this.getPixels().upload(0, 0, 0, 0, 0, td.getWidth(), td.getHeight(), selectedMod.getLogoBlur(), false, false, false);
}
}), new Size2i(logo.getWidth(), logo.getHeight()));
}
} catch (IOException e) {
}
return Pair.<ResourceLocation, Size2i>of(null, new Size2i(0, 0));
}).orElse(Pair.of(null, new Size2i(0, 0)));
lines.add(selectedMod.getDisplayName());
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.version", MavenVersionStringHelper.artifactVersionToString(selectedMod.getVersion())));
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), ModList.get().getModContainerById(selectedMod.getModId()).map(ModContainer::getCurrentState).map(Object::toString).orElse("NONE")));
selectedMod.getConfig().getConfigElement("credits").ifPresent(credits -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.credits", credits)));
selectedMod.getConfig().getConfigElement("authors").ifPresent(authors -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.authors", authors)));
selectedMod.getConfig().getConfigElement("displayURL").ifPresent(displayURL -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.displayurl", displayURL)));
if (selectedMod.getOwningFile() == null || selectedMod.getOwningFile().getMods().size() == 1)
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.nochildmods"));
else
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.childmods", selectedMod.getOwningFile().getMods().stream().map(IModInfo::getDisplayName).collect(Collectors.joining(","))));
if (vercheck.status() == VersionChecker.Status.OUTDATED || vercheck.status() == VersionChecker.Status.BETA_OUTDATED)
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.updateavailable", vercheck.url() == null ? "" : vercheck.url()));
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.license", selectedMod.getOwningFile().getLicense()));
lines.add(null);
lines.add(selectedMod.getDescription());
if ((vercheck.status() == VersionChecker.Status.OUTDATED || vercheck.status() == VersionChecker.Status.BETA_OUTDATED) && vercheck.changes().size() > 0) {
lines.add(null);
lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.changelogheader"));
for (Entry<ComparableVersion, String> entry : vercheck.changes().entrySet()) {
lines.add(" " + entry.getKey() + ":");
lines.add(entry.getValue());
lines.add(null);
}
}
modInfo.setInfo(lines, logoData.getLeft(), logoData.getRight());
}
Aggregations