Search in sources :

Example 1 with ComparableVersion

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion)

Example 2 with ComparableVersion

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));
}
Also used : Path(java.nio.file.Path) HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) URL(java.net.URL)

Example 3 with ComparableVersion

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());
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DomainObjectSet(org.gradle.tooling.model.DomainObjectSet) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ProjectDependency(meghanada.project.ProjectDependency) File(java.io.File)

Example 4 with ComparableVersion

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();
    }
}
Also used : Config.debugTimeItF(meghanada.config.Config.debugTimeItF) IdeaDependency(org.gradle.tooling.model.idea.IdeaDependency) ProjectParseException(meghanada.project.ProjectParseException) IdeaJavaLanguageSettings(org.gradle.tooling.model.idea.IdeaJavaLanguageSettings) FunctionUtils.wrapIOConsumer(meghanada.utils.FunctionUtils.wrapIOConsumer) StringUtils(org.apache.commons.lang3.StringUtils) PipedInputStream(java.io.PipedInputStream) Map(java.util.Map) GradleConnector(org.gradle.tooling.GradleConnector) Objects.isNull(java.util.Objects.isNull) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) Splitter(com.google.common.base.Splitter) GradleVersion(org.gradle.util.GradleVersion) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) BuildLauncher(org.gradle.tooling.BuildLauncher) CompileResult(meghanada.analyze.CompileResult) AndroidProject(com.android.builder.model.AndroidProject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) ResultHandler(org.gradle.tooling.ResultHandler) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ClassNameUtils(meghanada.utils.ClassNameUtils) IdeaContentRoot(org.gradle.tooling.model.idea.IdeaContentRoot) IdeaSingleEntryLibraryDependency(org.gradle.tooling.model.idea.IdeaSingleEntryLibraryDependency) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) Project(meghanada.project.Project) Objects.nonNull(java.util.Objects.nonNull) ProjectDependency(meghanada.project.ProjectDependency) Config(meghanada.config.Config) Joiner(com.google.common.base.Joiner) HashMap(java.util.HashMap) GradleConnectionException(org.gradle.tooling.GradleConnectionException) IdeaSourceDirectory(org.gradle.tooling.model.idea.IdeaSourceDirectory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) Files(com.google.common.io.Files) ConfigFactory(com.typesafe.config.ConfigFactory) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) IdeaModuleDependency(org.gradle.tooling.model.idea.IdeaModuleDependency) DomainObjectSet(org.gradle.tooling.model.DomainObjectSet) IOException(java.io.IOException) PipedOutputStream(java.io.PipedOutputStream) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) IdeaProject(org.gradle.tooling.model.idea.IdeaProject) GradleModuleVersion(org.gradle.tooling.model.GradleModuleVersion) ProjectConnection(org.gradle.tooling.ProjectConnection) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) IdeaProject(org.gradle.tooling.model.idea.IdeaProject) ProjectConnection(org.gradle.tooling.ProjectConnection) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ProjectParseException(meghanada.project.ProjectParseException) GradleConnectionException(org.gradle.tooling.GradleConnectionException) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) IOException(java.io.IOException) ProjectParseException(meghanada.project.ProjectParseException) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) File(java.io.File)

Example 5 with ComparableVersion

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());
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Font(net.minecraft.client.gui.Font) ObjectSelectionList(net.minecraft.client.gui.components.ObjectSelectionList) Pair(org.apache.commons.lang3.tuple.Pair) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) PathResourcePack(net.minecraftforge.resource.PathResourcePack) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) FMLPaths(net.minecraftforge.fml.loading.FMLPaths) Screen(net.minecraft.client.gui.screens.Screen) ModList(net.minecraftforge.fml.ModList) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) Language(net.minecraft.locale.Language) Style(net.minecraft.network.chat.Style) List(java.util.List) Util(net.minecraft.Util) Logger(org.apache.logging.log4j.Logger) EditBox(net.minecraft.client.gui.components.EditBox) Entry(java.util.Map.Entry) FormattedCharSequence(net.minecraft.util.FormattedCharSequence) ForgeI18n(net.minecraftforge.common.ForgeI18n) Size2i(net.minecraftforge.common.util.Size2i) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) ForgeHooks(net.minecraftforge.common.ForgeHooks) ModContainer(net.minecraftforge.fml.ModContainer) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Minecraft(net.minecraft.client.Minecraft) MavenVersionStringHelper(net.minecraftforge.common.util.MavenVersionStringHelper) NativeImage(com.mojang.blaze3d.platform.NativeImage) Button(net.minecraft.client.gui.components.Button) StringUtils(net.minecraftforge.fml.loading.StringUtils) GameRenderer(net.minecraft.client.renderer.GameRenderer) ResourcePackLoader(net.minecraftforge.resource.ResourcePackLoader) Component(net.minecraft.network.chat.Component) NarrationElementOutput(net.minecraft.client.gui.narration.NarrationElementOutput) IOException(java.io.IOException) TextureManager(net.minecraft.client.renderer.texture.TextureManager) Consumer(java.util.function.Consumer) Tesselator(com.mojang.blaze3d.vertex.Tesselator) VersionChecker(net.minecraftforge.fml.VersionChecker) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ModListWidget(net.minecraftforge.client.gui.widget.ModListWidget) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) ConfigGuiHandler(net.minecraftforge.client.ConfigGuiHandler) InputStream(java.io.InputStream) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModContainer(net.minecraftforge.fml.ModContainer) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) IOException(java.io.IOException) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) VersionChecker(net.minecraftforge.fml.VersionChecker) TextureManager(net.minecraft.client.renderer.texture.TextureManager) NativeImage(com.mojang.blaze3d.platform.NativeImage) ResourceLocation(net.minecraft.resources.ResourceLocation) Size2i(net.minecraftforge.common.util.Size2i) PathResourcePack(net.minecraftforge.resource.PathResourcePack)

Aggregations

ComparableVersion (org.apache.maven.artifact.versioning.ComparableVersion)13 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Matcher (java.util.regex.Matcher)4 File (java.io.File)3 List (java.util.List)3 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)2 URL (java.net.URL)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2 ProjectDependency (meghanada.project.ProjectDependency)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 DomainObjectSet (org.gradle.tooling.model.DomainObjectSet)2