org.jboss.forge.addon.dependencies.Coordinate Java Examples

The following examples show how to use org.jboss.forge.addon.dependencies.Coordinate. 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: WindupUpdateDistributionCommand.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception
{
    if (!context.getPrompt().promptBoolean(
        "Are you sure you want to continue? This command will delete current directories: addons, bin, lib, rules/migration-core"))
    {
        return Results.fail("Updating distribution was aborted.");
    }

    // Find the latest version.
    Coordinate latestDist = this.updater.getLatestReleaseOf("org.jboss.windup", "windup-distribution");
    Version latestVersion = SingleVersion.valueOf(latestDist.getVersion());
    Version installedVersion = currentAddon.getId().getVersion();
    if (latestVersion.compareTo(installedVersion) <= 0)
    {
        return Results.fail(Util.WINDUP_BRAND_NAME_ACRONYM+" CLI is already in the most updated version.");
    }

    distUpdater.replaceWindupDirectoryWithDistribution(latestDist);

    return Results.success("Sucessfully updated "+Util.WINDUP_BRAND_NAME_ACRONYM+" CLI to version " + latestDist.getVersion() + ". Please restart MTA CLI.");
}
 
Example #2
Source File: MavenHelpers.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public static MavenPlugin findPlugin(Project project, String groupId, String artifactId) {
    if (project != null) {
        MavenPluginFacet pluginFacet = project.getFacet(MavenPluginFacet.class);
        if (pluginFacet != null) {
            List<MavenPlugin> plugins = pluginFacet.listConfiguredPlugins();
            if (plugins != null) {
                for (MavenPlugin plugin : plugins) {
                    Coordinate coordinate = plugin.getCoordinate();
                    if (coordinate != null) {
                        if (Objects.equal(groupId, coordinate.getGroupId()) &&
                                Objects.equal(artifactId, coordinate.getArtifactId())) {
                            return plugin;
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example #3
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 #4
Source File: RulesetsUpdater.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
public String replaceRulesetsDirectoryWithLatestReleaseIfAny() throws IOException, DependencyException
{
    if (!this.rulesetsNeedUpdate(false))
        return null;

    Path windupRulesDir = getRulesetsDir();
    Path coreRulesetsDir = windupRulesDir.resolve(RULESET_CORE_DIRECTORY);

    Coordinate rulesetsCoord = getLatestReleaseOf(RULES_GROUP_ID, RULESETS_ARTIFACT_ID);
    if(rulesetsCoord == null)
        throw new WindupException("No Windup rulesets release found.");

    FileUtils.deleteDirectory(coreRulesetsDir.toFile());
    extractArtifact(rulesetsCoord, coreRulesetsDir.toFile());

    return rulesetsCoord.getVersion();
}
 
Example #5
Source File: InMemoryArchiveIdentificationService.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
public InMemoryArchiveIdentificationService addMappingsFrom(File file)
{
    try (FileInputStream inputStream = new FileInputStream(file))
    {
        LineIterator iterator = IOUtils.lineIterator(inputStream, "UTF-8");
        int lineNumber = 0;
        while (iterator.hasNext())
        {
            lineNumber++;
            String line = iterator.next();
            if (line.startsWith("#") || line.trim().isEmpty())
                continue;
            String[] parts = StringUtils.split(line, ' ');
            if (parts.length < 2)
                throw new IllegalArgumentException("Expected 'SHA1 GROUP_ID:ARTIFACT_ID:[PACKAGING:[COORDINATE:]]VERSION', but was: [" + line
                            + "] in [" + file + "] at line [" + lineNumber + "]");

            addMapping(parts[0], parts[1]);
        }
    }
    catch (IOException e)
    {
        throw new WindupException("Failed to load SHA1 to " + Coordinate.class.getSimpleName() + " definitions from [" + file + "]", e);
    }
    return this;
}
 
Example #6
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 #7
Source File: SkippedArchives.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isSkipped(Coordinate coordinate)
{
    for (Entry<Coordinate, VersionRange> entry : map.entrySet())
    {
        Coordinate pattern = entry.getKey();
        VersionRange range = entry.getValue();

        if (isPatternMatch(pattern.getGroupId(), coordinate.getGroupId())
                    && isPatternMatch(pattern.getArtifactId(), coordinate.getArtifactId())
                    && isPatternMatch(pattern.getClassifier(), coordinate.getClassifier()))
        {
            if (range.isEmpty() || range.includes(new SingleVersion(coordinate.getVersion())))
                return true;
        }
    }
    return false;
}
 
Example #8
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 #9
Source File: DistributionUpdater.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
public void replaceWindupDirectoryWithLatestDistribution()
{
    Coordinate coord = updater.queryLatestWindupRelease();
    if(coord == null)
        throw new WindupException("No "+ Util.WINDUP_BRAND_NAME_ACRONYM +" release found.");
    log.info("Latest "+ Util.WINDUP_BRAND_NAME_ACRONYM +" version available: " + coord.getVersion());
    log.fine("Latest "+ Util.WINDUP_BRAND_NAME_ACRONYM +" version available: " + coord);

    replaceWindupDirectoryWithDistribution(coord);
}
 
Example #10
Source File: RulesetsUpdater.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private SingleVersion getLatestCoreRulesetVersion()
{
    Coordinate lastRelease = this.getLatestReleaseOf(RULES_GROUP_ID, RULESETS_ARTIFACT_ID);
    if (lastRelease == null)
        return null;
    return new SingleVersion(lastRelease.getVersion());
}
 
Example #11
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 #12
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 #13
Source File: RulesetsUpdater.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
public void extractArtifact(Coordinate artifactCoords, File targetDir) throws IOException, DependencyException
{
    final DependencyQueryBuilder query = DependencyQueryBuilder.create(artifactCoords);
    Dependency dependency = depsResolver.resolveArtifact(query);
    FileResource<?> artifact = dependency.getArtifact();
    ZipUtil.unzipToFolder(new File(artifact.getFullyQualifiedName()), targetDir);
}
 
Example #14
Source File: ArchiveCoordinateIdentificationTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testIdentifyArchive() throws IOException
{
    final File mappingFile = new File(DATA_PATH + "/test.archive-metadata.txt");
    identifier.addMappingsFrom(mappingFile);
    Coordinate gav = identifier.getCoordinate("11856de4eeea74ce134ef3f910ff8d6f989dab2e");
    Assert.assertNotNull("IdentifiedArchives.getGAVFromSHA1 returned something", gav);
    Assert.assertEquals("org.jboss.windup", gav.getGroupId());
    Assert.assertEquals("windup-bootstrap", gav.getArtifactId());
    Assert.assertEquals("2.0.0.Beta7", gav.getVersion());
    Assert.assertEquals(null, gav.getClassifier());
}
 
Example #15
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 #16
Source File: LuceneFileArchiveIdentificationServiceTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private static String coordToString(Coordinate coord)
{
    StringBuilder sb = new StringBuilder();
    sb.append(coord.getGroupId()).append(':').append(coord.getArtifactId());
    if (coord.getPackaging() != null)
        sb.append(':').append(coord.getPackaging());
    if (coord.getClassifier() != null)
        sb.append(':').append(coord.getClassifier());
    sb.append(':').append(coord.getVersion());
    return sb.toString();
}
 
Example #17
Source File: LuceneFileArchiveIdentificationServiceTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGetCoordinateFromSHA1() throws Exception
{
    final File file = new File("target/test-nexus-data/lucene/");
    Assert.assertTrue("Test file does not exist", file.exists());
    LuceneArchiveIdentificationService ident = new LuceneArchiveIdentificationService(file);

    Coordinate coordinate = ident.getCoordinate("55555555564e84315e83c6ba4a855b07ba51166b");
    Assert.assertNull("No coordinate for 55555555564e84315e83c6ba4a855b07ba51166b", coordinate);

    // Position 0
    check(ident, "000005ce9bd9867e24cdc33c06e88a65edce71db", "com.google.apis:google-api-services-genomics:jar::v1beta-rev26-1.18.0-rc");

    // Last entry
    check(ident, "ffffdf1558b62750b24bdaa33cb9a72b0cb766ce", "org.glassfish.metro:wsmc-impl:jar::2.1.1-b06");

    // A block around pivot break.
    check(ident, "4e02fd52064e84315e83c6ba4a855b07ba51166b", "org.jogamp.joal:joal:jar:natives-macosx-universal:2.1.2");
    check(ident, "4e031603849ad1e70d245855802cc388ded93461", "org.glassfish.jdbc.jdbc-ra.jdbc40:jdbc40:jar::3.0-b37");
    // Position 29723213
    check(ident, "4e031bb61df09069aeb2bffb4019e7a5034a4ee0", "junit:junit:jar::4.11");
    check(ident, "4e0334465984c00cbcf177b1702805bd4b5d6d27", "org.soitoolkit.refapps.sd:soitoolkit-refapps-sample-schemas:jar::0.6.1");
    check(ident, "4e034d862d9650df285b8ee98f7f770db6c19029", "org.apache.cxf:cxf-rt-bindings-soap:jar::2.4.8");

    // Some which caused issues.
    check(ident, "7ff0d167a6816aa113b1b4a8a37515701a74b288", "org.kill-bill.billing:killbill-platform-osgi-bundles-lib-slf4j-osgi:jar::0.1.0");
}
 
Example #18
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 #19
Source File: CompositeArchiveIdentificationService.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Coordinate getCoordinate(String checksum)
{
    for (ArchiveIdentificationService identifier : identifiers)
    {
        Coordinate coordinate = identifier.getCoordinate(checksum);
        if (coordinate != null)
            return coordinate;
    }
    return null;
}
 
Example #20
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 #21
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 #22
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 #23
Source File: LuceneFileArchiveIdentificationServiceTest.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
private static void check(ArchiveIdentificationService ident, String hash, String coordString)
{
    Coordinate coord = ident.getCoordinate(hash);
    Assert.assertNotNull("Coordinate found for " + hash, coord);
    Assert.assertEquals(hash + " = " + coordString, coordString, coordToString(coord));
}
 
Example #24
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 #25
Source File: ArchiveIdentificationGraphChangedListener.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void vertexPropertyChanged(Vertex element, Property oldValue, Object setValue, Object... vertexPropertyKeyValues)
{
    String key = oldValue.key();
    if (ArchiveModel.ARCHIVE_NAME.equals(key))
    {
        ArchiveModel archive = archiveService.getById(element.id());

        setArchiveHashes(archive);

        Coordinate coordinate = identifier.getCoordinate(archive.getSHA1Hash());
        if (coordinate != null)
        {
            // If this is not a jar file, do not ignore it
            if (!StringUtils.endsWithIgnoreCase(archive.getFileName(), ".jar"))
                return;

            // Never ignore the input application
            WindupConfigurationModel configurationModel = WindupConfigurationService.getConfigurationModel(this.context);
            for (FileModel inputPath : configurationModel.getInputPaths())
            {
                if (inputPath.equals(archive))
                    return;
            }

            IdentifiedArchiveModel identifiedArchive = GraphService.addTypeToModel(context, archive, IdentifiedArchiveModel.class);
            ArchiveCoordinateModel coordinateModel = new GraphService<>(context, ArchiveCoordinateModel.class).create();

            coordinateModel.setArtifactId(coordinate.getArtifactId());
            coordinateModel.setGroupId(coordinate.getGroupId());
            coordinateModel.setVersion(coordinate.getVersion());
            coordinateModel.setClassifier(coordinate.getClassifier());
            identifiedArchive.setCoordinate(coordinateModel);

            LOG.info("Identified archive: [" + archive.getFilePath() + "] as [" + coordinate + "] will not be unzipped or analyzed.");
            IgnoredArchiveModel ignoredArchive = GraphService.addTypeToModel(context, archive, IgnoredArchiveModel.class);
            ignoredArchive.setIgnoredRegex("Known open-source library");
        }
        else
        {
            LOG.info("Archive not identified: " + archive.getFilePath() + " SHA1: " + archive.getSHA1Hash());
        }
    }
}
 
Example #26
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
protected Coordinate createCamelCoordinate(String artifactId, String version) {
    return createCoordinate("org.apache.camel", artifactId, version);
}
 
Example #27
Source File: MavenHelpers.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
public static Coordinate createCoordinate(String groupId, String artifactId, String version) {
    return createCoordinate(groupId, artifactId, version, null);
}
 
Example #28
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 #29
Source File: AbstractFabricProjectCommand.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
protected Coordinate createCoordinate(String groupId, String artifactId, String version) {
    return createCoordinate(groupId, artifactId, version, null);
}
 
Example #30
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);
    }
}