org.jboss.forge.furnace.versions.Versions Java Examples

The following examples show how to use org.jboss.forge.furnace.versions.Versions. 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: AddonRepositoryStateStrategyImpl.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public List<AddonId> listEnabledCompatibleWithVersion(final Version version)
{
   return lock.performLocked(LockMode.READ, new Callable<List<AddonId>>()
   {
      @Override
      public List<AddonId> call() throws Exception
      {
         List<AddonId> list = listAll();
         List<AddonId> result = new ArrayList<>();
         for (AddonId entry : list)
         {
            if (version == null || entry.getApiVersion() == null
                     || Versions.isApiCompatible(version, entry.getApiVersion()))
            {
               result.add(entry);
            }
         }
         return result;
      }
   });
}
 
Example #2
Source File: SkippedArchives.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
static CoordinatePattern fromCoordinatePattern(String coordinates)
{
    String[] parts = coordinates.split("\\s*:\\s*");
    if (parts.length < 3)
        throw new IllegalArgumentException("Expected GAV definition format is 'GROUP_ID:ARTIFACT_ID:VERSION_OR_RANGE[:CLASSIFIER]', was: "
                    + coordinates);

    CoordinateBuilder coordinate = CoordinateBuilder.create()
                .setGroupId(parts[0])
                .setArtifactId(parts[1]);

    VersionRange version = null;

    if (parts[2].equals("*"))
        version = new EmptyVersionRange();
    //  Range - (1.0,2.0]  or [1.0,2.0) etc.
    else if (parts[2].matches("^(\\[|\\()[^,]+(,[^,]+)?(\\]|\\))$"))
        version = Versions.parseMultipleVersionRange(parts[2]);
    else
        version = new SingleVersionRange(new SingleVersion(parts[2]));

    if (parts.length >= 4)
        coordinate.setClassifier(parts[3]);

    return new CoordinatePattern(coordinate, version);
}
 
Example #3
Source File: MetadataTechnologyHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public TechnologyReference processElement(ParserContext handlerManager, Element element) throws ConfigurationException
{
    String id = element.getAttribute(ID);
    String versionRangeString = element.getAttribute(VERSION_RANGE);
    if (StringUtils.isBlank(id))
    {
        throw new WindupXMLRulesetParsingException("The '" + element.getTagName() + "' element must have a non-empty '" + ID + "' attribute");
    }
    VersionRange versionRange = null;
    if (StringUtils.isNotBlank(versionRangeString))
    {
        try
        {
            versionRange = Versions.parseVersionRange(versionRangeString);
        }
        catch (VersionException ex)
        {
            throw new WindupXMLRulesetParsingException("The '" + VERSION_RANGE + "' attribute with value \"" + versionRangeString
                        + "\" in the element "
                        + element.getTagName() + " is not a valid version", ex);
        }
    }

    return new TechnologyReference(id, versionRange);
}
 
Example #4
Source File: TechnologyReferenceTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testVersionPartialOverlapAcrossMax()
{
    VersionRange versionRange1 = Versions.parseVersionRange("(10,20)");
    VersionRange versionRange2 = Versions.parseVersionRange("(18,22)");
    TechnologyReference technologyReference = new TechnologyReference("tech", versionRange1);

    boolean overlap = technologyReference.versionRangesOverlap(versionRange2);
    Assert.assertTrue(overlap);
}
 
Example #5
Source File: TechnologyReferenceTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testVersionRangeIntersectionSimpleNoOverlap()
{
    VersionRange versionRange1 = Versions.parseVersionRange("(10,20)");
    VersionRange versionRange2 = Versions.parseVersionRange("(8,9]");
    TechnologyReference technologyReference = new TechnologyReference("tech", versionRange1);

    boolean overlap = technologyReference.versionRangesOverlap(versionRange2);
    Assert.assertFalse(overlap);
}
 
Example #6
Source File: TechnologyReferenceTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testVersionRangeIntersectionSingleVersionInclusiveBegin()
{
    VersionRange versionRange1 = Versions.parseVersionRange("[10]");
    VersionRange versionRange2 = Versions.parseVersionRange("[10,17]");
    TechnologyReference technologyReference = new TechnologyReference("tech", versionRange1);

    boolean overlap = technologyReference.versionRangesOverlap(versionRange2);
    Assert.assertTrue(overlap);
}
 
Example #7
Source File: TechnologyReferenceTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testVersionRangeIntersectionSingleVersionExclusiveBegin()
{
    VersionRange versionRange1 = Versions.parseVersionRange("[10]");
    VersionRange versionRange2 = Versions.parseVersionRange("(10,17]");
    TechnologyReference technologyReference = new TechnologyReference("tech", versionRange1);

    boolean overlap = technologyReference.versionRangesOverlap(versionRange2);
    Assert.assertFalse(overlap);
}
 
Example #8
Source File: TechnologyReferenceTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testVersionRangeIntersectionSimpleExclusiveBegin()
{
    VersionRange versionRange1 = Versions.parseVersionRange("[10,20)");
    VersionRange versionRange2 = Versions.parseVersionRange("[10,17]");
    TechnologyReference technologyReference = new TechnologyReference("tech", versionRange1);

    boolean overlap = technologyReference.versionRangesOverlap(versionRange2);
    Assert.assertTrue(overlap);
}
 
Example #9
Source File: TechnologyReferenceTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testVersionRangeIntersectionSimple()
{
    VersionRange versionRange1 = Versions.parseVersionRange("(10,20)");
    VersionRange versionRange2 = Versions.parseVersionRange("(12,17]");
    TechnologyReference technologyReference = new TechnologyReference("tech", versionRange1);

    boolean overlap = technologyReference.versionRangesOverlap(versionRange2);
    Assert.assertTrue(overlap);
}
 
Example #10
Source File: TechnologyReference.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Parses a {@link TechnologyReference} from a string that is formatted as either
 * "id" or "id:versionRange".
 */
public static TechnologyReference parseFromIDAndVersion(String idAndVersion)
{
    if (idAndVersion.contains(":"))
    {
        String tech = StringUtils.substringBefore(idAndVersion, ":");
        String versionRangeString = StringUtils.substringAfter(idAndVersion, ":");
        if (!versionRangeString.matches("^[(\\[].*[)\\]]"))
            versionRangeString = "[" + versionRangeString + "]";

        VersionRange versionRange = Versions.parseVersionRange(versionRangeString);
        return new TechnologyReference(tech, versionRange);
    }
    return new TechnologyReference(idAndVersion);
}
 
Example #11
Source File: TechnologyReference.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Construct a new {@link TechnologyReference} using the given {@link String} ID and {@link String} version range.
 */
public TechnologyReference(String id, String versionRange)
{
    this.id = id;
    if (versionRange != null)
        this.versionRange = Versions.parseVersionRange(versionRange);
}
 
Example #12
Source File: TechnologyReferenceTransformerHandlerTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testXmlParsinfOfRulesetMetadata() throws Exception
{
    File fXmlFile = new File(XML_FILE);
    RuleLoaderContext loaderContext = new RuleLoaderContext(Collections.singleton(fXmlFile.toPath()), null);
    ParserContext parser = new ParserContext(furnace, loaderContext);
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    dbFactory.setNamespaceAware(true);
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document firstXmlFile = dBuilder.parse(fXmlFile);
    List<TechnologyReferenceTransformer> transformers = parser.processElement(firstXmlFile.getDocumentElement());

    // verify xmlfile
    Assert.assertEquals(2, transformers.size());
    Assert.assertEquals("sampleinput1", transformers.get(0).getOriginal().getId());
    Assert.assertEquals("[1]", transformers.get(0).getOriginal().getVersionRange().toString());
    Assert.assertEquals("sampleoutput2", transformers.get(0).getTarget().getId());
    Assert.assertEquals("[2]", transformers.get(0).getTarget().getVersionRange().toString());

    TechnologyReference input1 = new TechnologyReference("sampleinput1", Versions.parseVersionRange("[1]"));
    TechnologyReference output2 = transformers.get(0).transform(input1);
    Assert.assertEquals("sampleoutput2", output2.getId());
    Assert.assertEquals("[2]", output2.getVersionRange().toString());

    Assert.assertEquals("sampleinput3", transformers.get(1).getOriginal().getId());
    Assert.assertEquals("[3]", transformers.get(1).getOriginal().getVersionRange().toString());
    Assert.assertEquals("sampleoutput4", transformers.get(1).getTarget().getId());
    Assert.assertEquals("[4]", transformers.get(1).getTarget().getVersionRange().toString());
}
 
Example #13
Source File: AddonRepositoryStorageStrategyImpl.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Set<AddonDependencyEntry> getAddonDependencies(final AddonId addon)
{
   return lock.performLocked(LockMode.READ, new Callable<Set<AddonDependencyEntry>>()
   {
      @Override
      public Set<AddonDependencyEntry> call() throws Exception
      {
         Set<AddonDependencyEntry> result = new LinkedHashSet<AddonDependencyEntry>();
         File descriptor = getAddonDescriptor(addon);

         try
         {
            Node installed = getXmlRoot(descriptor);

            List<Node> children = installed.get("dependencies/dependency");
            for (final Node child : children)
            {
               if (child != null)
               {
                  result.add(AddonDependencyEntry.create(
                           child.getAttribute(ATTR_NAME),
                           Versions.parseMultipleVersionRange(child.getAttribute(ATTR_VERSION)),
                           Boolean.valueOf(child.getAttribute(ATTR_EXPORT)),
                           Boolean.valueOf(child.getAttribute(ATTR_OPTIONAL))));
               }
            }
         }
         catch (FileNotFoundException e)
         {
            // already removed
         }

         return result;
      }
   });
}
 
Example #14
Source File: TechnologyReferenceTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testVersionPartialOverlapAcrossMaxReverse()
{
    VersionRange versionRange1 = Versions.parseVersionRange("(10,20)");
    VersionRange versionRange2 = Versions.parseVersionRange("(18,22)");
    TechnologyReference technologyReference = new TechnologyReference("tech", versionRange2);

    boolean overlap = technologyReference.versionRangesOverlap(versionRange1);
    Assert.assertTrue(overlap);
}
 
Example #15
Source File: AddonRepositoryImpl.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
public static Version getRuntimeAPIVersion()
{
   String versionOverride = System.getProperty("furnace.version.override");
   if (versionOverride != null)
   {
      return SingleVersion.valueOf(versionOverride);
   }
   return Versions.getImplementationVersionFor(AddonRepository.class);
}
 
Example #16
Source File: TechnologyReferenceTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testVersionPartialOverlapAcrossMin()
{
    VersionRange versionRange1 = Versions.parseVersionRange("(10,20)");
    VersionRange versionRange2 = Versions.parseVersionRange("(7,13)");
    TechnologyReference technologyReference = new TechnologyReference("tech", versionRange1);

    boolean overlap = technologyReference.versionRangesOverlap(versionRange2);
    Assert.assertTrue(overlap);
}
 
Example #17
Source File: TechnologyReferenceTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testVersionPartialOverlapAcrossMinReverse()
{
    VersionRange versionRange1 = Versions.parseVersionRange("(10,20)");
    VersionRange versionRange2 = Versions.parseVersionRange("(7,13)");
    TechnologyReference technologyReference = new TechnologyReference("tech", versionRange1);

    boolean overlap = technologyReference.versionRangesOverlap(versionRange2);
    Assert.assertTrue(overlap);
}
 
Example #18
Source File: MetadataTestRulesetMetadata.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Set<TechnologyReference> getSourceTechnologies()
{
    return new HashSet<>(Arrays.asList(
                new TechnologyReference("source-a", Versions.parseVersionRange("[1,]")),
                new TechnologyReference("source-b", Versions.parseVersionRange("[2,]"))
                ));
}
 
Example #19
Source File: MetadataTestRulesetMetadata.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Set<TechnologyReference> getTargetTechnologies()
{
    return new HashSet<>(Arrays.asList(
                new TechnologyReference("target-x", Versions.parseVersionRange("[3,]"))
                ));
}
 
Example #20
Source File: ThorntailFacet.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
private String getWildflySwarmVersion()
{
   return Versions.getImplementationVersionFor(FractionList.class).toString();
}
 
Example #21
Source File: InstallAddonCommand.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
void install(String coordinates, boolean batchMode)
{
    Version runtimeAPIVersion = AddonRepositoryImpl.getRuntimeAPIVersion();
    try
    {
        AddonDependencyResolver resolver = new MavenAddonDependencyResolver();
        AddonManagerImpl addonManager = new AddonManagerImpl(furnace, resolver);

        AddonId addonId;

        coordinates = convertColonVersionToComma(coordinates);

        // This allows windup --install maven
        if (coordinates.matches(artifactWithCommaVersionPattern))
        {
            addonId = AddonId.fromCoordinates(coordinates);
        }
        else if (coordinates.matches(artifactPattern))
        {
            AddonId[] versions = resolver.resolveVersions(coordinates).get();
            String coordinate = coordinates;

            if (versions.length == 0)
            {
                throw new IllegalArgumentException("No Artifact version found for " + coordinate);
            }
            else
            {
                AddonId selected = null;
                for (int i = versions.length - 1; selected == null && i >= 0; i--)
                {
                    String apiVersion = resolver.resolveAPIVersion(versions[i]).get();
                    if (apiVersion != null
                                && Versions.isApiCompatible(runtimeAPIVersion, SingleVersion.valueOf(apiVersion)))
                    {
                        selected = versions[i];
                    }
                }
                if (selected == null)
                {
                    throw new IllegalArgumentException("No compatible addon API version found for " + coordinate
                                + " for API " + runtimeAPIVersion);
                }

                addonId = selected;
            }
        }
        else
        {
            throw new IllegalArgumentException("Unrecognized format: " + coordinates + ", format must match: GROUP_ID:ARTIFACT_ID:VERSION");
        }

        AddonActionRequest request = addonManager.install(addonId);
        System.out.println(request);
        if (!batchMode)
        {
            String result = System.console().readLine("Confirm installation [Y/n]? ");
            if ("n".equalsIgnoreCase(result.trim()))
            {
                System.out.println("Installation aborted.");
                return;
            }
        }
        request.perform();
        System.out.println("Installation completed successfully.");
        System.out.println();
    }
    catch (Exception e)
    {
        e.printStackTrace();
        System.out.println("> Forge version [" + runtimeAPIVersion + "]");
    }
}
 
Example #22
Source File: AddonRepositoryImpl.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isApiCompatible(Version runtimeVersion, AddonId entry)
{
   Assert.notNull(entry, "Addon entry must not be null.");

   return Versions.isApiCompatible(runtimeVersion, entry.getApiVersion());
}
 
Example #23
Source File: AddonManagerImpl.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Calculate the necessary request based in the list of installed addons for a given {@link MutableAddonRepository}
 *
 * @param addonInfo
 * @param repository
 * @param installedAddons
 * @return
 */
private AddonActionRequest createRequest(final AddonInfo requestedAddonInfo, final AddonInfo addonInfo,
         final MutableAddonRepository repository,
         final Map<AddonId, AddonRepository> installedAddons)
{
   final AddonActionRequest request;
   AddonId addon = addonInfo.getAddon();
   if (installedAddons.containsKey(addon))
   {
      // Already contains the installed addon. Update ONLY if the version is SNAPSHOT and if it is the requested
      // addon
      if (Versions.isSnapshot(addon.getVersion()) && addonInfo.equals(requestedAddonInfo))
      {
         AddonRepository addonRepository = installedAddons.get(addon);
         if (repository.equals(addonRepository))
         {
            request = createUpdateRequest(addonInfo, addonInfo, repository, furnace);
         }
         else
         {
            request = createDeployRequest(addonInfo, repository, furnace);
         }
      }
      else
      {
         request = null;
      }
   }
   else
   {
      // Addon is not installed or has a different version
      Entry<AddonId, AddonRepository> differentVersionEntry = null;
      for (Entry<AddonId, AddonRepository> addonEntry : installedAddons.entrySet())
      {
         AddonId addonId = addonEntry.getKey();
         if (addonId.getName().equals(addon.getName()))
         {
            differentVersionEntry = addonEntry;
            break;
         }
      }
      if (differentVersionEntry != null)
      {
         // Avoiding ClassCastExceptions
         Version differentVersion = SingleVersion.valueOf(differentVersionEntry.getKey().getVersion().toString());
         Version addonVersion = SingleVersion.valueOf(addon.getVersion().toString());
         // TODO: Review condition below
         // Update ONLY if it is the requested addon
         if (differentVersion.compareTo(addonVersion) < 0 && addonInfo.equals(requestedAddonInfo))
         {
            if (repository.equals(differentVersionEntry.getValue()))
            {
               request = createUpdateRequest(info(differentVersionEntry.getKey()), addonInfo, repository, furnace);
            }
            else
            {
               request = createDeployRequest(addonInfo, repository, furnace);
            }
         }
         else
         {
            // No update needed. Don't do anything with it
            request = null;
         }
      }
      else
      {
         request = createDeployRequest(addonInfo, repository, furnace);
      }
   }
   return request;
}
 
Example #24
Source File: MavenAddonDependencyResolver.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Response<AddonId[]> resolveVersions(final String addonName)
{
   String addonNameSplit;
   String version;

   String[] split = addonName.split(",");
   if (split.length == 2)
   {
      addonNameSplit = split[0];
      version = split[1];
   }
   else
   {
      addonNameSplit = addonName;
      version = null;
   }
   RepositorySystem system = container.getRepositorySystem();
   Settings settings = getSettings();
   DefaultRepositorySystemSession session = container.setupRepoSession(system, settings);
   List<RemoteRepository> repositories = MavenRepositories.getRemoteRepositories(container, settings);
   VersionRangeResult versions = getVersions(system, settings, session, repositories, addonNameSplit, version);
   List<Exception> exceptions = versions.getExceptions();
   List<Version> versionsList = versions.getVersions();
   List<AddonId> addons = new ArrayList<AddonId>();
   List<AddonId> snapshots = new ArrayList<AddonId>();
   for (Version artifactVersion : versionsList)
   {
      AddonId addonId = AddonId.from(addonName, artifactVersion.toString());
      if (Versions.isSnapshot(addonId.getVersion()))
      {
         snapshots.add(addonId);
      }
      else
      {
         addons.add(addonId);
      }
   }
   if (addons.isEmpty())
   {
      addons = snapshots;
   }
   return new MavenResponseBuilder<AddonId[]>(addons.toArray(new AddonId[addons.size()])).setExceptions(exceptions);
}
 
Example #25
Source File: AddonDependencyEntry.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create a new {@link AddonDependencyEntry} with the given attributes.
 */
public static AddonDependencyEntry create(String name, String versionRange, boolean exported, boolean optional)
{
   return create(name, Versions.parseMultipleVersionRange(versionRange), exported, optional);
}
 
Example #26
Source File: AddonDependencyEntry.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create a new {@link AddonDependencyEntry} with the given attributes.
 */
public static AddonDependencyEntry create(String name, String versionRange, boolean exported)
{
   return create(name, Versions.parseMultipleVersionRange(versionRange), exported, false);
}
 
Example #27
Source File: AddonDependencyEntry.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create a new {@link AddonDependencyEntry} with the given attributes.
 */
public static AddonDependencyEntry create(String name, String versionRange)
{
   return create(name, Versions.parseMultipleVersionRange(versionRange), false, false);
}