Skip to content

Commit

Permalink
[GR-18195] Component dependencies.
Browse files Browse the repository at this point in the history
PullRequest: graal/4401
  • Loading branch information
sdedic committed Oct 11, 2019
2 parents ac3a21a + 94c1d94 commit 6bb1989
Show file tree
Hide file tree
Showing 102 changed files with 6,469 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void addRemoteComponent(String relative, String u, boolean addParam) throws IOEx
public void testReadComponentMetadataNoNetwork() throws Exception {
addRemoteComponent("persist/data/truffleruby3.jar", "test://graalvm.io/download/truffleruby.zip", false);
textParams.add("ruby");
CatalogIterable cit = new CatalogIterable(this, this, getRegistry(), this);
CatalogIterable cit = new CatalogIterable(this, this);
assertTrue(cit.iterator().hasNext());
for (ComponentParam p : cit) {
URL remoteU = p.createMetaLoader().getComponentInfo().getRemoteURL();
Expand All @@ -162,7 +162,7 @@ public void testUnknownComponentSpecified() throws Exception {
exception.expectMessage("REMOTE_UnknownComponentId");
addRemoteComponent("persist/data/truffleruby3.jar", "test://graalvm.io/download/truffleruby.zip", false);
textParams.add("r");
CatalogIterable cit = new CatalogIterable(this, this, getRegistry(), this);
CatalogIterable cit = new CatalogIterable(this, this);
assertTrue(cit.iterator().hasNext());
cit.iterator().next();
}
Expand All @@ -178,7 +178,7 @@ public void testUnknownComponentButExistingFile() throws Exception {
addRemoteComponent("persist/data/truffleruby3.jar", "test://graalvm.io/download/truffleruby.zip", false);
File mistyped = folder.newFile("mistyped-component.jar");
textParams.add(mistyped.getPath());
CatalogIterable cit = new CatalogIterable(this, this, getRegistry(), this);
CatalogIterable cit = new CatalogIterable(this, this);
assertTrue(cit.iterator().hasNext());
cit.iterator().next();
}
Expand Down Expand Up @@ -280,7 +280,7 @@ public void connect() throws IOException {
}
});

CatalogIterable cit = new CatalogIterable(this, this, getRegistry(), this);
CatalogIterable cit = new CatalogIterable(this, this);
ComponentParam rubyComp = cit.iterator().next();

exception.expect(FailedOperationException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;

public class CommandTestBase extends TestBase implements CommandInput, SoftwareChannel {
public class CommandTestBase extends TestBase implements CommandInput, SoftwareChannel, ComponentCatalog.DownloadInterceptor {
@Rule public ExpectedException exception = ExpectedException.none();
protected JarFile componentJarFile;
@Rule public TemporaryFolder folder = new TemporaryFolder();
Expand All @@ -63,7 +63,7 @@ public class CommandTestBase extends TestBase implements CommandInput, SoftwareC
protected FileOperations fileOps;
protected MockStorage storage;
protected MockStorage catalogStorage;
protected ComponentCollection registry;
protected ComponentCatalog registry;
protected ComponentRegistry localRegistry;

protected List<File> files = new ArrayList<>();
Expand Down Expand Up @@ -121,67 +121,77 @@ public FileOperations getFileOperations() {
return fileOps;
}

@Override
public ComponentIterable existingFiles() throws FailedOperationException {
if (paramIterable != null) {
return paramIterable;
protected class CompIterableImpl implements ComponentIterable {
@Override
public void setVerifyJars(boolean verify) {
verifyJars = verify;
}
return new ComponentIterable() {
@Override
public void setVerifyJars(boolean verify) {
verifyJars = verify;
}

@Override
public ComponentParam createParam(String cmdString, ComponentInfo nfo) {
return null;
}

@Override
public Iterator<ComponentParam> iterator() {
return new Iterator<ComponentParam>() {
private Iterator<ComponentParam> pit = components.iterator();
private Iterator<ComponentParam> fit;
{
FileIterable ff = new FileIterable(CommandTestBase.this, CommandTestBase.this);
ff.setVerifyJars(verifyJars);
fit = ff.iterator();
}

@Override
public boolean hasNext() {
return fit.hasNext() || pit.hasNext();
}
@Override
public ComponentParam createParam(String cmdString, ComponentInfo nfo) {
return null;
}

@Override
public ComponentParam next() {
ComponentParam p = null;

if (pit.hasNext()) {
p = pit.next();
// discard one parameter from files:
files.remove(0);
if (p != null) {
return p;
}
@Override
public Iterator<ComponentParam> iterator() {
return new Iterator<ComponentParam>() {
private Iterator<ComponentParam> pit = components.iterator();
private Iterator<ComponentParam> fit;
{
FileIterable ff = new FileIterable(CommandTestBase.this, CommandTestBase.this);
ff.setVerifyJars(verifyJars);
fit = ff.iterator();
}

@Override
public boolean hasNext() {
return fit.hasNext() || pit.hasNext();
}

@Override
public ComponentParam next() {
ComponentParam p = null;

if (pit.hasNext()) {
p = pit.next();
// discard one parameter from files:
files.remove(0);
if (p != null) {
return p;
}
return fit.next();
}
return fit.next();
}

};
}
};
}

@Override
public ComponentIterable matchVersion(Version.Match m) {
return this;
}
@Override
public ComponentIterable matchVersion(Version.Match m) {
return this;
}

@Override
public ComponentIterable allowIncompatible() {
return this;
}
@Override
public ComponentIterable allowIncompatible() {
return this;
}
}

protected ComponentIterable iterableInstance;

protected ComponentIterable createComponentIterable() {
if (iterableInstance != null) {
return iterableInstance;
}
return new CompIterableImpl();
}

};
@Override
public ComponentIterable existingFiles() throws FailedOperationException {
if (paramIterable != null) {
return paramIterable;
}
return createComponentIterable();
}

@Override
Expand Down Expand Up @@ -219,9 +229,9 @@ public Path getGraalHomePath() {
}

@Override
public ComponentCollection getRegistry() {
public ComponentCatalog getRegistry() {
if (registry == null) {
registry = new CatalogContents(this, catalogStorage, getLocalRegistry());
registry = getCatalogFactory().createComponentCatalog(this, getLocalRegistry());
}
return registry;
}
Expand All @@ -247,6 +257,11 @@ public void setUp() throws Exception {
fileOps.setRootPath(targetPath);
}

@Override
public FileDownloader processDownloader(ComponentInfo ci, FileDownloader dn) {
return dn;
}

@Override
public FileDownloader configureDownloader(ComponentInfo ci, FileDownloader dn) {
return dn;
Expand All @@ -256,4 +271,13 @@ public FileDownloader configureDownloader(ComponentInfo ci, FileDownloader dn) {
public ComponentStorage getStorage() {
return catalogStorage;
}

@Override
public CatalogFactory getCatalogFactory() {
if (registry != null) {
return (a, b) -> registry;
} else {
return (a, b) -> new CatalogContents(this, catalogStorage, getLocalRegistry());
}
}
}
Loading

0 comments on commit 6bb1989

Please sign in to comment.