Search in sources :

Example 1 with Exclusion

use of org.eclipse.ceylon.model.cmr.Exclusion in project ceylon by eclipse.

the class JvmBackendUtil method finishLoadingModule.

private static void finishLoadingModule(ModuleSpec module, SortedSet<String> packages, List<ArtifactResult> dependencies, final List<String> dexEntries, StaticMetamodelLoader staticMetamodelLoader) {
    final SortedSet<String> packagesCopy = new TreeSet<>(packages);
    final List<ArtifactResult> dependenciesCopy = new ArrayList<>(dependencies);
    final String namespace = ModuleUtil.getNamespaceFromUri(module.getName());
    final String name = ModuleUtil.getModuleNameFromUri(module.getName());
    final String version = module.getVersion();
    ArtifactResult artifact = new ContentAwareArtifactResult() {

        @Override
        public VisibilityType visibilityType() {
            return VisibilityType.STRICT;
        }

        @Override
        public String version() {
            return version;
        }

        @Override
        public ArtifactResultType type() {
            return ArtifactResultType.OTHER;
        }

        @Override
        public String repositoryDisplayString() {
            return "Android repo";
        }

        @Override
        public Repository repository() {
            return null;
        }

        @Override
        public String namespace() {
            return namespace;
        }

        @Override
        public String name() {
            return name;
        }

        @Override
        public String artifactId() {
            return ModuleUtil.getMavenArtifactIdIfMavenModule(name);
        }

        @Override
        public String groupId() {
            return ModuleUtil.getMavenGroupIdIfMavenModule(name);
        }

        @Override
        public String classifier() {
            return ModuleUtil.getMavenClassifierIfMavenModule(name);
        }

        @Override
        public boolean exported() {
            return false;
        }

        @Override
        public boolean optional() {
            return false;
        }

        @Override
        public PathFilter filter() {
            return null;
        }

        @Override
        public List<ArtifactResult> dependencies() throws RepositoryException {
            return dependenciesCopy;
        }

        @Override
        public File artifact() throws RepositoryException {
            return null;
        }

        @Override
        public Collection<String> getPackages() {
            return packagesCopy;
        }

        @Override
        public List<String> getFileNames(String path) {
            return getAndroidFileNames(path);
        }

        private List<String> getAndroidFileNames(String path) {
            path = path + "/";
            List<String> ret = new LinkedList<>();
            for (String entry : dexEntries) {
                if (entry.startsWith(path)) {
                    String part = entry.substring(path.length());
                    // no folders and no subfolders
                    if (!part.isEmpty() && part.indexOf('/') == -1)
                        ret.add(entry);
                }
            }
            return ret;
        }

        @Override
        public Collection<String> getEntries() {
            return getAndroidEntries();
        }

        private Collection<String> getAndroidEntries() {
            List<String> ret = new LinkedList<>();
            for (String entry : dexEntries) {
                for (String pkg : packagesCopy) {
                    String path = pkg.replace('.', '/') + "/";
                    if (entry.startsWith(path)) {
                        ret.add(entry);
                        break;
                    }
                }
            }
            return ret;
        }

        @Override
        public byte[] getContents(String path) {
            // this is used by the metamodel module resource system
            try {
                return IOUtil.readStream(getClass().getClassLoader().getResourceAsStream(path));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public URI getContentUri(String path) {
            try {
                return getClass().getClassLoader().getResource(path).toURI();
            } catch (URISyntaxException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String toString() {
            return "StaticMetamodelArtifact for module " + name + "/" + version;
        }

        @Override
        public ModuleScope moduleScope() {
            return ModuleScope.COMPILE;
        }

        @Override
        public List<Exclusion> getExclusions() {
            return null;
        }
    };
    staticMetamodelLoader.loadModule(module.getName(), module.getVersion(), artifact);
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) LinkedList(java.util.LinkedList) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) TreeSet(java.util.TreeSet) Exclusion(org.eclipse.ceylon.model.cmr.Exclusion)

Example 2 with Exclusion

use of org.eclipse.ceylon.model.cmr.Exclusion in project ceylon by eclipse.

the class AetherUtils method createArtifactResult.

protected ArtifactResult createArtifactResult(final RepositoryManager manager, CmrRepository repository, final String groupId, final String artifactId, final String classifier, final String dVersion, final boolean shared, final boolean optional, final ModuleScope scope, final String repositoryDisplayString, final List<ExclusionDescriptor> exclusions) {
    final String dName = MavenUtils.moduleName(groupId, artifactId, classifier);
    return new MavenArtifactResult(repository, dName, dVersion, groupId, artifactId, classifier, repositoryDisplayString) {

        private ArtifactResult result;

        {
            if (exclusions != null) {
                List<Exclusion> ret = new ArrayList<>(exclusions.size());
                for (ExclusionDescriptor xDescr : exclusions) {
                    ret.add(new Exclusion(xDescr.getGroupId(), xDescr.getArtifactId()));
                }
                setExclusions(ret);
            }
        }

        @Override
        public boolean exported() {
            return shared;
        }

        @Override
        public boolean optional() {
            return optional;
        }

        @Override
        public ModuleScope moduleScope() {
            return scope;
        }

        private synchronized ArtifactResult getResult() {
            if (result == null) {
                result = fetchDependencies(manager, (CmrRepository) repository(), groupId, artifactId, classifier, dVersion, false, repositoryDisplayString);
            }
            return result;
        }

        protected File artifactInternal() throws RepositoryException {
            return getResult().artifact();
        }

        public List<ArtifactResult> dependencies() throws RepositoryException {
            return getResult().dependencies();
        }
    };
}
Also used : Exclusion(org.eclipse.ceylon.model.cmr.Exclusion) ArrayList(java.util.ArrayList) ExclusionDescriptor(org.eclipse.ceylon.cmr.resolver.aether.ExclusionDescriptor) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) LazyArtifactResult(org.eclipse.ceylon.cmr.impl.LazyArtifactResult) AbstractArtifactResult(org.eclipse.ceylon.cmr.impl.AbstractArtifactResult) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Aggregations

ArrayList (java.util.ArrayList)2 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)2 Exclusion (org.eclipse.ceylon.model.cmr.Exclusion)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 LinkedList (java.util.LinkedList)1 TreeSet (java.util.TreeSet)1 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)1 AbstractArtifactResult (org.eclipse.ceylon.cmr.impl.AbstractArtifactResult)1 LazyArtifactResult (org.eclipse.ceylon.cmr.impl.LazyArtifactResult)1 ExclusionDescriptor (org.eclipse.ceylon.cmr.resolver.aether.ExclusionDescriptor)1