Search in sources :

Example 26 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getLatestVersion.

public MavenPluginVersion getLatestVersion() {
    Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":LATEST");
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.setRepositories(mavenPluginRepository.getRepositories());
    try {
        VersionRangeResult rangeResult = mavenPluginRepository.getSystem().resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
        List<Version> versions = rangeResult.getVersions();
        if (!versions.isEmpty()) {
            Version version = versions.get(0);
            ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
            Artifact versionArtifact = new DefaultArtifact(groupId + ":" + artifactId + ":pom:" + version.toString());
            descriptorRequest.setArtifact(versionArtifact);
            descriptorRequest.setRepositories(mavenPluginRepository.getRepositories());
            MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
            ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
            ArtifactRequest request = new ArtifactRequest();
            request.setArtifact(descriptorResult.getArtifact());
            request.setRepositories(mavenPluginRepository.getRepositories());
            ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
            File pomFile = resolveArtifact.getArtifact().getFile();
            MavenXpp3Reader mavenreader = new MavenXpp3Reader();
            try (FileReader fileReader = new FileReader(pomFile)) {
                try {
                    Model model = mavenreader.read(fileReader);
                    mavenPluginVersion.setModel(model);
                } catch (XmlPullParserException e) {
                    e.printStackTrace();
                }
            } catch (FileNotFoundException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
                DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
                mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
            }
            return mavenPluginVersion;
        }
    } catch (VersionRangeResolutionException e) {
        e.printStackTrace();
    } catch (ArtifactDescriptorException e) {
        e.printStackTrace();
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Version(org.eclipse.aether.version.Version) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Model(org.apache.maven.model.Model) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) File(java.io.File) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 27 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project maven-git-versioning-extension by qoomon.

the class VersioningModelProcessor method deduceProjectVersion.

private ProjectVersion deduceProjectVersion(GAV gav, File gitDir) throws IOException {
    FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder().findGitDir(gitDir);
    logger.debug(gav + "git directory " + repositoryBuilder.getGitDir());
    try (Repository repository = repositoryBuilder.build()) {
        final String headCommit = getHeadCommit(repository);
        String projectBranchName = null;
        String projectTagName = null;
        VersionFormatDescription projectVersionFormatDescription = null;
        Map<String, String> projectVersionDataMap = buildCommonVersionDataMap(headCommit, gav);
        if (!configuration.getTagVersionDescriptions().isEmpty()) {
            final List<String> headTags = getHeadTags(repository);
            if (!headTags.isEmpty()) {
                for (VersionFormatDescription versionFormatDescription : configuration.getTagVersionDescriptions()) {
                    String tagName = headTags.stream().sequential().filter(tag -> tag.matches(versionFormatDescription.pattern)).sorted((versionLeft, versionRight) -> {
                        DefaultArtifactVersion tagVersionLeft = new DefaultArtifactVersion(removePrefix(versionLeft, versionFormatDescription.prefix));
                        DefaultArtifactVersion tagVersionRight = new DefaultArtifactVersion(removePrefix(versionRight, versionFormatDescription.prefix));
                        // -1 revert sorting, latest version first
                        return tagVersionLeft.compareTo(tagVersionRight) * -1;
                    }).findFirst().orElse(null);
                    if (tagName != null) {
                        projectTagName = tagName;
                        projectVersionFormatDescription = versionFormatDescription;
                        projectVersionDataMap.put("tag", removePrefix(projectTagName, projectVersionFormatDescription.prefix));
                        projectVersionDataMap.putAll(getRegexGroupValueMap(projectVersionFormatDescription.pattern, projectTagName));
                        break;
                    }
                }
            }
        }
        if (projectTagName == null) {
            final String branchName = getHeadBranch(repository).orElseThrow(() -> new ModelParseException(gitDir + ": No Branch Name provided in Detached HEAD state. See documentation.", 0, 0));
            projectBranchName = branchName;
            projectVersionFormatDescription = configuration.getBranchVersionDescriptions().stream().filter(versionFormatDescription -> branchName.matches(versionFormatDescription.pattern)).findFirst().orElseThrow(() -> new ModelParseException(gitDir + ": No version format for branch '" + branchName + "' found.", 0, 0));
            projectVersionDataMap.put("branch", removePrefix(projectBranchName, projectVersionFormatDescription.prefix));
            projectVersionDataMap.putAll(getRegexGroupValueMap(projectVersionFormatDescription.pattern, projectBranchName));
        }
        String version = StrSubstitutor.replace(projectVersionFormatDescription.versionFormat, projectVersionDataMap);
        ProjectVersion projectVersion = new ProjectVersion(escapeVersion(version), headCommit, projectBranchName, projectTagName);
        logger.info(gav.getArtifactId() + ":" + gav.getVersion() + (projectVersion.getTag() != null ? " - tag: " + projectVersion.getTag() : "") + (projectVersion.getTag() != null ? " - branch: " + projectVersion.getBranch() : "") + " -> version: " + projectVersion.getVersion());
        return projectVersion;
    }
}
Also used : ModelParseException(org.apache.maven.model.io.ModelParseException) PluginExecution(org.apache.maven.model.PluginExecution) java.util(java.util) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) VersionFormatDescription(com.qoomon.maven.extension.gitversioning.config.model.VersionFormatDescription) Component(org.codehaus.plexus.component.annotations.Component) Build(org.apache.maven.model.Build) Inject(javax.inject.Inject) Matcher(java.util.regex.Matcher) ModelProcessor(org.apache.maven.model.building.ModelProcessor) ModelUtil(com.qoomon.maven.ModelUtil) Source(org.apache.maven.building.Source) StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) DefaultModelProcessor(org.apache.maven.model.building.DefaultModelProcessor) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) MavenSession(org.apache.maven.execution.MavenSession) Constants(org.eclipse.jgit.lib.Constants) IOException(java.io.IOException) Reader(java.io.Reader) SessionScopeUtil(com.qoomon.maven.extension.gitversioning.SessionScopeUtil) Collectors(java.util.stream.Collectors) File(java.io.File) ObjectId(org.eclipse.jgit.lib.ObjectId) GAV(com.qoomon.maven.GAV) Plugin(org.apache.maven.model.Plugin) SessionScope(org.apache.maven.session.scope.internal.SessionScope) Stream(java.util.stream.Stream) BuildProperties(com.qoomon.maven.BuildProperties) VersioningConfigurationProvider(com.qoomon.maven.extension.gitversioning.config.VersioningConfigurationProvider) Logger(org.codehaus.plexus.logging.Logger) Pattern(java.util.regex.Pattern) VersioningConfiguration(com.qoomon.maven.extension.gitversioning.config.VersioningConfiguration) Repository(org.eclipse.jgit.lib.Repository) Model(org.apache.maven.model.Model) InputStream(java.io.InputStream) Repository(org.eclipse.jgit.lib.Repository) ModelParseException(org.apache.maven.model.io.ModelParseException) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) VersionFormatDescription(com.qoomon.maven.extension.gitversioning.config.model.VersionFormatDescription) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder)

Example 28 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project liferay-ide by liferay.

the class MavenUtil method getVersion.

public static String getVersion(String version) {
    String retval = null;
    DefaultArtifactVersion v = new DefaultArtifactVersion(version);
    retval = v.getMajorVersion() + "." + v.getMinorVersion() + "." + v.getIncrementalVersion();
    if ("0.0.0".equals(retval)) {
        retval = v.getQualifier();
    }
    try {
        Version.parseVersion(retval);
    } catch (Exception e) {
        retval = "0.0.0";
    }
    return retval;
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException)

Example 29 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project herd by FINRAOS.

the class EmrClusterDefinitionHelper method validateEmrClusterDefinitionConfiguration.

/**
 * Validates an EMR cluster definition configuration.
 *
 * @param emrClusterDefinition the EMR cluster definition configuration
 *
 * @throws IllegalArgumentException if any validation errors were found
 */
public void validateEmrClusterDefinitionConfiguration(EmrClusterDefinition emrClusterDefinition) throws IllegalArgumentException {
    Assert.notNull(emrClusterDefinition, "An EMR cluster definition configuration must be specified.");
    Assert.isTrue(StringUtils.isNotBlank(emrClusterDefinition.getSubnetId()), "Subnet ID must be specified");
    for (String token : emrClusterDefinition.getSubnetId().split(",")) {
        Assert.isTrue(StringUtils.isNotBlank(token), "No blank is allowed in the list of subnet IDs");
    }
    Assert.isTrue(!emrHelper.isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions()) || CollectionUtils.isNotEmpty(emrClusterDefinition.getInstanceFleets()), "Instance group definitions or instance fleets must be specified.");
    if (!emrHelper.isInstanceDefinitionsEmpty(emrClusterDefinition.getInstanceDefinitions())) {
        // Check master instances.
        Assert.notNull(emrClusterDefinition.getInstanceDefinitions().getMasterInstances(), "Master instances must be specified.");
        validateMasterInstanceDefinition(emrClusterDefinition.getInstanceDefinitions().getMasterInstances());
        // Check core instances.
        if (emrClusterDefinition.getInstanceDefinitions().getCoreInstances() != null) {
            validateInstanceDefinition("core", emrClusterDefinition.getInstanceDefinitions().getCoreInstances(), 0);
            // If instance count is <= 0, remove the entire core instance definition since it is redundant.
            if (emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceCount() <= 0) {
                emrClusterDefinition.getInstanceDefinitions().setCoreInstances(null);
            }
        }
        // Check task instances
        if (emrClusterDefinition.getInstanceDefinitions().getTaskInstances() != null) {
            validateInstanceDefinition("task", emrClusterDefinition.getInstanceDefinitions().getTaskInstances(), 1);
        }
        // Check that total number of instances does not exceed the max allowed.
        int maxEmrInstanceCount = configurationHelper.getProperty(ConfigurationValue.MAX_EMR_INSTANCES_COUNT, Integer.class);
        if (maxEmrInstanceCount > 0) {
            int instancesRequested = emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceCount();
            if (emrClusterDefinition.getInstanceDefinitions().getCoreInstances() != null) {
                instancesRequested += emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceCount();
            }
            if (emrClusterDefinition.getInstanceDefinitions().getTaskInstances() != null) {
                instancesRequested += emrClusterDefinition.getInstanceDefinitions().getTaskInstances().getInstanceCount();
            }
            Assert.isTrue((maxEmrInstanceCount >= instancesRequested), "Total number of instances requested can not exceed : " + maxEmrInstanceCount);
        }
    }
    // Validate node tags including checking for required tags and detecting any duplicate node tag names in case sensitive manner.
    Assert.notEmpty(emrClusterDefinition.getNodeTags(), "Node tags must be specified.");
    HashSet<String> nodeTagNameValidationSet = new HashSet<>();
    for (NodeTag nodeTag : emrClusterDefinition.getNodeTags()) {
        Assert.hasText(nodeTag.getTagName(), "A node tag name must be specified.");
        Assert.hasText(nodeTag.getTagValue(), "A node tag value must be specified.");
        Assert.isTrue(!nodeTagNameValidationSet.contains(nodeTag.getTagName()), String.format("Duplicate node tag \"%s\" is found.", nodeTag.getTagName()));
        nodeTagNameValidationSet.add(nodeTag.getTagName());
    }
    // Validate the mandatory AWS tags are there
    for (String mandatoryTag : herdStringHelper.splitStringWithDefaultDelimiter(configurationHelper.getProperty(ConfigurationValue.MANDATORY_AWS_TAGS))) {
        Assert.isTrue(nodeTagNameValidationSet.contains(mandatoryTag), String.format("Mandatory AWS tag not specified: \"%s\"", mandatoryTag));
    }
    emrClusterDefinition.setAdditionalMasterSecurityGroups(assertNotBlankAndTrim(emrClusterDefinition.getAdditionalMasterSecurityGroups(), "additionalMasterSecurityGroup"));
    emrClusterDefinition.setAdditionalSlaveSecurityGroups(assertNotBlankAndTrim(emrClusterDefinition.getAdditionalSlaveSecurityGroups(), "additionalSlaveSecurityGroup"));
    // Fail if security configuration is specified for EMR version less than 4.8.0.
    if (StringUtils.isNotBlank(emrClusterDefinition.getSecurityConfiguration())) {
        final DefaultArtifactVersion securityConfigurationMinEmrVersion = new DefaultArtifactVersion("4.8.0");
        Assert.isTrue(StringUtils.isNotBlank(emrClusterDefinition.getReleaseLabel()) && securityConfigurationMinEmrVersion.compareTo(new DefaultArtifactVersion(emrClusterDefinition.getReleaseLabel().replaceFirst("^(emr-)", ""))) <= 0, "EMR security configuration is not supported prior to EMR release 4.8.0.");
    }
}
Also used : NodeTag(org.finra.herd.model.api.xml.NodeTag) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) HashSet(java.util.HashSet)

Example 30 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project azure-tools-for-java by Microsoft.

the class WhatsNewAction method actionPerformed.

@Override
@AzureOperation(name = "common.load_whatsnew", type = AzureOperation.Type.ACTION)
public void actionPerformed(@Nonnull final AnActionEvent event) {
    final boolean manually = !"AzurePluginStartupActivity".equals(event.getPlace());
    final String content = getWhatsNewContent();
    final DefaultArtifactVersion currentVersion = getVersion(content);
    final DefaultArtifactVersion lastVersion = getLastVersion();
    if (manually || compare(currentVersion, lastVersion)) {
        saveVersion(currentVersion);
        doShow(content, currentVersion, manually, Objects.requireNonNull(event.getProject()));
    }
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Aggregations

DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)37 ArtifactVersion (org.apache.maven.artifact.versioning.ArtifactVersion)12 File (java.io.File)8 IOException (java.io.IOException)7 Model (org.apache.maven.model.Model)5 FileNotFoundException (java.io.FileNotFoundException)4 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)4 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 Artifact (org.apache.maven.artifact.Artifact)3 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)3 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)3 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)3 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)3 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)3 FileReader (java.io.FileReader)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2