Skip to content

Commit

Permalink
[GR-27927] Permit upgrades to different editions.
Browse files Browse the repository at this point in the history
  • Loading branch information
sdedic committed Dec 15, 2020
1 parent ccb0c62 commit 246de5b
Show file tree
Hide file tree
Showing 25 changed files with 348 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public Path getGraalHomePath() {
@Override
public ComponentCatalog getRegistry() {
if (registry == null) {
registry = getCatalogFactory().createComponentCatalog(this, getLocalRegistry());
registry = getCatalogFactory().createComponentCatalog(this);
}
return registry;
}
Expand Down Expand Up @@ -281,7 +281,7 @@ public ComponentStorage getStorage() {
public CatalogFactory getCatalogFactory() {
return new CatalogFactory() {
@Override
public ComponentCatalog createComponentCatalog(CommandInput input, ComponentRegistry targetGraalVM) {
public ComponentCatalog createComponentCatalog(CommandInput input) {
if (registry != null) {
return registry;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void setupReleaseAndCatalog() throws Exception {

private void initRemoteStorage() {
GraalEditionList list = new GraalEditionList(this, this, getLocalRegistry());
this.registry = list.createComponentCatalog(this, getLocalRegistry());
this.registry = list.createComponentCatalog(this);
this.editionList = list;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ public void testInstallDependencyFromSameDirectory() throws Exception {
new SoftwareChannelSource(ruby193Source.getParent().toFile().toURI().toString()));
catalogFactory = new CatalogFactory() {
@Override
public ComponentCatalog createComponentCatalog(CommandInput input, ComponentRegistry reg) {
return new CatalogContents(CatalogInstallTest.this, downloader.getStorage(), reg);
public ComponentCatalog createComponentCatalog(CommandInput input) {
return new CatalogContents(CatalogInstallTest.this, downloader.getStorage(), input.getLocalRegistry());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void initCatalogIterable(URL u) {
channel.setReleasesIndexURL(u);
cfactory = new CatalogFactory() {
@Override
public ComponentCatalog createComponentCatalog(CommandInput input, ComponentRegistry targetGraalVM) {
public ComponentCatalog createComponentCatalog(CommandInput input) {
try {
return new CatalogContents(InstallLicensedCatalogTest.this, channel.getStorage(), localRegistry);
} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.graalvm.component.installer.CommandInput;
import org.graalvm.component.installer.CommandTestBase;
import org.graalvm.component.installer.Commands;
import org.graalvm.component.installer.CommonConstants;
import org.graalvm.component.installer.ComponentCatalog;
import org.graalvm.component.installer.ComponentParam;
import org.graalvm.component.installer.FailedOperationException;
Expand Down Expand Up @@ -370,7 +371,7 @@ public void testInstallIntoExistingNonempty() throws Exception {

ComponentInfo info = cmd.configureProcess();
Path p = getGraalHomePath().normalize();
Path ndir = p.resolveSibling("graalvm-ce-1.0.1");
Path ndir = graalVMDirectory(p, "1.0.1");
Files.createDirectories(ndir);
Files.write(ndir.resolve("some-content"), Arrays.asList("Fail"));

Expand All @@ -379,6 +380,11 @@ public void testInstallIntoExistingNonempty() throws Exception {
helper.prepareInstall(info);
}

private Path graalVMDirectory(Path sibling, String version) {
return sibling.resolveSibling("graalvm-ce-java" +
getLocalRegistry().getGraalCapabilities().get(CommonConstants.CAP_JAVA_VERSION) + "-" + version);
}

/**
* Fails on non-empty directory.
*/
Expand All @@ -395,7 +401,7 @@ public void testInstallIntoExistingRelease() throws Exception {

ComponentInfo info = cmd.configureProcess();
Path p = getGraalHomePath().normalize();
Path ndir = p.resolveSibling("graalvm-ce-1.0.1");
Path ndir = graalVMDirectory(p, "1.0.1");
Files.createDirectories(ndir);
Files.write(ndir.resolve("some-content"), Arrays.asList("Fail"));
Path toCopy = dataFile("../persist/release_simple.properties");
Expand All @@ -422,7 +428,7 @@ public void testInstallIntoExistingEmpty() throws Exception {

ComponentInfo info = cmd.configureProcess();
Path p = getGraalHomePath().normalize();
Path ndir = p.resolveSibling("graalvm-ce-1.0.1");
Path ndir = graalVMDirectory(p, "1.0.1");
Files.createDirectories(ndir);

assertTrue(helper.prepareInstall(info));
Expand Down Expand Up @@ -617,10 +623,10 @@ public void testUpgradeWithDependencies() throws Exception {

factory = new CatalogFactory() {
@Override
public ComponentCatalog createComponentCatalog(CommandInput in, ComponentRegistry reg) {
public ComponentCatalog createComponentCatalog(CommandInput in) {
RemoteCatalogDownloader dnl = new RemoteCatalogDownloader(in, UpgradeTest.this, downloader.getOverrideCatalogSpec());
// carry over the override spec
return new CatalogContents(UpgradeTest.this, dnl.getStorage(), reg);
return new CatalogContents(UpgradeTest.this, dnl.getStorage(), in.getLocalRegistry());
}

@Override
Expand Down Expand Up @@ -671,9 +677,9 @@ public void testUpgradeRespectsTargetCatalogURLs() throws Exception {
assertTrue(installed);
factory = new CatalogFactory() {
@Override
public ComponentCatalog createComponentCatalog(CommandInput in, ComponentRegistry reg) {
public ComponentCatalog createComponentCatalog(CommandInput in) {
RemoteCatalogDownloader dnl = new RemoteCatalogDownloader(in, UpgradeTest.this, (String) null);
return new CatalogContents(UpgradeTest.this, dnl.getStorage(), reg);
return new CatalogContents(UpgradeTest.this, dnl.getStorage(), in.getLocalRegistry());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void testLoadFromEmptyDirectory() throws Exception {
}

@Override
public ComponentCatalog createComponentCatalog(CommandInput input, ComponentRegistry targetGraalVM) {
public ComponentCatalog createComponentCatalog(CommandInput input) {
return new CatalogContents(this, downloader.getStorage(), getLocalRegistry());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public void testAcceptLicense() throws Exception {
enableLicensesForTesting();
storage.recordLicenseAccepted(info, "cafebabe", "This is a dummy license", null);
Path p = registryPath.resolve(SystemUtils.fromCommonString(
MessageFormat.format(DirectoryStorage.LICENSE_FILE_TEMPLATE, "cafebabe", "org.graalvm.fastr")));
MessageFormat.format(DirectoryStorage.LICENSE_FILE_TEMPLATE, "cafebabe", "org.graalvm.fastr")));
Path p2 = registryPath.resolve(SystemUtils.fromCommonString("licenses/cafebabe"));
assertTrue(Files.isReadable(p));
assertEquals(Arrays.asList("This is a dummy license"), Files.readAllLines(p2));
Expand All @@ -514,7 +514,7 @@ public void testAcceptLicenseWithUrlId() throws Exception {
enableLicensesForTesting();
storage.recordLicenseAccepted(info, "http://acme.org/license.txt", "This is a dummy license", null);
Path p = registryPath.resolve(SystemUtils.fromCommonString(
MessageFormat.format(DirectoryStorage.LICENSE_FILE_TEMPLATE, "http___acme.org_license.txt", "org.graalvm.fastr")));
MessageFormat.format(DirectoryStorage.LICENSE_FILE_TEMPLATE, "http___acme.org_license.txt", "org.graalvm.fastr")));
Path p2 = registryPath.resolve(SystemUtils.fromCommonString("licenses/http___acme.org_license.txt"));
Path p3 = registryPath.resolve(SystemUtils.fromCommonString("licenses/http___acme.org_license.txt.id"));
assertTrue(Files.isReadable(p));
Expand Down Expand Up @@ -563,7 +563,7 @@ public void testLicenseAccepted1() throws Exception {
ComponentInfo info2 = loadLastComponent("ruby");

Path p = registryPath.resolve(SystemUtils.fromCommonString(
MessageFormat.format(DirectoryStorage.LICENSE_FILE_TEMPLATE, "cafebabe", "org.graalvm.fastr")));
MessageFormat.format(DirectoryStorage.LICENSE_FILE_TEMPLATE, "cafebabe", "org.graalvm.fastr")));
Files.createDirectories(p.getParent());
Files.write(p, Arrays.asList("ahoj"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private ComponentCatalog getRemoteContents() {
return remoteCatalog;
}
if (remoteFactory != null) {
remoteCatalog = remoteFactory.createComponentCatalog(input, input.getLocalRegistry());
remoteCatalog = remoteFactory.createComponentCatalog(input);
} else {
remoteCatalog = new NullCatalog();
}
Expand Down Expand Up @@ -100,6 +100,10 @@ public ComponentParam createParam(String cmdString, ComponentInfo info) {
}

private static class NullCatalog implements ComponentCatalog, DownloadInterceptor {
@Override
public boolean isAllowDistUpdate() {
return false;
}

@Override
public ComponentInfo findComponentMatch(String id, Version.Match vmatch, boolean localOnly, boolean exact) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ INFO_Usage=\n\
\tgu install [-0CcDfiLMnosruvyxY] <param> installs a component package\n\
\tgu list [-clv] <expression> lists installed components, or components from catalog\n\
\tgu remove [-0DfMxv] <id> uninstalls a component\n\
\tgu upgrade [-cCnLsux] [<ver>] [<param>] upgrades to recent GraalVM\n\
\tgu upgrade [-cCnLsuxSd] [<ver>] [<cmp>] upgrades to recent GraalVM or edition\n\
\tgu rebuild-images rebuilds native images. Use -h for detailed usage\n\
\n\
Common options:\n\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,10 @@ interface CatalogFactory {
/**
* Create a component catalog for the target VM installation, using the commandline options.
*
* @param targetGraalVM target installation component registry
* @param input values for the catalog
* @return ComponentCatalog usable with target installation
*/
ComponentCatalog createComponentCatalog(CommandInput input, ComponentRegistry targetGraalVM);
ComponentCatalog createComponentCatalog(CommandInput input);

/**
* Lists GraalVM editions defined for the installation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,16 @@ public interface Commands {
*/
String OPTION_SHOW_UPDATES = "&";
String LONG_OPTION_SHOW_UPDATES = "show-updates";

/**
* Install into target directory.
*/
String OPTION_TARGET_DIRECTORY = "d";
String LONG_OPTION_TARGET_DIRECTORY = "target-dir";

/**
* Do not create or update symlink.
*/
String OPTION_NO_SYMLINK = "S";
String LONG_OPTION_NO_SYMLINK = "no-symlink";
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ default ComponentInfo findComponent(String id) {
return findComponent(id, null);
}

boolean isAllowDistUpdate();

void setAllowDistUpdate(boolean distUpgrade);

default ComponentInfo findComponent(String id, Version.Match vm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void setCatalogFactory(CatalogFactory catalogFactory) {
@Override
public ComponentCatalog getRegistry() {
if (componentCatalog == null) {
componentCatalog = catalogFactory.createComponentCatalog(this, getLocalRegistry());
componentCatalog = catalogFactory.createComponentCatalog(this);
}
return componentCatalog;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,21 @@ public Map<String, String> supportedOptions() {
@Override
protected ComponentCollection initRegistry() {
super.initRegistry();
if (showUpdates) {
input.getRegistry().setAllowDistUpdate(true);
}
return input.getRegistry();
}

@Override
public void init(CommandInput commandInput, Feedback feedBack) {
super.init(commandInput, feedBack);
String v = commandInput.optValue(Commands.OPTION_VERSION);
if (v != null) {
vmatch = Version.versionFilter(v);
}
showUpdates = commandInput.hasOption(Commands.OPTION_SHOW_UPDATES) || commandInput.hasOption(Commands.OPTION_ALL);
showCore = commandInput.hasOption(Commands.OPTION_SHOW_CORE) | showUpdates | commandInput.hasOption(Commands.OPTION_USE_EDITION);
super.init(commandInput, feedBack);
}

private boolean showUpdates;
Expand All @@ -96,9 +101,6 @@ public int execute() throws IOException {
feedback.output("AVAILABLE_Help");
return 0;
}
showUpdates = input.hasOption(Commands.OPTION_SHOW_UPDATES);
showCore = input.hasOption(Commands.OPTION_SHOW_CORE) | showUpdates | input.hasOption(Commands.OPTION_USE_EDITION);

return super.execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,12 @@ UPGRADE_TargetDirectoryExists=Cannot install GraalVM: file or directory {0} alre
UPGRADE_CantDeleteOldSymlink=Could not delete old symlink {0}: {1}
UPGRADE_CantCreateNewSymlink=Unable to create new symlink {0}: {1}
# {0} - version
UPGRADE_GraalVMDirName@=graalvm-{0}
# {2} - java prefix
UPGRADE_GraalVMDirName@=graalvm-java{2}-{0}
# {0} - version
# {1} - edition
UPGRADE_GraalVMDirNameEdition@=graalvm-{1}-{0}
# {2} - java prefix
UPGRADE_GraalVMDirNameEdition@=graalvm-{1}-java{2}-{0}
# {0} - required version
UPGRADE_NoVersionSatisfiesComponents=No GraalVM version satisfies all the requested components. At least {0} is required.
UPGRADE_ComponentsCannotMigrate=Some of the installed components cannot migrate to the new version. Please first upgrade to a specific GraalVM version first.
Expand Down Expand Up @@ -339,8 +341,8 @@ UPDATE_Help=\

UPGRADE_Help=\
Usage:\n\
gu upgrade [-cCnLsux] [version] [param ...]\n\
gu update [-cCnLsux] [version] [param ...]\n\
gu upgrade [-cCdnLsSux] [version] [param ...]\n\
gu update [-cCdnLsSux] [version] [param ...]\n\
\n\
Options:\n\
\ -c, --catalog treat parameters as component IDs from catalog of GraalVM components. This is the default.\n\
Expand All @@ -349,12 +351,12 @@ UPGRADE_Help=\
\ -L, --local-file treat parameters as local filenames of packaged components.\n\
\ -n, --no-progress do not display download progress.\n\
\ -s, --no-verify-jars skips integrity verification of component archives\n\
\ -S, --no-symlink do not create or update symlink\n\
\ -d, --target-dir install into specified target dir, implies -S\n\
\ -u, --url interpret parameters as URLs of packaged components.\n\
\ -x, --ignore-missing ignores missing components for the target version, install new core anyway\n\
\n\
If "version" is specified, the GraalVM will be updated to that version, most recent patch. "version" can\n\
be prepended with = (equals sign) to force an exact patch. If prepended by + (plus sign), install will\n\
use most recent available version newer or equal the one specified.\n\
If "version" is specified, the GraalVM will be updated to that version.\n\
\n\
The GraalVM core will be upgraded and existing components reinstalled in appropriate versions into the \n\
new installation. Additional components to install may be specified as parameters. Install fails if the\\n\
Expand Down Expand Up @@ -383,4 +385,22 @@ INSTALL_DownloadLicenseName=Contents of "{0}"

# [0} license Id
# {1} error message
WARN_LicenseNotRecorded=Warning: Acceptance of license {0} could not be recorded: {1}
WARN_LicenseNotRecorded=Warning: Acceptance of license {0} could not be recorded: {1}
UPGRADE_CannotMigrateGDS=Warning: Could not migrate GDS settings
# {0} symlink name
# {1} symlink target
UPGRADE_CreatingSymlink=Creating symlink to the new GraalVM Installation: {0} -> {1}
UPGRADE_UpdatingSymlink=Updating symlink to the new GraalVM Installation: {0} -> {1}

# {0} - graalvm core name
# {1} - graalvm core version
# {2} - list of components
UPGRADE_MissingComponents=Components missing for {0} {1}: \n{2}
# {0} - component (short) ID
# {1} - component name
UPGRADE_MissingComponentItem=\t{0} ({1})
# {0} - preceding list part,
# {1} - additional item.
UPGRADE_MissingComponentListPart={0},\n{1}
# {0} - list contents
UPGRADE_MissingComponentListFinish={0}
Loading

0 comments on commit 246de5b

Please sign in to comment.