org.jboss.forge.addon.dependencies.builder.CoordinateBuilder Java Examples

The following examples show how to use org.jboss.forge.addon.dependencies.builder.CoordinateBuilder. 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: RulesetsUpdater.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return Finds the latest non-SNAPSHOT of given artifact.
 */
public Coordinate getLatestReleaseOf(final CoordinateBuilder coord)
{
    List<Coordinate> availableVersions = depsResolver.resolveVersions(DependencyQueryBuilder.create(coord));

    // Find the latest non-SNAPSHOT and non-CR version.
    for(int i = availableVersions.size()-1; i >= 0; i--)
    {
        Coordinate availableCoord = availableVersions.get(i);
        String versionStr = availableCoord.getVersion();

        if(versionStr != null && !availableCoord.isSnapshot() && !versionStr.matches(".*CR[0-9]$"))
            return availableCoord;
    }
    return null;
}
 
Example #2
Source File: LuceneArchiveIdentificationService.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Coordinate getCoordinate(String sha1)
{
    return this.findSingle(DocTo.Fields.SHA1, sha1, new DocTo<Coordinate>()
    {
        public Coordinate convert(Document doc)
        {
            return CoordinateBuilder.create()
                .setGroupId(doc.get(GROUP_ID))
                .setArtifactId(doc.get(ARTIFACT_ID))
                .setVersion(doc.get(VERSION))
                .setClassifier(doc.get(CLASSIFIER))
                .setPackaging(doc.get(PACKAGING));
        }
    });
}
 
Example #3
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 #4
Source File: MavenHelpers.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static Coordinate createCoordinate(String groupId, String artifactId, String version, String packaging) {
    CoordinateBuilder builder = CoordinateBuilder.create()
            .setGroupId(groupId)
            .setArtifactId(artifactId);
    if (version != null) {
        builder = builder.setVersion(version);
    }
    if (packaging != null) {
        builder = builder.setPackaging(packaging);
    }

    return builder;
}
 
Example #5
Source File: RulesetsUpdater.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Connects to a repository and returns the version of the latest windup-distribution.
 */
public Coordinate queryLatestWindupRelease()
{
    final CoordinateBuilder coords = CoordinateBuilder.create()
            .setGroupId("org.jboss.windup")
            .setArtifactId("windup-distribution")
            .setClassifier("offline")
            .setPackaging("zip");
    Coordinate coord = this.getLatestReleaseOf(coords);
    return coord;
}
 
Example #6
Source File: RulesetsUpdater.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * A convenience method.
 * @return Finds the latest non-SNAPSHOT of given artifact.
 */
public Coordinate getLatestReleaseOf(String groupId, String artifactId)
{
    final CoordinateBuilder coord = CoordinateBuilder.create()
            .setGroupId(groupId)
            .setArtifactId(artifactId);
    return getLatestReleaseOf(coord);
}
 
Example #7
Source File: ArchiveCoordinateIdentificationTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAllButClassifier() throws IOException
{
    // org.freemarker:freemarker-core:3.1
    Assert.assertTrue(SkippedArchives.isSkipped(CoordinateBuilder.create("org.freemarker.foo:freemarker-core:3.1")));
    Assert.assertFalse(SkippedArchives.isSkipped(CoordinateBuilder.create("org.freemarker.foo:freemarker-core:3.1.1")));
    Assert.assertFalse(SkippedArchives.isSkipped(CoordinateBuilder.create("org.freemarker:freemarker-core:4.2.1")));
}
 
Example #8
Source File: ArchiveCoordinateIdentificationTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testVersionRangeAndArtifactIdSuffixPattern() throws IOException
{
    // org.hibernate.*:hibernate-core:[3.0,5.0)
    Assert.assertTrue(SkippedArchives.isSkipped(CoordinateBuilder.create("org.hibernate.foo:hibernate-core:3.2.1")));
    Assert.assertFalse(SkippedArchives.isSkipped(CoordinateBuilder.create("org.hibernate.foo:hibernate-core:1.2.3")));
    Assert.assertTrue(SkippedArchives.isSkipped(CoordinateBuilder.create("org.hibernate.foo:hibernate-core:4.2.1")));
    Assert.assertFalse(SkippedArchives.isSkipped(CoordinateBuilder.create("org.hibernate.foo:hibernate-core:5.0")));
    Assert.assertFalse(SkippedArchives.isSkipped(CoordinateBuilder.create("org.hibernate.foo:hibernate-core:5.2.5-SNAPSHOT")));
}
 
Example #9
Source File: ArchiveCoordinateIdentificationTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGroupIdSuffixWithVersionAndClassifierWildcard() throws IOException
{
    // org.jboss.bar:bar-*:*:*
    Assert.assertTrue(SkippedArchives.isSkipped(CoordinateBuilder.create("org.jboss.bar:bar-foo:1.2.3")));
    Assert.assertFalse(SkippedArchives.isSkipped(CoordinateBuilder.create("org.jboss.bar:just-foo:1.2.3")));

}
 
Example #10
Source File: ArchiveCoordinateIdentificationTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testArtifactIdSuffixWithWildcards() throws IOException
{
    // org.jboss.windup.*:*:*
    Assert.assertTrue(SkippedArchives.isSkipped(CoordinateBuilder.create("org.jboss.windup:windup-foo:1.2.3")));
    // org.apache.commons.*:*:*
    Assert.assertTrue(SkippedArchives.isSkipped(CoordinateBuilder.create("org.apache.commons.foo:commons-foo:1.2.3")));
}
 
Example #11
Source File: IdentifyArchivesRulesetTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Run initial Windup rules against the JEE sample app, add a single identification record, and check if the lib is identified.
 */
@Test
public void testJarsAreIdentified() throws Exception
{
    try (GraphContext graphContext = contextFactory.create(true))
    {
        FileUtils.deleteDirectory(OUTPUT_PATH.toFile());

        InMemoryArchiveIdentificationService inMemoryIdentifier = new InMemoryArchiveIdentificationService();
        inMemoryIdentifier.addMapping("4bf32b10f459a4ecd4df234ae2ccb32b9d9ba9b7", LOG4J_COORDINATE);
        identifier.addIdentifier(inMemoryIdentifier);

        WindupConfiguration wc = new WindupConfiguration();
        wc.setGraphContext(graphContext);
        wc.addInputPath(INPUT_PATH);
        wc.setOutputDirectory(OUTPUT_PATH);
        wc.setOptionValue(OverwriteOption.NAME, true);
        wc.setRuleProviderFilter(new NotPredicate(
                    new RuleProviderPhasePredicate(ArchiveExtractionPhase.class, DecompilationPhase.class, MigrationRulesPhase.class,
                                ReportGenerationPhase.class, ReportRenderingPhase.class)
                    ));

        processor.execute(wc);

        GraphService<IdentifiedArchiveModel> archiveService = new GraphService<>(graphContext, IdentifiedArchiveModel.class);
        Iterable<IdentifiedArchiveModel> archives = archiveService.findAllByProperty(IdentifiedArchiveModel.FILE_NAME, "log4j-1.2.6.jar");
        for (IdentifiedArchiveModel archive : archives)
        {
            ArchiveCoordinateModel archiveCoordinate = archive.getCoordinate();
            Assert.assertNotNull(archiveCoordinate);

            final Coordinate expected = CoordinateBuilder.create(LOG4J_COORDINATE);
            Assert.assertEquals(expected, CoordinateBuilder.create()
                        .setGroupId(archiveCoordinate.getGroupId())
                        .setArtifactId(archiveCoordinate.getArtifactId())
                        .setClassifier(archiveCoordinate.getClassifier())
                        .setVersion(archiveCoordinate.getVersion()));
        }
    }
}
 
Example #12
Source File: SkippedArchives.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isSkipped(ArchiveCoordinateModel coordinate)
{
    return isSkipped(CoordinateBuilder.create()
                .setArtifactId(coordinate.getArtifactId())
                .setGroupId(coordinate.getGroupId())
                .setClassifier(coordinate.getClassifier())
                .setVersion(coordinate.getVersion()));
}
 
Example #13
Source File: InMemoryArchiveIdentificationService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Coordinate getCoordinate(String checksum)
{
    if (checksum == null)
        return null;

    String coordinate = map.get(checksum);

    if (coordinate == null)
        return null;

    return CoordinateBuilder.create(coordinate);
}
 
Example #14
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected Coordinate createCoordinate(String groupId, String artifactId, String version) {
    CoordinateBuilder builder = CoordinateBuilder.create()
            .setGroupId(groupId)
            .setArtifactId(artifactId);
    if (version != null) {
        builder = builder.setVersion(version);
    }

    return builder;
}
 
Example #15
Source File: FabricArchetypeCatalogFactory.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public ArchetypeCatalog getArchetypeCatalog() {
    if (cachedArchetypes == null) {
        String version = VersionHelper.fabric8ArchetypesVersion();

        Coordinate coordinate = CoordinateBuilder.create()
                .setGroupId("io.fabric8.archetypes")
                .setArtifactId("archetypes-catalog")
                .setVersion(version)
                .setPackaging("jar");

        // load the archetype-catalog.xml from inside the JAR
        Dependency dependency = resolver.get().resolveArtifact(DependencyQueryBuilder.create(coordinate));
        if (dependency != null) {
            try {
                String name = dependency.getArtifact().getFullyQualifiedName();
                URL url = new URL("file", null, name);
                URLClassLoader loader = new URLClassLoader(new URL[]{url});
                InputStream is = loader.getResourceAsStream("archetype-catalog.xml");
                if (is != null) {
                    cachedArchetypes = new ArchetypeCatalogXpp3Reader().read(is);
                }
            } catch (Exception e) {
                LOG.log(Level.WARNING, "Error while retrieving archetypes due " + e.getMessage(), e);
            }
        }
    }
    return cachedArchetypes;
}
 
Example #16
Source File: AbstractFabricProjectCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected Coordinate createCoordinate(String groupId, String artifactId, String version, String packaging) {
    CoordinateBuilder builder = CoordinateBuilder.create()
            .setGroupId(groupId)
            .setArtifactId(artifactId);
    if (version != null) {
        builder = builder.setVersion(version);
    }
    if (packaging != null) {
        builder = builder.setPackaging(packaging);
    }

    return builder;
}
 
Example #17
Source File: IgnoreArchivesRulesetTest.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testSkippedArchivesFound() throws Exception
{
    try (GraphContext graphContext = contextFactory.create(true))
    {
        FileUtils.deleteDirectory(OUTPUT_PATH.toFile());

        InMemoryArchiveIdentificationService inMemoryIdentifier = new InMemoryArchiveIdentificationService();
        inMemoryIdentifier.addMapping("4bf32b10f459a4ecd4df234ae2ccb32b9d9ba9b7", LOG4J_COORDINATE);

        InMemoryArchiveIdentificationService identificationService = new InMemoryArchiveIdentificationService();
        identificationService.addMappingsFrom(new File("src/test/resources/testArchiveMapping.txt"));

        identifier.addIdentifier(inMemoryIdentifier);
        identifier.addIdentifier(identificationService);

        SkippedArchives.add("log4j:*:*");

        WindupConfiguration config = new WindupConfiguration();
        config.setGraphContext(graphContext);
        config.addInputPath(INPUT_PATH);
        config.setOutputDirectory(OUTPUT_PATH);
        config.setOptionValue(OverwriteOption.NAME, true);
        config.setRuleProviderFilter(new NotPredicate(
                    new RuleProviderPhasePredicate(DecompilationPhase.class, MigrationRulesPhase.class, ReportGenerationPhase.class,
                                ReportRenderingPhase.class)
                    ));

        processor.execute(config);

        GraphService<IgnoredArchiveModel> archiveService = new GraphService<>(graphContext, IgnoredArchiveModel.class);
        Iterable<IgnoredArchiveModel> archives = archiveService.findAllByProperty(IgnoredArchiveModel.FILE_NAME, "log4j-1.2.6.jar");
        Assert.assertTrue(archives.iterator().hasNext());
        for (IgnoredArchiveModel archive : archives)
        {
            if (archive.isDirectory())
                continue;
            Assert.assertNotNull(archive);
            Assert.assertTrue(archive instanceof IdentifiedArchiveModel);
            ArchiveCoordinateModel archiveCoordinate = ((IdentifiedArchiveModel) archive).getCoordinate();
            Assert.assertNotNull(archiveCoordinate);

            final Coordinate expected = CoordinateBuilder.create(LOG4J_COORDINATE);
            final CoordinateBuilder actual = CoordinateBuilder.create()
                        .setGroupId(archiveCoordinate.getGroupId())
                        .setArtifactId(archiveCoordinate.getArtifactId())
                        .setPackaging(archiveCoordinate.getPackaging())
                        .setClassifier(archiveCoordinate.getClassifier())
                        .setVersion(archiveCoordinate.getVersion());

            Assert.assertEquals(expected.toString(), actual.toString());
        }
    }
}
 
Example #18
Source File: SkippedArchives.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
public CoordinateBuilder getCoordinate()
{
    return coordinate;
}
 
Example #19
Source File: SkippedArchives.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
public CoordinatePattern(CoordinateBuilder coordinate, VersionRange version)
{
    this.coordinate = coordinate;
    this.version = version;
}
 
Example #20
Source File: ArchiveCoordinateIdentificationTest.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testUnlistedArchivesAreNotSkipped() throws IOException
{
    Assert.assertFalse(SkippedArchives.isSkipped(CoordinateBuilder.create("com.example.foo:example-foo:1.2.3")));
}
 
Example #21
Source File: DistributionUpdater.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Downloads the given artifact, extracts it and replaces current Windup directory (as given by PathUtil)
 * with the content from the artifact (assuming it really is a Windup distribution zip).
 */
public void replaceWindupDirectoryWithDistribution(Coordinate distCoordinate)
        throws WindupException
{
    try
    {
        final CoordinateBuilder coord = CoordinateBuilder.create(distCoordinate);
        File tempFolder = OperatingSystemUtils.createTempDir();
        this.updater.extractArtifact(coord, tempFolder);

        File newDistWindupDir = getWindupDistributionSubdir(tempFolder);

        if (null == newDistWindupDir)
            throw new WindupException("Distribution update failed: "
                + "The distribution archive did not contain the windup-distribution-* directory: " + coord.toString());


        Path addonsDir = PathUtil.getWindupAddonsDir();
        Path binDir = PathUtil.getWindupHome().resolve(PathUtil.BINARY_DIRECTORY_NAME);
        Path libDir = PathUtil.getWindupHome().resolve(PathUtil.LIBRARY_DIRECTORY_NAME);

        FileUtils.deleteDirectory(addonsDir.toFile());
        FileUtils.deleteDirectory(libDir.toFile());
        FileUtils.deleteDirectory(binDir.toFile());

        FileUtils.moveDirectory(new File(newDistWindupDir, PathUtil.ADDONS_DIRECTORY_NAME), addonsDir.toFile());
        FileUtils.moveDirectory(new File(newDistWindupDir, PathUtil.BINARY_DIRECTORY_NAME), binDir.toFile());
        FileUtils.moveDirectory(new File(newDistWindupDir, PathUtil.LIBRARY_DIRECTORY_NAME), libDir.toFile());

        // Rulesets
        Path rulesDir = PathUtil.getWindupHome().resolve(PathUtil.RULES_DIRECTORY_NAME); //PathUtil.getWindupRulesDir();
        File coreDir = rulesDir.resolve(RulesetsUpdater.RULESET_CORE_DIRECTORY).toFile();

        // This is for testing purposes. The releases do not contain migration-core/ .
        if (coreDir.exists())
        {
            // migration-core/ exists -> Only replace that one.
            FileUtils.deleteDirectory(coreDir);
            final File coreDirNew = newDistWindupDir.toPath().resolve(PathUtil.RULES_DIRECTORY_NAME).resolve(RulesetsUpdater.RULESET_CORE_DIRECTORY).toFile();
            FileUtils.moveDirectory(coreDirNew, rulesDir.resolve(RulesetsUpdater.RULESET_CORE_DIRECTORY).toFile());
        }
        else
        {
            // Otherwise replace the whole rules directory (backing up the old one).
            final String newName = "rules-" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
            FileUtils.moveDirectory(rulesDir.toFile(), rulesDir.getParent().resolve(newName).toFile());
            FileUtils.moveDirectory(new File(newDistWindupDir, PathUtil.RULES_DIRECTORY_NAME), rulesDir.toFile());
        }

        FileUtils.deleteDirectory(tempFolder);
    }
    catch (IllegalStateException | DependencyException | IOException ex)
    {
        throw new WindupException("Distribution update failed: " + ex.getMessage(), ex);
    }
}
 
Example #22
Source File: WindupUpdateDistributionCommandTest.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
@Test
@Ignore("The current implementation doesn't work as it tampers with addons loaded at the time."
            + " Even if it replaced all Windup addons, it would still fail on Windows as they keep the .jar's locked.")
public void testUpdateDistribution() throws Exception
{
    // Download and unzip an old distribution.
    final CoordinateBuilder coords = CoordinateBuilder.create()
                .setGroupId("org.jboss.windup")
                .setArtifactId("windup-distribution")
                .setClassifier("offline")
                .setVersion("2.2.0.Final")
                .setPackaging("zip");
    System.out.println("Downloading " + coords + ", may take a while.");
    List<Coordinate> results = resolver.resolveVersions(DependencyQueryBuilder.create(coords));

    File windupDir = OperatingSystemUtils.createTempDir();
    this.updater.extractArtifact(results.get(0), windupDir);
    windupDir = DistributionUpdater.getWindupDistributionSubdir(windupDir);
    Assert.assertTrue(windupDir.exists());
    System.setProperty(PathUtil.WINDUP_HOME, windupDir.getAbsolutePath());

    // Run the upgrader.
    distUpdater.replaceWindupDirectoryWithLatestDistribution();

    // Check the new version.
    String newUiVersion = getInstalledAddonVersion(windupDir.toPath().resolve("addons").toString(), WINDUP_UI_ADDON_NAME);
    Assert.assertTrue(SingleVersion.valueOf(newUiVersion).compareTo(SingleVersion.valueOf("2.2.0.Final")) > 0);

    // Try to run Windup from there.
    // TODO: I need to set the harness addons directory to the freshly created dir.
    UITestHarness harness = furnace.getAddonRegistry().getServices(UITestHarness.class).get();
    try (CommandController controller = harness.createCommandController(WindupCommand.class))
    {
        controller.initialize();
        controller.setValueFor(InputPathOption.NAME, Collections.singletonList(new File("src/test/resources/test.jar").getAbsolutePath()));
        final File resultDir = new File("target/testRunFromUpgraded");
        resultDir.mkdirs();
        controller.setValueFor(OutputPathOption.NAME, resultDir.getAbsolutePath());

        Result result = controller.execute();
        Assert.assertTrue(result.getMessage(), !(result instanceof Failed));
    }
    catch (Throwable ex)
    {
        throw new WindupException("Failed running Windup from the upgraded directory: " + ex.getMessage(), ex);
    }
}