Skip to content

Commit

Permalink
Changed APIs to support multiple versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
sdedic committed Apr 25, 2019
1 parent bbce4aa commit b49d6f8
Show file tree
Hide file tree
Showing 40 changed files with 1,362 additions and 201 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ test-output/
workingsets.xml
bench-results.json
jmh_result.json
/vm/src/installer/dist/
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import org.junit.Rule;
import org.junit.Test;

public class CatalogIterableTest extends CommandTestBase implements SoftwareChannel {
public class CatalogIterableTest extends CommandTestBase {
@Rule public final ProxyResource proxyResource = new ProxyResource();

@Override
Expand Down Expand Up @@ -291,23 +291,17 @@ public void connect() throws IOException {
rubyComp.createFileLoader().getComponentInfo();
}

@Override
public boolean setupLocation(String urlString) {
// OK
return true;
}

@Override
public void init(CommandInput input, Feedback output) {
}

@Override
public MetadataLoader createLocalFileLoader(Path localFile, boolean verify) throws IOException {
public MetadataLoader createLocalFileLoader(ComponentInfo info, Path localFile, boolean verify) throws IOException {
return new JarMetaLoader(new JarFile(localFile.toFile(), verify), this);
}

@Override
public FileDownloader configureDownloader(FileDownloader dn) {
public FileDownloader configureDownloader(ComponentInfo info, FileDownloader dn) {
return dn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.graalvm.component.installer.jar.JarMetaLoader;
import org.graalvm.component.installer.model.ComponentInfo;
import org.graalvm.component.installer.model.ComponentRegistry;
import org.graalvm.component.installer.model.ComponentStorage;
import org.graalvm.component.installer.persist.ComponentPackageLoader;
import org.graalvm.component.installer.remote.FileDownloader;
import org.graalvm.component.installer.persist.MetadataLoader;
Expand Down Expand Up @@ -193,23 +194,22 @@ public void setUp() throws Exception {
localRegistry = registry = new ComponentRegistry(this, storage);
}

@Override
public boolean setupLocation(String urlString) {
return false;
}

@Override
public void init(CommandInput input, Feedback output) {
}

@Override
public FileDownloader configureDownloader(FileDownloader dn) {
public FileDownloader configureDownloader(ComponentInfo info, FileDownloader dn) {
return dn;
}

@Override
public MetadataLoader createLocalFileLoader(Path localFile, boolean verify) throws IOException {
public MetadataLoader createLocalFileLoader(ComponentInfo info, Path localFile, boolean verify) throws IOException {
return new JarMetaLoader(new JarFile(localFile.toFile(), verify), this);
}

@Override
public ComponentStorage getStorage() {
return storage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.graalvm.component.installer;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
*
* @author sdedic
*/
public class VersionTest {
@Test
public void testNoVersionInfimum() throws Exception {
Version otherNullVersion = Version.fromString(Version.NO_VERSION.toString());

assertTrue(otherNullVersion.compareTo(Version.NO_VERSION) > 0);
assertTrue(Version.NO_VERSION.compareTo(otherNullVersion) < 0);

assertFalse(otherNullVersion.equals(Version.NO_VERSION));
assertFalse(Version.NO_VERSION.equals(otherNullVersion));
}

@Test
public void testNoVersionEqualToSelf() throws Exception {
assertTrue(Version.NO_VERSION.compareTo(Version.NO_VERSION) == 0);
assertTrue(Version.NO_VERSION.equals(Version.NO_VERSION));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void testFailRemoteComponentExisting() throws IOException {
@Test
public void testSetReplaceComponents() throws IOException {
setupComponentInstall("truffleruby2.jar");
ComponentInfo fakeInfo = new ComponentInfo("org.graalvm.ruby", "Fake ruby", "1.0");
ComponentInfo fakeInfo = new ComponentInfo("org.graalvm.ruby", "Fake ruby", "0.32");
storage.installed.add(fakeInfo);

installer.setReplaceComponents(true);
Expand All @@ -147,7 +147,7 @@ public void testSetReplaceComponents() throws IOException {
@Test
public void testFailOnExistingComponent() throws IOException {
setupComponentInstall("truffleruby2.jar");
ComponentInfo fakeInfo = new ComponentInfo("org.graalvm.ruby", "Fake ruby", "1.0");
ComponentInfo fakeInfo = new ComponentInfo("org.graalvm.ruby", "Fake ruby", "0.32");
storage.installed.add(fakeInfo);

exception.expect(DependencyException.Conflict.class);
Expand All @@ -159,7 +159,7 @@ public void testFailOnExistingComponent() throws IOException {
@Test
public void testSkipExistingComponent() throws IOException {
setupComponentInstall("truffleruby2.jar");
ComponentInfo fakeInfo = new ComponentInfo("org.graalvm.ruby", "Fake ruby", "1.0");
ComponentInfo fakeInfo = new ComponentInfo("org.graalvm.ruby", "Fake ruby", "0.32");
storage.installed.add(fakeInfo);

installer.setFailOnExisting(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Objects;
import java.util.Properties;
import org.graalvm.component.installer.CommandTestBase;
import org.graalvm.component.installer.Version;
import org.graalvm.component.installer.model.ComponentRegistry;
import org.graalvm.component.installer.remote.RemotePropertiesStorage;
import static org.junit.Assert.assertEquals;
Expand All @@ -51,7 +52,10 @@ public class ListTest extends CommandTestBase {

private void initRemoteStorage() throws MalformedURLException {
this.remoteStorage = new RemotePropertiesStorage(
this, localRegistry, catalogContents, "1.0.0-rc3-dev_linux_amd64", new URL("http://go.to/graalvm"));
this, localRegistry, catalogContents,
"linux_amd64",
Version.fromString("1.0.0-rc3-dev"),
new URL("http://go.to/graalvm"));
this.registry = new ComponentRegistry(this, remoteStorage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -83,8 +84,9 @@ public ComponentInfo loadComponentFiles(ComponentInfo ci) throws IOException {
}

@Override
public ComponentInfo loadComponentMetadata(String tag) throws IOException {
return installed.stream().filter((ci) -> ci.getId().equals(tag)).findFirst().orElse(null);
public Set<ComponentInfo> loadComponentMetadata(String tag) throws IOException {
ComponentInfo ret = installed.stream().filter((ci) -> ci.getId().equals(tag)).findFirst().orElse(null);
return ret == null ? null : Collections.singleton(ret);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ public void setUp() throws Exception {
ldr.loadSymlinks();
}

fakeInfo = new ComponentInfo("org.graalvm.fake", "Fake component", "1.0");
fakeInfo = new ComponentInfo("org.graalvm.fake", "Fake component", "0.32");
fakeInfo.addPaths(Arrays.asList(
"jre/bin/ruby",
"jre/languages/fake/nothing"));
mockStorage.installed.add(fakeInfo);
}

private void registerAdditionalComponents() {
ComponentInfo tmp = new ComponentInfo("org.graalvm.foobar", "Test component 1", "1.0");
ComponentInfo tmp = new ComponentInfo("org.graalvm.foobar", "Test component 1", "0.32");
mockStorage.installed.add(tmp);

tmp = new ComponentInfo("org.graalvm.clash", "Test component 2", "1.0");
tmp = new ComponentInfo("org.graalvm.clash", "Test component 2", "0.32");
mockStorage.installed.add(tmp);
tmp1 = tmp;
tmp = new ComponentInfo("org.github.clash", "Test component 3", "1.0");
tmp = new ComponentInfo("org.github.clash", "Test component 3", "0.32");
mockStorage.installed.add(tmp);
tmp2 = tmp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

import org.graalvm.component.installer.BundleConstants;
Expand Down Expand Up @@ -165,13 +166,23 @@ public void testListComponentsEmpty() throws Exception {
assertEquals(Collections.emptyList(), components);
}

private ComponentInfo loadLastComponent(String id) throws IOException {
Set<ComponentInfo> infos = storage.loadComponentMetadata(id);
if (infos == null || infos.isEmpty()) {
return null;
}
List<ComponentInfo> sorted = new ArrayList<>(infos);
Collections.sort(sorted, ComponentInfo.versionComparator());
return sorted.get(sorted.size() - 1);
}

/**
* Test of loadComponentMetadata method, of class RegistryStorage.
*/
@Test
public void testLoadComponentMetadata() throws Exception {
copyDir("list1", registryPath);
ComponentInfo info = storage.loadComponentMetadata("fastr");
ComponentInfo info = loadLastComponent("fastr");
assertEquals("org.graalvm.fastr", info.getId());
assertEquals("1.0", info.getVersionString());
assertEquals("0.32", info.getRequiredGraalValues().get("graalvm_version"));
Expand All @@ -183,7 +194,7 @@ public void testLoadComponentMetadata() throws Exception {
@Test
public void testLoadComponentMetadata2() throws Exception {
copyDir("list1", registryPath);
ComponentInfo info = storage.loadComponentMetadata("fastr-2");
ComponentInfo info = loadLastComponent("fastr-2");
assertEquals("org.graalvm.fastr", info.getId());

assertTrue(info.isPolyglotRebuild());
Expand All @@ -199,7 +210,7 @@ public void testLoadComponentMetadata2() throws Exception {
@Test
public void loadComponentFiles() throws Exception {
copyDir("list1", registryPath);
ComponentInfo info = storage.loadComponentMetadata("fastr");
ComponentInfo info = loadLastComponent("fastr");
storage.loadComponentFiles(info);
List<String> files = info.getPaths();
assertEquals(Arrays.asList(
Expand All @@ -216,7 +227,7 @@ public void loadComponentFilesMissing() throws Exception {
copyDir("list1", registryPath);
Files.delete(registryPath.resolve(SystemUtils.fileName("org.graalvm.fastr.filelist")));

ComponentInfo info = storage.loadComponentMetadata("fastr");
ComponentInfo info = loadLastComponent("fastr");
storage.loadComponentFiles(info);
List<String> files = info.getPaths();
assertTrue(files.isEmpty());
Expand All @@ -228,7 +239,7 @@ public void loadComponentFilesMissing() throws Exception {
@Test
public void testLoadMissingComponentMetadata() throws Exception {
copyDir("list1", registryPath);
assertNull(storage.loadComponentMetadata("rrr"));
assertNull(loadLastComponent("rrr"));
}

@Test
Expand Down Expand Up @@ -425,7 +436,7 @@ public void saveComponentFiles() throws Exception {
@Test
public void testAcceptLicense() throws Exception {
copyDir("list1", registryPath);
ComponentInfo info = storage.loadComponentMetadata("fastr");
ComponentInfo info = loadLastComponent("fastr");

storage.recordLicenseAccepted(info, "cafebabe", "This is a dummy license");
Path p = registryPath.resolve(SystemUtils.fromCommonString("licenses/cafebabe.accepted/org.graalvm.fastr"));
Expand All @@ -437,8 +448,8 @@ public void testAcceptLicense() throws Exception {
@Test
public void testLicenseAccepted1() throws Exception {
copyDir("list1", registryPath);
ComponentInfo info = storage.loadComponentMetadata("fastr");
ComponentInfo info2 = storage.loadComponentMetadata("ruby");
ComponentInfo info = loadLastComponent("fastr");
ComponentInfo info2 = loadLastComponent("ruby");

Path p = registryPath.resolve(SystemUtils.fromCommonString("licenses/cafebabe.accepted/org.graalvm.fastr"));
Files.createDirectories(p.getParent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,28 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package org.graalvm.component.installer.persist.test;

import org.graalvm.component.installer.CommandInput;
import org.graalvm.component.installer.Feedback;
import org.graalvm.component.installer.SoftwareChannel;
import org.graalvm.component.installer.ce.WebCatalog;

/**
* Stub that accepts also "test:" URL scheme.
*
*
* @author sdedic
*/
public class TestCatalog extends WebCatalog {
public class TestCatalog implements SoftwareChannel.Factory {

@Override
protected boolean acceptURLScheme(String scheme) {
if ("test".equals(scheme)) {
return true;
public SoftwareChannel createChannel(String urlSpec, CommandInput input, Feedback fb) {
if (urlSpec.startsWith("test://")) {
WebCatalog c = new WebCatalog(urlSpec);
c.init(input, fb);
return c;
}
return super.acceptURLScheme(scheme);
}

return null;
}
}
Loading

0 comments on commit b49d6f8

Please sign in to comment.