use of org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder in project ceylon by eclipse.
the class ToolLoader method loadModule.
public ClassLoader loadModule(String name, String version, String overrides) {
try {
// Ok, now for something really crappy to force loading of the required module
String loaderClassName;
if (loader.getClass().getName().equals("org.jboss.modules.ModuleClassLoader") || loader.getClass().getName().equals("ceylon.modules.jboss.runtime.CeylonModuleClassLoader")) {
// If we run using the Ceylon runtime
loaderClassName = "org.eclipse.ceylon.module.loader.JBossModuleLoader";
} else {
// If we run in a normal Java environment
loaderClassName = "org.eclipse.ceylon.module.loader.FlatpathModuleLoader";
}
Class<?> loaderClass = loader.loadClass(loaderClassName);
CeylonRepoManagerBuilder repositoryManagerBuilder = CeylonUtils.repoManager();
if (overrides != null)
repositoryManagerBuilder.overrides(overrides);
RepositoryManager repositoryManager = repositoryManagerBuilder.buildManager();
Constructor<?> loaderConstr = loaderClass.getConstructor(RepositoryManager.class, ClassLoader.class);
Object modLoader = loaderConstr.newInstance(repositoryManager, loader);
Method loadMth = loaderClass.getMethod("loadModule", String.class, String.class);
ClassLoader mcl = (ClassLoader) loadMth.invoke(modLoader, name, version);
return mcl;
} catch (ReflectiveOperationException e) {
Throwable cause = (e.getCause() != null) ? e.getCause() : e;
throw new ToolError("Could not load module '" + name + "/" + version + "' because: " + cause.toString(), e) {
};
}
}
use of org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder in project ceylon by eclipse.
the class ImportJarToolTests method testMissingOptionalPackages.
@Test
public void testMissingOptionalPackages() throws Exception {
// Jetty is compiled for JDK8
Assume.assumeTrue("Runs on JDK8", JDKUtils.jdk == JDKUtils.JDK.JDK8);
CeylonRepoManagerBuilder builder = CeylonUtils.repoManager();
RepositoryManager repository = builder.buildManager();
File artifact = repository.getArtifact(MavenArtifactContext.NAMESPACE, "org.eclipse.jetty:jetty-server", "9.3.2.v20150730");
Assert.assertNotNull(artifact);
ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
Assert.assertNotNull(model);
// no descriptor
CeylonImportJarTool tool;
StringBuilder b = new StringBuilder();
// make sure we don't get a missing package with array shit in there: [Ljavax.servlet;
try {
tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
tool.setOut(b);
tool.run();
Assert.fail();
} catch (ToolUsageError e) {
Assert.assertEquals("Problems were found, aborting. Try adding a descriptor file, see help for more information.", e.getMessage());
Assert.assertEquals("The following JDK modules are used and could be declared as imports:\n" + " java.base ... [shared]\n" + " java.jdbc ... [shared]\n" + " java.tls ... [shared]\n" + " javax.naming\n" + "Modules containing the following packages need to be declared as imports:\n" + "(Tip: try running again with the '--show-suggestions' option)\n" + " javax.servlet ... [shared]\n" + " javax.servlet.descriptor ... [shared]\n" + " javax.servlet.http ... [shared]\n" + " org.eclipse.jetty.http ... [shared]\n" + " org.eclipse.jetty.io ... [shared]\n" + " org.eclipse.jetty.io.ssl ... [shared]\n" + " org.eclipse.jetty.jmx ... [shared]\n" + " org.eclipse.jetty.util ... [shared]\n" + " org.eclipse.jetty.util.annotation ... [shared]\n" + " org.eclipse.jetty.util.component ... [shared]\n" + " org.eclipse.jetty.util.log ... [shared]\n" + " org.eclipse.jetty.util.resource ... [shared]\n" + " org.eclipse.jetty.util.ssl ... [shared]\n" + " org.eclipse.jetty.util.statistic ... [shared]\n" + " org.eclipse.jetty.util.thread ... [shared]\n", b.toString());
}
// all OK
tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-module.properties", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
tool.run();
// with missing module
tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", // exact
"--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound/9.3.2.v20150730=org.eclipse.jetty.jmx", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
tool.run();
// with missing module
tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", // **
"--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound/9.3.2.v20150730=org.**.jmx", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
tool.run();
// with missing module
tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", // *
"--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound/9.3.2.v20150730=org.eclipse.jetty.jm*", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
tool.run();
try {
// with missing module
tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", // * with dots
"--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound/9.3.2.v20150730=org.*.jmx", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
tool.run();
Assert.fail();
} catch (ToolUsageError e) {
Assert.assertEquals("Problems were found, aborting.", e.getMessage());
}
// with missing module
tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", // ?
"--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound/9.3.2.v20150730=org.eclipse.jetty.jm?", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
tool.run();
try {
// with invalid pattern
tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", "--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
tool.run();
Assert.fail();
} catch (ToolError e) {
Assert.assertEquals("Invalid missing dependencies descriptor : 'org.eclipse.jetty:jetty-jmxnotfound'. 'Syntax is module-name/module-version=package-wildcard(,package-wildcard)*'.", e.getMessage());
}
}
use of org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder in project ceylon by eclipse.
the class CMRTests method testMavenFileResolver.
@Test
public void testMavenFileResolver() throws ZipException, IOException {
CeylonRepoManagerBuilder builder = CeylonUtils.repoManager();
RepositoryManager repository = builder.buildManager();
String groupId = "javax.el";
String artifactId = "javax.el-api";
String version = "3.0.0";
String coord = groupId + ":" + artifactId;
File artifact = repository.getArtifact(MavenArtifactContext.NAMESPACE, coord, version);
Assert.assertNotNull(artifact);
try (ZipFile zf = new ZipFile(artifact)) {
String descriptorPath = String.format("META-INF/maven/%s/%s/pom.xml", groupId, artifactId);
ZipEntry entry = zf.getEntry(descriptorPath);
Assert.assertNotNull(entry);
try (InputStream is = zf.getInputStream(entry)) {
DependencyResolver resolver = new MavenDependencyResolver();
ModuleInfo info = resolver.resolveFromInputStream(is, coord, version, null);
Assert.assertNotNull(info);
// FIXME: find one with dependencies
System.err.println(info.getDependencies());
}
}
}
use of org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder in project ceylon by eclipse.
the class ImportJarToolTests method testSystemRepositoryModuleDescriptors.
@Test
public void testSystemRepositoryModuleDescriptors() throws Exception {
CeylonRepoManagerBuilder builder = CeylonUtils.repoManager();
builder.outRepo(destDir.getPath()).cacheRepo(cacheDir.getPath()).systemRepo(getSysRepPath());
final RepositoryManager repository = builder.buildManager();
final Path repoPath = Paths.get(getSysRepPath());
Files.walkFileTree(repoPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().endsWith(".jar") || file.getFileName().toString().endsWith(".car")) {
System.err.println("Checking file " + file);
Path p = repoPath.relativize(file.getParent());
String module = p.getParent().toString().replace('/', '.');
String version = p.getFileName().toString();
try {
checkModuleDescriptor(repository, module, version);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return super.visitFile(file, attrs);
}
});
}
Aggregations