-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WINDUP-705 Fix automatic distribution updating - WIP
- Loading branch information
1 parent
09f05b4
commit fffaabd
Showing
3 changed files
with
199 additions
and
96 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
ui/addon/src/main/java/org/jboss/windup/ui/DistributionUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.jboss.windup.ui; | ||
|
||
|
||
import java.io.File; | ||
import java.io.FilenameFilter; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.logging.Logger; | ||
import javax.inject.Inject; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.IOCase; | ||
import org.apache.commons.io.filefilter.FileFilterUtils; | ||
import org.jboss.forge.addon.dependencies.Coordinate; | ||
import org.jboss.forge.addon.dependencies.DependencyException; | ||
import org.jboss.forge.addon.dependencies.builder.CoordinateBuilder; | ||
import org.jboss.forge.furnace.util.OperatingSystemUtils; | ||
import org.jboss.windup.exec.updater.RulesetsUpdater; | ||
import org.jboss.windup.util.PathUtil; | ||
import org.jboss.windup.util.exception.WindupException; | ||
|
||
/** | ||
* | ||
* @author Ondrej Zizka, ozizka at redhat.com | ||
*/ | ||
public class DistributionUpdater | ||
{ | ||
private static final Logger log = Logger.getLogger( DistributionUpdater.class.getName() ); | ||
|
||
@Inject | ||
private RulesetsUpdater updater; | ||
|
||
|
||
/** | ||
* 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 IllegalStateException, DependencyException, IOException, WindupException | ||
{ | ||
Path windupRulesDir = PathUtil.getWindupRulesDir(); | ||
Path addonsDir = PathUtil.getWindupAddonsDir(); | ||
Path binDir = PathUtil.getWindupHome().resolve(PathUtil.BINARY_DIRECTORY_NAME); | ||
Path libDir = PathUtil.getWindupHome().resolve(PathUtil.LIBRARY_DIRECTORY_NAME); | ||
Path coreRulesPropertiesPath = windupRulesDir.resolve(RulesetsUpdater.RULESET_CORE_DIRECTORY); | ||
|
||
final CoordinateBuilder coord = CoordinateBuilder.create(distCoordinate).setClassifier("offline").setPackaging("zip"); | ||
File tempFolder = OperatingSystemUtils.createTempDir(); | ||
this.updater.extractArtifact(coord, tempFolder); | ||
|
||
|
||
File[] matchingDirs = tempFolder.listFiles((FilenameFilter) FileFilterUtils.prefixFileFilter("windup-distribution-", IOCase.INSENSITIVE)); | ||
if (matchingDirs.length == 0) | ||
throw new WindupException("Distribution update failed: " + "The distribution archive did not contain the windup-distribution-* directory: " + coord.toString()); | ||
String distTempPath = matchingDirs[0].getAbsolutePath(); | ||
|
||
FileUtils.deleteDirectory(coreRulesPropertiesPath.toFile()); | ||
FileUtils.deleteDirectory(addonsDir.toFile()); | ||
FileUtils.deleteDirectory(libDir.toFile()); | ||
FileUtils.deleteDirectory(binDir.toFile()); | ||
|
||
FileUtils.moveDirectory(new File(distTempPath, PathUtil.ADDONS_DIRECTORY_NAME), addonsDir.toFile()); | ||
FileUtils.moveDirectory(new File(distTempPath, PathUtil.BINARY_DIRECTORY_NAME), binDir.toFile()); | ||
FileUtils.moveDirectory(new File(distTempPath, PathUtil.LIBRARY_DIRECTORY_NAME), libDir.toFile()); | ||
// This is for testing purposes. The releases do not contain migration-core/ . | ||
File downloadedMigrationCore = new File(distTempPath, PathUtil.RULES_DIRECTORY_NAME + File.pathSeparator + RulesetsUpdater.RULESET_CORE_DIRECTORY); | ||
File fromDir = downloadedMigrationCore.exists() ? downloadedMigrationCore : new File(distTempPath, PathUtil.RULES_DIRECTORY_NAME); | ||
FileUtils.moveDirectory(fromDir, coreRulesPropertiesPath.toFile()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.