use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class ResolverTestCase method doTest.
private void doTest(Tester tester) throws Exception {
CmrRepository repository = createAetherRepository();
RepositoryManager manager = new SimpleRepositoryManager(repository, log);
ArtifactResult result = manager.getArtifactResult(MavenArtifactContext.NAMESPACE, "org.apache.camel:camel-core", "2.9.2");
Assert.assertNotNull(result);
Assert.assertEquals(result.name(), "org.apache.camel:camel-core");
File artifact = result.artifact();
boolean exists = false;
try {
Assert.assertNotNull(artifact);
Assert.assertTrue(artifact.exists());
exists = true;
tester.run(repository, artifact);
} finally {
if (exists) {
// delete this one
Assert.assertTrue(artifact.delete());
}
}
}
use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class CeylonCompileTool method initialize.
@Override
public void initialize(CeylonTool mainTool) throws Exception {
super.initialize(mainTool);
compiler = new Main("ceylon compile");
helper.options.clear();
Options.instance(new Context());
includeDependencies = processCompileFlags(includeDependencies, DefaultToolOptions.getCompilerIncludeDependencies());
if (modulesOrFiles.isEmpty() && !javac.contains("-help") && !javac.contains("-X") && !javac.contains("-version")) {
throw new IllegalStateException("Argument moduleOrFile should appear at least 1 time(s)");
}
arguments = new ArrayList<>();
if (cwd != null) {
arguments.add("-cwd");
arguments.add(cwd.getPath());
validateWithJavac(org.eclipse.ceylon.langtools.tools.javac.main.Option.CEYLONCWD, "-cwd", cwd.getPath());
}
if (jdkProvider != null) {
arguments.add("-jdk-provider");
arguments.add(jdkProvider.toString());
}
if (aptModules != null) {
for (ModuleSpec mod : aptModules) {
arguments.add("-apt");
arguments.add(mod.toString());
}
}
for (File source : applyCwd(this.sources)) {
arguments.add("-src");
arguments.add(source.getPath());
validateWithJavac(org.eclipse.ceylon.langtools.tools.javac.main.Option.CEYLONSOURCEPATH, "-sourcepath", source.getPath());
}
for (File resource : applyCwd(this.resources)) {
arguments.add("-res");
arguments.add(resource.getPath());
}
if (resourceRoot != null) {
arguments.add("-resroot");
arguments.add(resourceRoot);
}
if (continueOnErrors) {
arguments.add("-continue");
}
if (progress) {
arguments.add("-progress");
}
if (offline) {
arguments.add("-offline");
}
if (timeout != -1) {
arguments.add("-timeout");
arguments.add(String.valueOf(timeout));
}
if (flatClasspath) {
arguments.add("-flat-classpath");
}
if (autoExportMavenDependencies) {
arguments.add("-auto-export-maven-dependencies");
}
if (fullyExportMavenDependencies) {
arguments.add("-fully-export-maven-dependencies");
}
if (overrides != null) {
arguments.add("-overrides");
if (overrides.startsWith("classpath:")) {
arguments.add(overrides);
} else {
arguments.add(applyCwd(new File(overrides)).getPath());
}
}
if (jigsaw) {
arguments.add("-module-info");
}
if (noOsgi) {
arguments.add("-noosgi");
}
if (osgiProvidedBundles != null && !osgiProvidedBundles.isEmpty()) {
arguments.add("-osgi-provided-bundles");
arguments.add(osgiProvidedBundles);
}
if (noPom) {
arguments.add("-nopom");
}
if (pack200) {
arguments.add("-pack200");
}
if (verbose != null) {
if (verbose.isEmpty()) {
arguments.add("-verbose");
} else {
arguments.add("-verbose:" + verbose);
}
}
if (out != null) {
arguments.add("-out");
arguments.add(out);
}
if (user != null) {
arguments.add("-user");
arguments.add(user);
}
if (pass != null) {
arguments.add("-pass");
arguments.add(pass);
}
String fileEncoding = encoding;
if (fileEncoding == null) {
fileEncoding = DefaultToolOptions.getDefaultEncoding();
}
if (fileEncoding != null) {
try {
Charset.forName(fileEncoding);
} catch (IllegalCharsetNameException | UnsupportedCharsetException e) {
throw new IllegalArgumentException("Unsupported encoding: " + fileEncoding);
}
arguments.add(org.eclipse.ceylon.langtools.tools.javac.main.Option.ENCODING.text);
arguments.add(fileEncoding);
}
if (systemRepo != null) {
arguments.add("-sysrep");
arguments.add(systemRepo);
}
if (cacheRepo != null) {
arguments.add("-cacherep");
arguments.add(cacheRepo);
}
if (noDefRepos) {
arguments.add("-nodefreps");
}
if (repos != null) {
for (URI uri : this.repos) {
arguments.add("-rep");
arguments.add(uri.toString());
}
}
if (suppressWarnings != null) {
arguments.add("-suppress-warnings");
arguments.add(EnumUtil.enumsToString(suppressWarnings));
}
if (targetVersion != null) {
arguments.add("-source");
arguments.add(targetVersion.toString());
arguments.add("-target");
arguments.add(targetVersion.toString());
}
if (ee) {
arguments.add("-ee");
}
if (eeImport != null) {
for (String eeImport : this.eeImport) {
arguments.add("-ee-import");
arguments.add(eeImport);
}
}
if (eeAnnotation != null) {
for (String eeAnnotation : this.eeAnnotation) {
arguments.add("-ee-annotation");
arguments.add(eeAnnotation);
}
}
addJavacArguments(arguments, javac);
List<File> srcs = applyCwd(this.sources);
Collection<String> expandedModulesOrFiles = ModuleWildcardsHelper.expandWildcards(srcs, this.modulesOrFiles, Backend.Java);
expandedModulesOrFiles = normalizeFileNames(expandedModulesOrFiles);
if (expandedModulesOrFiles.isEmpty()) {
String msg = CeylonCompileMessages.msg("error.no.sources");
if (ModuleWildcardsHelper.onlyGlobArgs(this.modulesOrFiles)) {
throw new NonFatalToolMessage(msg);
} else {
throw new ToolUsageError(msg);
}
}
for (String moduleOrFile : expandedModulesOrFiles) {
if (!org.eclipse.ceylon.langtools.tools.javac.main.Option.SOURCEFILE.matches(moduleOrFile)) {
throw new IllegalArgumentException(CeylonCompileMessages.msg("argument.error", moduleOrFile));
}
validateWithJavac(org.eclipse.ceylon.langtools.tools.javac.main.Option.SOURCEFILE, moduleOrFile, moduleOrFile);
}
// We validate that all source arguments are correct
SourceArgumentsResolver sar = new SourceArgumentsResolver(this.sources, this.resources, Constants.CEYLON_SUFFIX, Constants.JAVA_SUFFIX);
sar.cwd(cwd).parse(expandedModulesOrFiles);
if (includeDependencies != null && !COMPILE_NEVER.equals(includeDependencies)) {
// Determine any dependencies that might need compiling as well
SourceDependencyResolver sdr = new SourceDependencyResolver(getModuleVersionReader(), this.sources, Backends.JAVA);
if (sdr.traverseDependencies(sar.getSourceFiles())) {
for (ModuleVersionDetails mvd : sdr.getAdditionalModules()) {
if (COMPILE_FORCE.equals(includeDependencies) || (COMPILE_CHECK.equals(includeDependencies) && shouldRecompile(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JVM, true)) || (COMPILE_ONCE.equals(includeDependencies) && shouldRecompile(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JVM, false))) {
expandedModulesOrFiles.add(mvd.getModule());
if (incremental) {
sar.parse(expandedModulesOrFiles);
}
}
}
}
}
if (incremental) {
next_module: for (String module : sar.getModules()) {
// Determine module version from source
ModuleVersionDetails mvd = getModuleVersionReader().fromSource(module);
if (mvd != null) {
// Find the module's CAR file
ArtifactResult artifact = getModuleArtifact(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JVM);
if (artifact != null) {
// Check the language module version
for (ArtifactResult dep : artifact.dependencies()) {
if ("ceylon.language".equals(dep.name())) {
if (!Versions.CEYLON_VERSION_NUMBER.equals(dep.version())) {
// Skip handling of --incremental on this module
continue next_module;
}
break;
}
}
File carFile = artifact.artifact();
// Check if it has META-INF/errors.txt
Properties errors = getMetaInfErrors(carFile);
if (errors != null && !errors.isEmpty()) {
// TODO handle this incrementally
continue;
}
// Check if it has META-INF/hashes.txt
Properties oldHashes = getMetaInfHashes(carFile);
if (oldHashes != null) {
// Get the hashes for the new files
List<File> files = sar.getFilesByModule().get(module);
Properties newHashes = getFileHashes(module, files);
// Compare the two and make list of changed files
Collection<String> changedFiles = determineChangedFiles(module, oldHashes, newHashes, carFile);
if (changedFiles == null) {
// This shouldn't happen, but if it does we just skip any
// special treatment and compile this module normally
} else if (changedFiles.isEmpty()) {
// No files were changed, we shouldn't compile the module
expandedModulesOrFiles.remove(module);
// And we remove its files too if any were mentioned
Collection<String> remove = filesToStrings(module, files);
expandedModulesOrFiles.removeAll(remove);
} else {
if (expandedModulesOrFiles.contains(module)) {
// The module itself was mentioned on the command line
if (changedFiles.size() < files.size()) {
// There were fewer changed files than the total number
// So we remove the module
expandedModulesOrFiles.remove(module);
// And we remove its files too if any were mentioned
Collection<String> remove = filesToStrings(module, files);
expandedModulesOrFiles.removeAll(remove);
// And then we add only those files that were changed
expandedModulesOrFiles.addAll(changedFiles);
}
} else {
// Separate source files were mentioned on the command line
// So we remove the unchanged files
Collection<String> unchanged = filesToStrings(module, files);
unchanged.removeAll(changedFiles);
expandedModulesOrFiles.removeAll(unchanged);
}
}
}
}
}
}
if (expandedModulesOrFiles.isEmpty()) {
String msg = CeylonCompileMessages.msg("error.no.need");
throw new NonFatalToolMessage(msg);
}
}
arguments.addAll(expandedModulesOrFiles);
if (verbose != null) {
System.out.println(arguments);
System.out.flush();
}
}
use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class CeylonModuleLoader method findModule.
@Override
protected ModuleSpec findModule(ModuleIdentifier moduleIdentifier) throws ModuleLoadException {
try {
final ArtifactResult artifact = findArtifact(moduleIdentifier);
if (artifact == null)
return null;
if (!artifact.version().equals(moduleIdentifier.getSlot())) {
AliasModuleSpec alias = (AliasModuleSpec) ModuleSpec.buildAlias(moduleIdentifier, ModuleIdentifier.create(artifact.name(), artifact.version())).create();
return alias;
}
final File moduleFile = artifact.artifact();
final boolean isDefault = RepositoryManager.DEFAULT_MODULE.equals(moduleIdentifier.getName());
boolean isMaven = artifact.type() == ArtifactResultType.MAVEN;
final List<DependencySpec> deps = new ArrayList<>();
ModuleSpec.Builder builder = ModuleSpec.build(moduleIdentifier);
if (!ModuleUtil.isMavenJarlessModule(moduleFile)) {
// add module's jar
ResourceLoader resourceLoader = ResourceLoaderProvider.getResourceLoader(moduleIdentifier, repository, moduleFile);
// filter
PathFilter filter = (artifact.filter() != null ? new CMRPathFilter(artifact.filter()) : PathFilters.acceptAll());
// module resource root
ResourceLoaderSpec rls = ResourceLoaderSpec.createResourceLoaderSpec(resourceLoader, filter);
builder.addResourceRoot(rls);
}
// add potential native lib lookup
ResourceLoader nativeLoader = new NativeLibraryResourceLoader(new File(moduleFile.getParent(), "lib"));
builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(nativeLoader));
Graph.Vertex<ModuleIdentifier, Boolean> vertex = graph.createVertex(moduleIdentifier, moduleIdentifier);
DependencySpec lds = DependencySpec.createLocalDependencySpec();
// local resources
builder.addDependency(lds);
deps.add(lds);
if (isDefault == false) {
Node<ArtifactResult> root = new Node<>();
for (ArtifactResult i : artifact.dependencies()) {
// Skip test scopes
if (i.moduleScope() == ModuleScope.TEST)
continue;
final String name = i.name();
// route logging to JBoss LogManager
if (isLogging(deps, builder, i)) {
continue;
}
// skip JDK modules
if (JDK_MODULE_NAMES.contains(name)) {
continue;
}
boolean isDepMaven = MavenArtifactContext.NAMESPACE.equals(i.namespace());
if (i.optional()) {
Node<ArtifactResult> current = root;
String[] tokens = name.split("\\.");
for (String token : tokens) {
Node<ArtifactResult> child = current.getChild(token);
if (child == null)
child = current.addChild(token);
current = child;
}
current.setValue(i);
} else {
DependencySpec mds = createModuleDependency(i, exportMavenImports && isMaven && isDepMaven);
builder.addDependency(mds);
deps.add(mds);
}
ModuleIdentifier mi = createModuleIdentifier(i);
Graph.Vertex<ModuleIdentifier, Boolean> dv = graph.createVertex(mi, mi);
Graph.Edge.create(i.exported() || (exportMavenImports && isMaven && isDepMaven), vertex, dv);
}
if (root.isEmpty() == false) {
LocalLoader onDemandLoader = new OnDemandLocalLoader(moduleIdentifier, this, root);
builder.setFallbackLoader(onDemandLoader);
}
}
// automagically import the JDK module
builder.addDependency(JDK_DEPENDENCY);
// no need to track system deps -- cannot be updated anyway
createModuleDependency(vertex, deps, builder, LANGUAGE, false);
// add runtime utils
final DependencySpec sds = DependencySpec.createModuleDependencySpec(PathFilters.match(CEYLON_RUNTIME_PATH), PathFilters.rejectAll(), this, RUNTIME, true);
builder.addDependency(sds);
deps.add(sds);
Graph.Vertex<ModuleIdentifier, Boolean> sdsv = graph.createVertex(RUNTIME, RUNTIME);
Graph.Edge.create(false, vertex, sdsv);
dependencies.put(moduleIdentifier, deps);
// Stef: enable back when we upgrade jboss modules
// index(artifact.artifact(), moduleIdentifier);
UtilRegistryTransformer transformer = new UtilRegistryTransformer(moduleIdentifier, artifact);
builder.setClassFileTransformer(transformer);
// make sure we set our own class loader factory so we can find the transformer back from the class loader
// this is used in the language module to force module metamodel registration
builder.setModuleClassLoaderFactory(new CeylonModuleClassLoader.CeylonModuleClassLoaderFactory(transformer));
return builder.create();
} catch (Exception e) {
throw new ModuleLoadException(e);
}
}
use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class OnDemandLocalLoader method doUpdate.
protected LocalLoader doUpdate(String[] tokens) {
Node<ArtifactResult> current = root;
for (String token : tokens) {
current = current.getChild(token);
if (current == null)
return null;
// noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (current) {
ArtifactResult i = current.getValue();
if (i != null) {
// remove, so we don't loop; should not happen though
current.remove();
DependencySpec mds = loader.createModuleDependency(i, false);
try {
Module owner = loader.preloadModule(target);
// update / add lazy dep
loader.updateModule(owner, mds);
Module module = loader.loadModule(CeylonModuleLoader.createModuleIdentifier(i));
return new ModuleLocalLoader(module);
} catch (ModuleLoadException ignored) {
return null;
}
}
}
}
return null;
}
use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.
the class LegacyImporter method checkDependencies.
private void checkDependencies(TreeSet<ModuleDependencyInfo> sortedDeps, Set<String> visited, boolean exported) throws Exception {
for (ModuleDependencyInfo dep : sortedDeps) {
// only do exported, or non-exported
if (exported != dep.isExport())
continue;
// skip test scope
if (dep.getModuleScope() == ModuleScope.TEST)
continue;
// skip already-visited dependencies based on name/version key
if (!visited.add(dep.getModuleName()))
continue;
feedback.beforeDependency(dep);
String name = dep.getName();
String version = dep.getVersion();
// missing dep is OK, it can be fixed later, but invalid module/dependency is not OK
if (name == null || name.isEmpty())
feedback.dependencyError(DependencyErrors.DEPERR_INVALID_MODULE_NAME, dep);
if (ModuleUtil.isDefaultModule(name))
feedback.dependencyError(DependencyErrors.DEPERR_INVALID_MODULE_DEFAULT, dep);
if (version == null || version.isEmpty())
feedback.dependencyError(DependencyErrors.DEPERR_INVALID_MODULE_VERSION, dep);
Usage usage = null;
if (jdkProvider.isJDKModule(name)) {
usage = scanner.removeMatchingJdkClasses(name);
} else {
ArtifactContext context = new ArtifactContext(dep.getNamespace(), name, version, ArtifactContext.CAR, ArtifactContext.JAR);
ArtifactResult result = lookupRepoman.getArtifactResult(context);
File artifact = result != null ? result.artifact() : null;
if (artifact != null && artifact.exists()) {
try {
Set<String> importedClasses = JarUtils.gatherClassnamesFromJar(artifact);
addTransitiveDependenciesClasses(result, importedClasses, visited, dep);
usage = scanner.removeMatchingClasses(importedClasses);
} catch (IOException e) {
feedback.dependency(DependencyResults.DEP_CHECK_FAILED, dep);
hasErrors = true;
}
} else {
if (dep.isOptional()) {
String key = ModuleUtil.makeModuleName(dep.getName(), dep.getVersion());
if (missingDependenciesPackages != null && missingDependenciesPackages.containsKey(key)) {
List<Pattern> packages = missingDependenciesPackages.get(key);
usage = scanner.removeMatchingPackages(packages);
}
}
if (usage == null) {
feedback.dependency(DependencyResults.DEP_NOT_FOUND, dep);
hasErrors = true;
}
}
}
if (usage != null) {
switch(usage) {
case Used:
if (!dep.isExport()) {
feedback.dependency(DependencyResults.DEP_OK, dep);
} else {
dep = new ModuleDependencyInfo(null, dep.getName(), dep.getVersion(), dep.isOptional(), false, dep.getNativeBackends(), dep.getModuleScope());
feedback.dependency(DependencyResults.DEP_MARK_UNSHARED, dep);
}
break;
case UsedInPublicApi:
if (dep.isExport()) {
feedback.dependency(DependencyResults.DEP_OK, dep);
} else {
dep = new ModuleDependencyInfo(null, dep.getName(), dep.getVersion(), dep.isOptional(), true, dep.getNativeBackends(), dep.getModuleScope());
feedback.dependency(DependencyResults.DEP_MARK_SHARED, dep);
hasProblems = true;
}
break;
default:
// not used at all
dep = new ModuleDependencyInfo(null, dep.getName(), dep.getVersion(), dep.isOptional(), false, dep.getNativeBackends(), dep.getModuleScope());
feedback.dependency(DependencyResults.DEP_OK_UNUSED, dep);
}
}
feedback.afterDependency(dep);
expectedDependencies.add(dep);
}
}
Aggregations