org.apache.maven.artifact.versioning.ComparableVersion Java Examples

The following examples show how to use org.apache.maven.artifact.versioning.ComparableVersion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnzipServlet.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
private static ComparableVersion parseVersion ( final String version )
{
    if ( version == null )
    {
        return null;
    }

    try
    {
        return new ComparableVersion ( version );
    }
    catch ( final Exception e )
    {
        logger.debug ( "Version not parsable: " + version, e );
        return null;
    }
}
 
Example #2
Source File: BuildInstallersAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ContextBuildInstaller(Lookup actionContext) {
    this.actionContext = actionContext;
    putValue(NAME, NbBundle.getMessage(BuildInstallersAction.class, "CTL_BuildInstallers"));
    putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
    Project project = actionContext.lookup(Project.class);
    if (project == null) {
        setEnabled(false); //#224115
    } else {
        NbMavenProject watcher = project.getLookup().lookup(NbMavenProject.class);
        if (watcher == null
                || !NbMavenProject.TYPE_NBM_APPLICATION.equalsIgnoreCase(watcher.getPackagingType())) {
            setEnabled(false);
        } else {
            String version = PluginPropertyUtils.getPluginVersion(watcher.getMavenProject(), "org.codehaus.mojo", "nbm-maven-plugin");
            if (version == null || new ComparableVersion(version).compareTo(new ComparableVersion("3.7-SNAPSHOT")) >= 0) {
                setEnabled(false); // now handled by maven.apisupport
            }
        }
    }
}
 
Example #3
Source File: ExtraPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages("LBL_InstallerPanel=Installer")
@Override
    public Category createCategory(Lookup context) {
    Project project = context.lookup(Project.class);
    NbMavenProject watcher = project.getLookup().lookup(NbMavenProject.class);
    if (watcher!=null &&
            NbMavenProject.TYPE_NBM_APPLICATION.equalsIgnoreCase(watcher.getPackagingType())) {
        String version = PluginPropertyUtils.getPluginVersion(watcher.getMavenProject(), "org.codehaus.mojo", "nbm-maven-plugin");
        if (version == null || new ComparableVersion(version).compareTo(new ComparableVersion("3.7-SNAPSHOT")) >= 0) {
            return null; // now handled by maven.apisupport
        }
        return ProjectCustomizer.Category.create(
                "Installer",
                LBL_InstallerPanel(),
                null,
                (ProjectCustomizer.Category[])null);
    }
    return null;
}
 
Example #4
Source File: UnzipServlet.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
protected static void handleMavenPerfect ( final Supplier<Collection<ArtifactInformation>> artifactsSupplier, final ChannelId channelId, final LinkedList<String> path, final IOConsumer<MavenVersionedArtifact> consumer ) throws IOException
{
    requirePathPrefix ( path, 3, "The 'maven' method requires at least one parameter: channel. e.g. /unzip/maven/perfect/<channelIdOrName>/<group.id>/<artifact.id>/<version>/path/to/file" );

    final String groupId = path.pop ();
    final String artifactId = path.pop ();
    final String versionString = path.pop ();

    final ComparableVersion v = new ComparableVersion ( versionString );

    final List<MavenVersionedArtifact> arts = getMavenArtifacts ( channelId.getId (), artifactsSupplier, groupId, artifactId, true, ( a ) -> a.compareTo ( v ) == 0 );

    if ( arts.isEmpty () )
    {
        // no result,
        throw new IllegalStateException ( String.format ( "No artifacts found for - groupId: %s, artifactId: %s, version: %s", groupId, artifactId, v ) );
    }

    processArtifacts ( String.format ( "maven artifact %s/%s/%s in channel %s", groupId, artifactId, versionString, channelId.getId () ), arts, consumer );
}
 
Example #5
Source File: DropwizardMojo.java    From dropwizard-debpkg-maven-plugin with Apache License 2.0 6 votes vote down vote up
protected void validateApplicationConfiguration(final File resourcesDir) throws MojoExecutionException {
    try {
        final Optional<Dependency> dropwizardDependency = Iterables.tryFind(project.getModel().getDependencies(),
                new DependencyFilter(DROPWIZARD_GROUP_ID, DROPWIZARD_ARTIFACT_ID));
        if (!dropwizardDependency.isPresent()) {
            log.warn("Failed to find Dropwizard dependency in project. Skipping configuration validation.");
            return;
        }

        final ComparableVersion version = new ComparableVersion(dropwizardDependency.get().getVersion());
        log.info(String.format("Detected Dropwizard %s, attempting to validate configuration.", version));

        final File configFile = new File(resourcesDir, "/files" + path.getConfigFile());
        final ApplicationValidator validator = new ApplicationValidator(artifactFile, log);
        validator.validateConfiguration(configFile);
    }
    catch (IOException | IllegalArgumentException | ClassNotFoundException e) {
        throw new MojoExecutionException("Failed to validate configuration", e);
    }
}
 
Example #6
Source File: ModuleInfoUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the configured maven-compiler-plugin isn't too old in case 
 * there is a main module-info.java in the given project (has to be >= 3.6).
 * 
 * @param prj the project to be checked
 * @return <code>true</code> if there is no mofule-info file or if the m-c-p version is new enough (>= 3.6). Otherwise <code>false</code>
 */
public static boolean checkModuleInfoAndCompilerFit(Project prj) {
    NbMavenProject nbprj = prj.getLookup().lookup(NbMavenProject.class);
    if (nbprj == null) {
        return true;
    }
    
    if (!hasModuleInfo(nbprj)) {
        return true;
    }
    
    String version = PluginPropertyUtils.getPluginVersion(nbprj.getMavenProject(), Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER);
    if (version == null) {
        return true;
    }
    
    return new ComparableVersion(version).compareTo(new ComparableVersion(Constants.PLUGIN_COMPILER_VERSION_SUPPORTING_JDK9)) >= 0;
}
 
Example #7
Source File: JUnitOutputListenerProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean usingJUnit4(MavenProject prj) { // SUREFIRE-724
    for (Artifact a : prj.getArtifacts()) {
        if ("junit".equals(a.getGroupId()) && ("junit".equals(a.getArtifactId()) || "junit-dep".equals(a.getArtifactId()))) { //junit-dep  see #214238
            String version = a.getVersion();
            if (version != null && new ComparableVersion(version).compareTo(new ComparableVersion("4.8")) >= 0) {
                return true;
            }
        }
    }
    return false;
}
 
Example #8
Source File: InstallerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Messages("LBL_InstallerPanel=Installer")
@Override public ProjectCustomizer.Category createCategory(Lookup context) {
    Project project = context.lookup(Project.class);
    NbMavenProject watcher = project.getLookup().lookup(NbMavenProject.class);
    if (watcher != null && NbMavenProject.TYPE_NBM_APPLICATION.equalsIgnoreCase(watcher.getPackagingType())) {
        String version = PluginBackwardPropertyUtils.getPluginVersion(watcher.getMavenProject());
        if (version != null && new ComparableVersion(version).compareTo(new ComparableVersion("3.7-SNAPSHOT")) >= 0) {
            return ProjectCustomizer.Category.create("Installer", LBL_InstallerPanel(), null);
        }
    }
    return null;
}
 
Example #9
Source File: JavaOutputListenerProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private synchronized Boolean isJDK9CompilerVersion() {      
    if(jdk9compilerVersionOK == null) {
        String version = PluginPropertyUtils.getPluginVersion(config.getMavenProject(), Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER);
        jdk9compilerVersionOK = new ComparableVersion(version).compareTo(new ComparableVersion("3.6-SNAPSHOT")) >= 0 ? Boolean.TRUE : Boolean.FALSE;
    }
    return jdk9compilerVersionOK;
}
 
Example #10
Source File: ActionProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean usingJUnit4() { // SUREFIRE-724
    for (Artifact a : proj.getLookup().lookup(NbMavenProject.class).getMavenProject().getArtifacts()) {
        if ("junit".equals(a.getGroupId()) && ("junit".equals(a.getArtifactId()) || "junit-dep".equals(a.getArtifactId()))) { //junit-dep  see #214238
            String version = a.getVersion();
            if (version != null && new ComparableVersion(version).compareTo(new ComparableVersion("4.8")) >= 0) {
                return true;
            }
        }
    }
    return false;
}
 
Example #11
Source File: CurrentMavenVersion.java    From maven-color with MIT License 5 votes vote down vote up
private ComparableVersion readVersion(String buildConfig) {
    InputStream build = DefaultColorization.class.getResourceAsStream(buildConfig);
    if (build == null) {
        return new ComparableVersion("0");
    }

    Properties props = new Properties();
    try {
        props.load(build);
        return new ComparableVersion(props.getProperty("version", "0"));
    } catch (IOException e) {
        LOGGER.warn("Cannot read current Maven version from: {}.", buildConfig, e);
        return new ComparableVersion("0");
    }
}
 
Example #12
Source File: JUnitOutputListenerProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String getJUnitVersion(MavenProject prj) {
    String juVersion = "";
    for (Artifact a : prj.getArtifacts()) {
        if ("junit".equals(a.getGroupId()) && ("junit".equals(a.getArtifactId()) || "junit-dep".equals(a.getArtifactId()))) { //junit-dep  see #214238
            String version = a.getVersion();
            if (version != null && new ComparableVersion(version).compareTo(new ComparableVersion("4.8")) >= 0) {
                return "JUNIT4"; //NOI18N
            }
            if (version != null && new ComparableVersion(version).compareTo(new ComparableVersion("3.8")) >= 0) {
                return "JUNIT3"; //NOI18N
            }
        }
    }
    return juVersion;
}
 
Example #13
Source File: SpringBootAndCloudVersion.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
public SpringBootAndCloudVersion(String bootStartVersion,
		boolean statVersionInclusive, String bootEndVersion,
		boolean endVersionInclusive, String springCloudVersion) {
	this.bootEndVersion = bootEndVersion;
	this.comparableBootEndVersion = new ComparableVersion(bootEndVersion);
	this.endVersionInclusive = endVersionInclusive;
	this.bootStartVersion = bootStartVersion;
	this.comparableBootStartVersion = new ComparableVersion(bootStartVersion);
	this.startVersionInclusive = statVersionInclusive;
	this.springCloudVersion = springCloudVersion;
}
 
Example #14
Source File: VersionCommand.java    From gyro with Apache License 2.0 5 votes vote down vote up
public static ComparableVersion getCurrentVersion() throws IOException {
    try (InputStream stream = VersionCommand.class.getResourceAsStream("/gyro.properties")) {
        Properties properties = new Properties();
        properties.load(stream);
        return new ComparableVersion((String) properties.get("version"));
    }
}
 
Example #15
Source File: VersionCommand.java    From gyro with Apache License 2.0 5 votes vote down vote up
public static void printUpdateVersion() throws IOException {
    ComparableVersion currentVersion = VersionCommand.getCurrentVersion();
    ComparableVersion latestVersion = VersionCommand.getLatestVersion();

    if (latestVersion != null) {
        Boolean isUpdateAvailable = currentVersion.compareTo(latestVersion) < 0;
        if (isUpdateAvailable) {
            VersionCommand.renderUpdateMessage(latestVersion.toString(), getOsName());
        }
    }
}
 
Example #16
Source File: SpringBootAndCloudVersion.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
boolean matchesSpringBootVersion(ComparableVersion versionToCheck) {
	int startVersionComparison = comparableBootStartVersion.compareTo(versionToCheck);
	int endVersionComparison = versionToCheck.compareTo(comparableBootEndVersion);
	return ((startVersionInclusive && startVersionComparison == 0)
			|| startVersionComparison <= -1)
			&& ((endVersionInclusive && endVersionComparison == 0)
					|| endVersionComparison <= -1);
}
 
Example #17
Source File: Library.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static boolean newer(MavenCoordinates coordinates, MavenCoordinates previousCoordinates) {
  try {
    ComparableVersion version1 = new ComparableVersion(coordinates.getVersion());
    ComparableVersion version2 = new ComparableVersion(previousCoordinates.getVersion());
    
    return version1.compareTo(version2) > 0;
  } catch (IllegalArgumentException ex) {
    return false;
  }
}
 
Example #18
Source File: MavenVersionedArtifact.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public ComparableVersion getVersion ()
{
    return this.version;
}
 
Example #19
Source File: UnzipServlet.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Get a list of all relevant maven artifacts
 *
 * @param artifactsSupplier
 *            the supplier of artifacts
 * @param groupId
 *            the group id to filter for, must not be <code>null
 * @param artifactId
 *            the artifact id to filter for, must not be <code>null
 * @param snapshot
 *            whether to consider snapshot versions of not
 * @param versionFilter
 *            an optional version filter
 * @return a list of all matching artifacts wrapped in
 *         {@link MavenVersionedArtifact}, if there is a snapshot version
 *         present, then the snapshot version of used as version
 */
protected static List<MavenVersionedArtifact> getMavenArtifacts ( final String channelId, final Supplier<Collection<ArtifactInformation>> artifactsSupplier, final String groupId, final String artifactId, final boolean snapshot, final Predicate<ComparableVersion> versionFilter )
{
    final List<MavenVersionedArtifact> arts = new ArrayList<> ();

    for ( final ArtifactInformation ai : artifactsSupplier.get () )
    {
        if ( !isZip ( ai ) )
        {
            // if is is anot a zip, then this is not for the unzip plugin
            continue;
        }

        // fetch meta data

        final String mvnGroupId = ai.getMetaData ().get ( MK_GROUP_ID );
        final String mvnArtifactId = ai.getMetaData ().get ( MK_ARTIFACT_ID );

        final String classifier = ai.getMetaData ().get ( MK_CLASSIFIER );

        final String mvnVersion = ai.getMetaData ().get ( MK_VERSION );
        final String mvnSnapshotVersion = ai.getMetaData ().get ( MK_SNAPSHOT_VERSION );

        if ( mvnGroupId == null || mvnArtifactId == null || mvnVersion == null )
        {
            // no GAV information
            continue;
        }

        if ( classifier != null && !classifier.isEmpty () )
        {
            // no classifiers right now
            continue;
        }

        if ( !mvnGroupId.equals ( groupId ) || !mvnArtifactId.equals ( artifactId ) )
        {
            // wrong group or artifact id
            continue;
        }

        if ( !snapshot && ( mvnSnapshotVersion != null || mvnVersion.endsWith ( "-SNAPSHOT" ) ) )
        {
            // we are not looking for snapshots
            continue;
        }

        final ComparableVersion v = parseVersion ( mvnVersion );
        final ComparableVersion sv = parseVersion ( mvnSnapshotVersion );

        if ( v == null )
        {
            // unable to parse v
            continue;
        }

        if ( versionFilter == null )
        {
            // no filter, add it
            arts.add ( new MavenVersionedArtifact ( sv != null ? sv : v, channelId, ai ) );
        }
        else if ( versionFilter.test ( v ) )
        {
            // filter matched, add it
            arts.add ( new MavenVersionedArtifact ( sv != null ? sv : v, channelId, ai ) );
        }
        else if ( sv != null && versionFilter.test ( sv ) )
        {
            // we have a snapshot version and it matched, add it
            arts.add ( new MavenVersionedArtifact ( sv, channelId, ai ) );
        }
    }

    return arts;
}
 
Example #20
Source File: TemplateManagerImpl.java    From peer-os with Apache License 2.0 4 votes vote down vote up
@Override
public Set<Template> getTemplates()
{

    if ( isCacheUpToDate() )
    {
        return templatesCache;
    }

    lock.lock();

    try
    {
        //check again just in case
        if ( isCacheUpToDate() )
        {
            return templatesCache;
        }


        CloseableHttpClient client = getHttpsClient();
        try
        {
            HttpGet httpGet = new HttpGet( String.format( "https://%s/rest/v1/cdn/templates", Common.BAZAAR_IP ) );
            CloseableHttpResponse response = client.execute( httpGet );

            try
            {
                List<Template> freshTemplateList = Lists.newArrayList();

                String json = readContent( response );

                if ( !StringUtils.isBlank( json ) )
                {
                    Set<Template> templates = JsonUtil.fromJson( json, new TypeToken<Set<Template>>()
                    {
                    }.getType() );

                    freshTemplateList.addAll( templates );
                }


                if ( !CollectionUtil.isCollectionEmpty( freshTemplateList ) )
                {
                    lastTemplatesFetchTime = System.currentTimeMillis();

                    freshTemplateList.sort( ( o1, o2 ) -> {
                        ComparableVersion v1 = new ComparableVersion( o1.getVersion() );
                        ComparableVersion v2 = new ComparableVersion( o2.getVersion() );
                        return v2.compareTo( v1 );
                    } );

                    templatesCache.clear();

                    for ( Template template : freshTemplateList )
                    {
                        if ( template != null && !StringUtils.isBlank( template.getId() ) )
                        {
                            templatesCache.add( template );
                        }
                    }
                }
            }
            finally
            {
                close( response );
            }
        }
        catch ( Exception e )
        {
            LOG.error( "Error getting templates from CDN", e );

            lastTemplatesFetchErrorTime = System.currentTimeMillis();
        }
        finally
        {
            IOUtils.closeQuietly( client );
        }
    }
    finally
    {
        lock.unlock();
    }

    return templatesCache;
}
 
Example #21
Source File: MavenVersionedArtifact.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public MavenVersionedArtifact ( final ComparableVersion version, final String channelId, final ArtifactInformation artifact )
{
    this.version = version;
    this.channelId = channelId;
    this.artifact = artifact;
}
 
Example #22
Source File: ProcessVersionComparator.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int compare(AbstractProcess o1, AbstractProcess o2) {
    ComparableVersion v1 = new ComparableVersion(o1.getVersion());
    ComparableVersion v2 = new ComparableVersion(o2.getVersion());
    return v1.compareTo(v2);
}
 
Example #23
Source File: CurrentMavenVersion.java    From maven-color with MIT License 4 votes vote down vote up
public boolean isGreaterThanOrEqualTo(String version) {
    return this.version.compareTo(new ComparableVersion(version)) >= 0;
}
 
Example #24
Source File: CurrentMavenVersion.java    From maven-color with MIT License 4 votes vote down vote up
ComparableVersion get() {
    return version;
}
 
Example #25
Source File: CurrentMavenVersionTest.java    From maven-color with MIT License 4 votes vote down vote up
@Test
public void read_version_from_configuration_file() {
    ComparableVersion result = new CurrentMavenVersion("/version/1.0.properties").get();

    assertThat(result).isEqualTo(new ComparableVersion("1.0"));
}
 
Example #26
Source File: CurrentMavenVersionTest.java    From maven-color with MIT License 4 votes vote down vote up
@Test
public void return_version_0_when_version_is_missing() {
    ComparableVersion result = new CurrentMavenVersion("/version/no-version.properties").get();

    assertThat(result).isEqualTo(new ComparableVersion("0"));
}
 
Example #27
Source File: CurrentMavenVersionTest.java    From maven-color with MIT License 4 votes vote down vote up
@Test
public void return_version_0_when_build_config_cannot_be_read() {
    ComparableVersion result = new CurrentMavenVersion("/version/does-not-exist.properties").get();

    assertThat(result).isEqualTo(new ComparableVersion("0"));
}
 
Example #28
Source File: VersionComparator.java    From cloud-opensource-java with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(String version1, String version2) {
  return new ComparableVersion(version1).compareTo(new ComparableVersion(version2));
}
 
Example #29
Source File: MavenVersionHelper.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
public static int compareVersions(IString refVersion, IString version) {
	Comparable<ComparableVersion> ref = new ComparableVersion(refVersion.getValue());
	Comparable<ComparableVersion> ver = new ComparableVersion(version.getValue());
	
	return ref.compareTo((ComparableVersion) ver);
}
 
Example #30
Source File: SpringBootAndCloudVersion.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
boolean matchesSpringBootVersion(String versionToCheck) {
	return matchesSpringBootVersion(new ComparableVersion(versionToCheck));
}